aboutsummaryrefslogtreecommitdiff
path: root/paludis/hooker_TEST.cc
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2009-02-09 21:35:39 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2009-02-09 21:35:39 +0000
commit8772b7a5c74c3254a53e70a922e9e0a2bc1c09c3 (patch)
treedb429b81a81135f285ed2ff16c873d65f09a813f /paludis/hooker_TEST.cc
parentd946b89871e6dad288440d5fd1ad29bfcd1dff1d (diff)
downloadpaludis-8772b7a5c74c3254a53e70a922e9e0a2bc1c09c3.tar.gz
paludis-8772b7a5c74c3254a53e70a922e9e0a2bc1c09c3.tar.xz
Avoid std::ifstream and std::ofstream.
Unfortunately std::ifstream and std::ofstream are allowed to fail in unobvious ways when given a duff file. In particular, gcc won't error out when a std::ifstream is created for a directory until the first read occurs. So we write our own stream buffer classes that do error checking and throw useful exceptions on error, and use those instead.
Diffstat (limited to 'paludis/hooker_TEST.cc')
-rw-r--r--paludis/hooker_TEST.cc14
1 files changed, 7 insertions, 7 deletions
diff --git a/paludis/hooker_TEST.cc b/paludis/hooker_TEST.cc
index 17ea9ec3e..91607adba 100644
--- a/paludis/hooker_TEST.cc
+++ b/paludis/hooker_TEST.cc
@@ -1,7 +1,7 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
- * Copyright (c) 2007, 2008 Ciaran McCreesh
+ * Copyright (c) 2007, 2008, 2009 Ciaran McCreesh
*
* This file is part of the Paludis package manager. Paludis is free software;
* you can redistribute it and/or modify it under the terms of the GNU General
@@ -23,9 +23,9 @@
#include <paludis/environments/test/test_environment.hh>
#include <paludis/util/fs_entry.hh>
#include <paludis/util/make_named_values.hh>
+#include <paludis/util/safe_ifstream.hh>
#include <test/test_runner.hh>
#include <test/test_framework.hh>
-#include <fstream>
#include <iterator>
using namespace test;
@@ -80,7 +80,7 @@ namespace test_cases
TEST_CHECK_EQUAL(result.max_exit_status(), 0);
TEST_CHECK_EQUAL(result.output(), "");
- std::ifstream f(stringify(FSEntry("hooker_TEST_dir/ordering.out")).c_str());
+ SafeIFStream f(FSEntry("hooker_TEST_dir/ordering.out"));
std::string line((std::istreambuf_iterator<char>(f)), std::istreambuf_iterator<char>());
#ifdef ENABLE_PYTHON_HOOKS
@@ -108,7 +108,7 @@ namespace test_cases
TEST_CHECK_EQUAL(result.max_exit_status(), 123);
TEST_CHECK_EQUAL(result.output(), "");
- std::ifstream f(stringify(FSEntry("hooker_TEST_dir/bad_hooks.out")).c_str());
+ SafeIFStream f(FSEntry("hooker_TEST_dir/bad_hooks.out"));
std::string line((std::istreambuf_iterator<char>(f)), std::istreambuf_iterator<char>());
TEST_CHECK_EQUAL(line, "one\nthree\n");
@@ -131,7 +131,7 @@ namespace test_cases
TEST_CHECK_EQUAL(result.max_exit_status(), 0);
TEST_CHECK_EQUAL(result.output(), "");
- std::ifstream f(stringify(FSEntry("hooker_TEST_dir/cycles.out")).c_str());
+ SafeIFStream f(FSEntry("hooker_TEST_dir/cycles.out"));
std::string line((std::istreambuf_iterator<char>(f)), std::istreambuf_iterator<char>());
TEST_CHECK_EQUAL(line, "b\na\ng\nf\ni\n");
@@ -194,7 +194,7 @@ namespace test_cases
TEST_CHECK_EQUAL(result.output(), "");
TEST_CHECK_EQUAL(result.max_exit_status(), 0);
- std::ifstream f(stringify(FSEntry("hooker_TEST_dir/several_output.out")).c_str());
+ SafeIFStream f(FSEntry("hooker_TEST_dir/several_output.out"));
std::string line((std::istreambuf_iterator<char>(f)), std::istreambuf_iterator<char>());
TEST_CHECK_EQUAL(line, "one\none\none\ntwo\none\ntwo\nthree\n");
@@ -220,7 +220,7 @@ namespace test_cases
TEST_CHECK_EQUAL(result.output(), "two");
TEST_CHECK_EQUAL(result.max_exit_status(), 99);
- std::ifstream f(stringify(FSEntry("hooker_TEST_dir/several_output_bad.out")).c_str());
+ SafeIFStream f(FSEntry("hooker_TEST_dir/several_output_bad.out"));
std::string line((std::istreambuf_iterator<char>(f)), std::istreambuf_iterator<char>());
TEST_CHECK_EQUAL(line, "one\ntwo\nthree\n");