aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2011-03-24 23:43:40 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2011-03-24 23:43:40 +0000
commit853185e5d38b54f3f2a5d9d6c181352812e6518c (patch)
treea28303ddfda4dd631d0b959129cf4104754bf6d5
parent1221d7496174c24427b9958a29ee83d895d64bb0 (diff)
downloadpaludis-853185e5d38b54f3f2a5d9d6c181352812e6518c.tar.gz
paludis-853185e5d38b54f3f2a5d9d6c181352812e6518c.tar.xz
gtest more
-rw-r--r--paludis/files.m42
-rw-r--r--paludis/hooker_TEST.cc323
2 files changed, 148 insertions, 177 deletions
diff --git a/paludis/files.m4 b/paludis/files.m4
index 232dd63..3a81b3b 100644
--- a/paludis/files.m4
+++ b/paludis/files.m4
@@ -55,7 +55,7 @@ add(`fuzzy_finder', `hh', `cc', `test')
add(`generator', `hh', `cc', `fwd', `test')
add(`generator_handler', `hh', `cc', `fwd')
add(`hook', `hh', `cc', `fwd', `se')
-add(`hooker', `hh', `cc', `test', `testscript')
+add(`hooker', `hh', `cc', `gtest', `testscript')
add(`ipc_output_manager', `hh', `cc', `fwd')
add(`libtool_linkage_checker', `hh', `cc')
add(`linkage_checker', `hh', `cc')
diff --git a/paludis/hooker_TEST.cc b/paludis/hooker_TEST.cc
index a4ba32f..f118899 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, 2009, 2010 Ciaran McCreesh
+ * Copyright (c) 2007, 2008, 2009, 2010, 2011 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
@@ -17,231 +17,202 @@
* Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include "config.h"
#include <paludis/hooker.hh>
#include <paludis/hook.hh>
+
#include <paludis/environments/test/test_environment.hh>
+
#include <paludis/util/make_named_values.hh>
#include <paludis/util/safe_ifstream.hh>
#include <paludis/util/make_null_shared_ptr.hh>
-#include <test/test_runner.hh>
-#include <test/test_framework.hh>
+
#include <iterator>
-using namespace test;
+#include <gtest/gtest.h>
+
+#include "config.h"
+
using namespace paludis;
-namespace test_cases
+TEST(Hooker, Works)
{
- struct HookerTest : TestCase
- {
- HookerTest() : TestCase("hooker") { }
+ TestEnvironment env;
+ Hooker hooker(&env);
+ HookResult result(make_named_values<HookResult>(n::max_exit_status() = 0, n::output() = ""));
- void run()
- {
- TestEnvironment env;
- Hooker hooker(&env);
- HookResult result(make_named_values<HookResult>(n::max_exit_status() = 0, n::output() = ""));
-
- hooker.add_dir(FSPath("hooker_TEST_dir/"), false);
+ hooker.add_dir(FSPath("hooker_TEST_dir/"), false);
#ifdef ENABLE_PYTHON_HOOKS
- result = hooker.perform_hook(Hook("py_hook"),
- make_null_shared_ptr());
- TEST_CHECK_EQUAL(result.max_exit_status(), 0);
+ result = hooker.perform_hook(Hook("py_hook"),
+ make_null_shared_ptr());
+ EXPECT_EQ(0, result.max_exit_status());
#endif
- result = hooker.perform_hook(Hook("simple_hook"),
- make_null_shared_ptr());
- TEST_CHECK_EQUAL(result.max_exit_status(), 3);
- TEST_CHECK_EQUAL(result.output(), "");
- result = hooker.perform_hook(Hook("fancy_hook"),
- make_null_shared_ptr());
- TEST_CHECK_EQUAL(result.max_exit_status(), 5);
- TEST_CHECK_EQUAL(result.output(), "");
- result = hooker.perform_hook(Hook("so_hook"),
- make_null_shared_ptr());
- TEST_CHECK_EQUAL(result.max_exit_status(), 6);
- TEST_CHECK_EQUAL(result.output(), "");
- result = hooker.perform_hook(Hook("several_hooks"),
- make_null_shared_ptr());
- TEST_CHECK_EQUAL(result.max_exit_status(), 7);
- TEST_CHECK_EQUAL(result.output(), "");
-
- }
- } test_hooker;
-
- struct HookerOrderingTest : TestCase
- {
- HookerOrderingTest() : TestCase("hooker ordering") { }
-
- void run()
- {
- TestEnvironment env;
- Hooker hooker(&env);
-
- FSPath("hooker_TEST_dir/ordering.out").unlink();
-
- hooker.add_dir(FSPath("hooker_TEST_dir/"), false);
- HookResult result(hooker.perform_hook(Hook("ordering"),
- make_null_shared_ptr()));
- TEST_CHECK_EQUAL(result.max_exit_status(), 0);
- TEST_CHECK_EQUAL(result.output(), "");
-
- SafeIFStream f(FSPath("hooker_TEST_dir/ordering.out"));
- std::string line((std::istreambuf_iterator<char>(f)), std::istreambuf_iterator<char>());
+ result = hooker.perform_hook(Hook("simple_hook"),
+ make_null_shared_ptr());
+ EXPECT_EQ(3, result.max_exit_status());
+ EXPECT_EQ("", result.output());
+ result = hooker.perform_hook(Hook("fancy_hook"),
+ make_null_shared_ptr());
+ EXPECT_EQ(5, result.max_exit_status());
+ EXPECT_EQ("", result.output());
+ result = hooker.perform_hook(Hook("so_hook"),
+ make_null_shared_ptr());
+ EXPECT_EQ(6, result.max_exit_status());
+ EXPECT_EQ("", result.output());
+ result = hooker.perform_hook(Hook("several_hooks"),
+ make_null_shared_ptr());
+ EXPECT_EQ(7, result.max_exit_status());
+ EXPECT_EQ("", result.output());
-#ifdef ENABLE_PYTHON_HOOKS
- TEST_CHECK_EQUAL(line, "e\nc\nf\nd\nb\na\npy_hook\ng\ni\nh\nsohook\nk\nj\n");
-#else
- TEST_CHECK_EQUAL(line, "e\nc\nf\nd\nb\na\ng\ni\nh\nsohook\nk\nj\n");
-#endif
+}
+
+TEST(Hooker, Ordering)
+{
+ TestEnvironment env;
+ Hooker hooker(&env);
- }
- } test_hooker_ordering;
+ FSPath("hooker_TEST_dir/ordering.out").unlink();
- struct HookerBadHooksTest : TestCase
- {
- HookerBadHooksTest() : TestCase("hooker bad hooks") { }
+ hooker.add_dir(FSPath("hooker_TEST_dir/"), false);
+ HookResult result(hooker.perform_hook(Hook("ordering"),
+ make_null_shared_ptr()));
+ EXPECT_EQ(0, result.max_exit_status());
+ EXPECT_EQ("", result.output());
- void run()
- {
- TestEnvironment env;
- Hooker hooker(&env);
+ SafeIFStream f(FSPath("hooker_TEST_dir/ordering.out"));
+ std::string line((std::istreambuf_iterator<char>(f)), std::istreambuf_iterator<char>());
- FSPath("hooker_TEST_dir/bad_hooks.out").unlink();
+#ifdef ENABLE_PYTHON_HOOKS
+ EXPECT_EQ("e\nc\nf\nd\nb\na\npy_hook\ng\ni\nh\nsohook\nk\nj\n", line);
+#else
+ EXPECT_EQ("e\nc\nf\nd\nb\na\ng\ni\nh\nsohook\nk\nj\n", line);
+#endif
- hooker.add_dir(FSPath("hooker_TEST_dir/"), false);
- HookResult result(hooker.perform_hook(Hook("bad_hooks"),
- make_null_shared_ptr()));
- TEST_CHECK_EQUAL(result.max_exit_status(), 123);
- TEST_CHECK_EQUAL(result.output(), "");
+}
- SafeIFStream f(FSPath("hooker_TEST_dir/bad_hooks.out"));
- std::string line((std::istreambuf_iterator<char>(f)), std::istreambuf_iterator<char>());
+TEST(Hooker, BadHooks)
+{
+ TestEnvironment env;
+ Hooker hooker(&env);
+
+ FSPath("hooker_TEST_dir/bad_hooks.out").unlink();
- TEST_CHECK_EQUAL(line, "one\nthree\n");
- }
- } test_hooker_bad_hooks;
+ hooker.add_dir(FSPath("hooker_TEST_dir/"), false);
+ HookResult result(hooker.perform_hook(Hook("bad_hooks"),
+ make_null_shared_ptr()));
+ EXPECT_EQ(123, result.max_exit_status());
+ EXPECT_EQ("", result.output());
- struct HookerCyclesTest : TestCase
- {
- HookerCyclesTest() : TestCase("hooker cycles") { }
+ SafeIFStream f(FSPath("hooker_TEST_dir/bad_hooks.out"));
+ std::string line((std::istreambuf_iterator<char>(f)), std::istreambuf_iterator<char>());
- void run()
- {
- TestEnvironment env;
- Hooker hooker(&env);
+ EXPECT_EQ("one\nthree\n", line);
+}
- FSPath("hooker_TEST_dir/cycles.out").unlink();
+TEST(Hooker, Cycles)
+{
+ TestEnvironment env;
+ Hooker hooker(&env);
- hooker.add_dir(FSPath("hooker_TEST_dir/"), false);
- HookResult result(hooker.perform_hook(Hook("cycles"),
- make_null_shared_ptr()));
- TEST_CHECK_EQUAL(result.max_exit_status(), 0);
- TEST_CHECK_EQUAL(result.output(), "");
+ FSPath("hooker_TEST_dir/cycles.out").unlink();
- SafeIFStream f(FSPath("hooker_TEST_dir/cycles.out"));
- std::string line((std::istreambuf_iterator<char>(f)), std::istreambuf_iterator<char>());
+ hooker.add_dir(FSPath("hooker_TEST_dir/"), false);
+ HookResult result(hooker.perform_hook(Hook("cycles"),
+ make_null_shared_ptr()));
+ EXPECT_EQ(0, result.max_exit_status());
+ EXPECT_EQ("", result.output());
- TEST_CHECK_EQUAL(line, "b\na\ng\nf\ni\n");
- }
- } test_hooker_cycles;
+ SafeIFStream f(FSPath("hooker_TEST_dir/cycles.out"));
+ std::string line((std::istreambuf_iterator<char>(f)), std::istreambuf_iterator<char>());
- struct HookerOutputTest : TestCase
- {
- HookerOutputTest() : TestCase("hooker output") { }
+ EXPECT_EQ("b\na\ng\nf\ni\n", line);
+}
- void run()
- {
- TestEnvironment env;
- Hooker hooker(&env);
- HookResult result(make_named_values<HookResult>(n::max_exit_status() = 0, n::output() = ""));
+TEST(Hooker, Output)
+{
+ TestEnvironment env;
+ Hooker hooker(&env);
+ HookResult result(make_named_values<HookResult>(n::max_exit_status() = 0, n::output() = ""));
- FSPath("hooker_TEST_dir/several_output.out").unlink();
+ FSPath("hooker_TEST_dir/several_output.out").unlink();
- hooker.add_dir(FSPath("hooker_TEST_dir/"), false);
+ hooker.add_dir(FSPath("hooker_TEST_dir/"), false);
- result = hooker.perform_hook(Hook("simple_hook_output")
- .grab_output(Hook::AllowedOutputValues()("foo")),
- make_null_shared_ptr());
- TEST_CHECK_EQUAL(result.max_exit_status(), 0);
- TEST_CHECK_EQUAL(result.output(), "foo");
+ result = hooker.perform_hook(Hook("simple_hook_output")
+ .grab_output(Hook::AllowedOutputValues()("foo")),
+ make_null_shared_ptr());
+ EXPECT_EQ(0, result.max_exit_status());
+ EXPECT_EQ("foo", result.output());
- result = hooker.perform_hook(Hook("fancy_hook_output")
- .grab_output(Hook::AllowedOutputValues()("foo")),
- make_null_shared_ptr());
- TEST_CHECK_EQUAL(result.max_exit_status(), 0);
- TEST_CHECK_EQUAL(result.output(), "foo");
+ result = hooker.perform_hook(Hook("fancy_hook_output")
+ .grab_output(Hook::AllowedOutputValues()("foo")),
+ make_null_shared_ptr());
+ EXPECT_EQ(0, result.max_exit_status());
+ EXPECT_EQ("foo", result.output());
- result = hooker.perform_hook(Hook("so_hook_output")
- .grab_output(Hook::AllowedOutputValues()("foo")),
- make_null_shared_ptr());
- TEST_CHECK_EQUAL(result.max_exit_status(), 0);
- TEST_CHECK_EQUAL(result.output(), "foo");
+ result = hooker.perform_hook(Hook("so_hook_output")
+ .grab_output(Hook::AllowedOutputValues()("foo")),
+ make_null_shared_ptr());
+ EXPECT_EQ(0, result.max_exit_status());
+ EXPECT_EQ("foo", result.output());
#ifdef ENABLE_PYTHON_HOOKS
- result = hooker.perform_hook(Hook("py_hook_output")
- .grab_output(Hook::AllowedOutputValues()("foo")),
- make_null_shared_ptr());
- TEST_CHECK_EQUAL(result.max_exit_status(), 0);
- TEST_CHECK_EQUAL(result.output(), "foo");
+ result = hooker.perform_hook(Hook("py_hook_output")
+ .grab_output(Hook::AllowedOutputValues()("foo")),
+ make_null_shared_ptr());
+ EXPECT_EQ(0, result.max_exit_status());
+ EXPECT_EQ("foo", result.output());
#endif
- result = hooker.perform_hook(Hook("several_hooks_output")
- .grab_output(Hook::AllowedOutputValues()),
- make_null_shared_ptr());
- TEST_CHECK_EQUAL(result.max_exit_status(), 0);
- TEST_CHECK_EQUAL(result.output(), "one");
-
- result = hooker.perform_hook(Hook("several_hooks_output")
- .grab_output(Hook::AllowedOutputValues()("one")),
- make_null_shared_ptr());
- TEST_CHECK_EQUAL(result.max_exit_status(), 0);
- TEST_CHECK_EQUAL(result.output(), "one");
+ result = hooker.perform_hook(Hook("several_hooks_output")
+ .grab_output(Hook::AllowedOutputValues()),
+ make_null_shared_ptr());
+ EXPECT_EQ(0, result.max_exit_status());
+ EXPECT_EQ("one", result.output());
- result = hooker.perform_hook(Hook("several_hooks_output")
- .grab_output(Hook::AllowedOutputValues()("two")("three")),
- make_null_shared_ptr());
- TEST_CHECK_EQUAL(result.max_exit_status(), 0);
- TEST_CHECK_EQUAL(result.output(), "two");
+ result = hooker.perform_hook(Hook("several_hooks_output")
+ .grab_output(Hook::AllowedOutputValues()("one")),
+ make_null_shared_ptr());
+ EXPECT_EQ(0, result.max_exit_status());
+ EXPECT_EQ("one", result.output());
- result = hooker.perform_hook(Hook("several_hooks_output")
- .grab_output(Hook::AllowedOutputValues()("blah")),
- make_null_shared_ptr());
- TEST_CHECK_EQUAL(result.output(), "");
- TEST_CHECK_EQUAL(result.max_exit_status(), 0);
+ result = hooker.perform_hook(Hook("several_hooks_output")
+ .grab_output(Hook::AllowedOutputValues()("two")("three")),
+ make_null_shared_ptr());
+ EXPECT_EQ(0, result.max_exit_status());
+ EXPECT_EQ("two", result.output());
- SafeIFStream f(FSPath("hooker_TEST_dir/several_output.out"));
- std::string line((std::istreambuf_iterator<char>(f)), std::istreambuf_iterator<char>());
+ result = hooker.perform_hook(Hook("several_hooks_output")
+ .grab_output(Hook::AllowedOutputValues()("blah")),
+ make_null_shared_ptr());
+ EXPECT_EQ("", result.output());
+ EXPECT_EQ(0, result.max_exit_status());
- TEST_CHECK_EQUAL(line, "one\none\none\ntwo\none\ntwo\nthree\n");
+ SafeIFStream f(FSPath("hooker_TEST_dir/several_output.out"));
+ std::string line((std::istreambuf_iterator<char>(f)), std::istreambuf_iterator<char>());
- }
- } test_hooker_output;
+ EXPECT_EQ("one\none\none\ntwo\none\ntwo\nthree\n", line);
- struct HookerBadOutputHooksTest : TestCase
- {
- HookerBadOutputHooksTest() : TestCase("hooker bad ouput hooks") { }
+}
- void run()
- {
- TestEnvironment env;
- Hooker hooker(&env);
+TEST(Hooker, BadOutput)
+{
+ TestEnvironment env;
+ Hooker hooker(&env);
- FSPath("hooker_TEST_dir/several_output_bad.out").unlink();
+ FSPath("hooker_TEST_dir/several_output_bad.out").unlink();
- hooker.add_dir(FSPath("hooker_TEST_dir/"), false);
+ hooker.add_dir(FSPath("hooker_TEST_dir/"), false);
- HookResult result(hooker.perform_hook(Hook("several_hooks_output_bad")
- .grab_output(Hook::AllowedOutputValues()),
- make_null_shared_ptr()));
- TEST_CHECK_EQUAL(result.output(), "two");
- TEST_CHECK_EQUAL(result.max_exit_status(), 99);
+ HookResult result(hooker.perform_hook(Hook("several_hooks_output_bad")
+ .grab_output(Hook::AllowedOutputValues()),
+ make_null_shared_ptr()));
+ EXPECT_EQ("two", result.output());
+ EXPECT_EQ(99, result.max_exit_status());
- SafeIFStream f(FSPath("hooker_TEST_dir/several_output_bad.out"));
- std::string line((std::istreambuf_iterator<char>(f)), std::istreambuf_iterator<char>());
+ SafeIFStream f(FSPath("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");
- }
- } test_hooker_bad_output_hooks;
+ EXPECT_EQ("one\ntwo\nthree\n", line);
}
+