aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-05-18 10:10:10 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-05-18 10:10:10 +0000
commitd9e139d5563d97e4247ed59d16a4dca4cf282053 (patch)
tree5f6e304b6538b4b0502a8832963fe58b437ae59c
parent604bd6789d0ebb5baf7b64c076f999f6e0489287 (diff)
downloadpaludis-d9e139d5563d97e4247ed59d16a4dca4cf282053.tar.gz
paludis-d9e139d5563d97e4247ed59d16a4dca4cf282053.tar.xz
Fix output wrapper formatting, add test cases
-rw-r--r--paludis/util/files.m41
-rw-r--r--paludis/util/output_wrapper.cc6
-rw-r--r--paludis/util/output_wrapper_TEST.cc273
-rwxr-xr-xpaludis/util/output_wrapper_TEST_cleanup.sh10
-rwxr-xr-xpaludis/util/output_wrapper_TEST_setup.sh109
5 files changed, 399 insertions, 0 deletions
diff --git a/paludis/util/files.m4 b/paludis/util/files.m4
index f9f6481..774695f 100644
--- a/paludis/util/files.m4
+++ b/paludis/util/files.m4
@@ -27,6 +27,7 @@ add(`is_file_with_extension', `hh', `cc', `se', `test', `testscript')
add(`join', `hh', `test')
add(`log', `hh', `cc', `se', `test')
add(`options', `hh', `cc', `test')
+add(`output_wrapper', `test', `testscript')
add(`pipe', `hh', `cc')
add(`private_implementation_pattern', `hh')
add(`pstream', `hh', `cc', `test')
diff --git a/paludis/util/output_wrapper.cc b/paludis/util/output_wrapper.cc
index 2ba19ae..90b5585 100644
--- a/paludis/util/output_wrapper.cc
+++ b/paludis/util/output_wrapper.cc
@@ -169,7 +169,10 @@ main(int argc, char *argv[])
stdout_had_interesting_char = true;
}
else if (! stdout_had_non_blanks)
+ {
++stdout_blanks;
+ continue;
+ }
if (! stdout_prefix_shown)
{
@@ -216,7 +219,10 @@ main(int argc, char *argv[])
stderr_had_interesting_char = true;
}
else if (! stderr_had_non_blanks)
+ {
++stderr_blanks;
+ continue;
+ }
if (! stderr_prefix_shown)
{
diff --git a/paludis/util/output_wrapper_TEST.cc b/paludis/util/output_wrapper_TEST.cc
new file mode 100644
index 0000000..d640f47
--- /dev/null
+++ b/paludis/util/output_wrapper_TEST.cc
@@ -0,0 +1,273 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2007 Ciaran McCreesh <ciaranm@ciaranm.org>
+ *
+ * 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
+ * Public License version 2, as published by the Free Software Foundation.
+ *
+ * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <test/test_framework.hh>
+#include <test/test_runner.hh>
+
+#include <paludis/util/pstream.hh>
+#include <paludis/util/system.hh>
+#include <paludis/util/join.hh>
+
+#include <fstream>
+#include <iterator>
+#include <set>
+
+using namespace test;
+using namespace paludis;
+
+namespace test_cases
+{
+ struct StdoutPrefixTest : TestCase
+ {
+ StdoutPrefixTest() : TestCase("stdout prefix") { }
+
+ void run()
+ {
+ PStream p(Command("./outputwrapper --stdout-prefix 'o p ' -- "
+ "bash output_wrapper_TEST_dir/stdout_prefix.bash"));
+ std::string s((std::istreambuf_iterator<char>(p)), std::istreambuf_iterator<char>());
+ TEST_CHECK_EQUAL(s, "o p one\no p two\no p three\n");
+ TEST_CHECK_EQUAL(0, p.exit_status());
+ }
+ } test_stdout_prefix;
+
+ struct StderrPrefixTest : TestCase
+ {
+ StderrPrefixTest() : TestCase("stderr prefix") { }
+
+ void run()
+ {
+ PStream p(Command("./outputwrapper --stderr-prefix 'e p ' -- "
+ "bash output_wrapper_TEST_dir/stderr_prefix.bash 2>&1"));
+ std::string s((std::istreambuf_iterator<char>(p)), std::istreambuf_iterator<char>());
+ TEST_CHECK_EQUAL(s, "e p one\ne p two\ne p three\n");
+ TEST_CHECK_EQUAL(0, p.exit_status());
+ }
+ } test_stderr_prefix;
+
+ struct MixedPrefixTest : TestCase
+ {
+ MixedPrefixTest() : TestCase("mixed prefix") { }
+
+ void run()
+ {
+ PStream p(Command("./outputwrapper --stdout-prefix 'o p ' --stderr-prefix 'e p ' -- "
+ "bash output_wrapper_TEST_dir/mixed_prefix.bash 2>&1"));
+ std::multiset<std::string> lines;
+ std::string line;
+ while (std::getline(p, line))
+ lines.insert(line);
+
+ TestMessageSuffix s("lines=(" + join(lines.begin(), lines.end(), ",") + ")");
+ TEST_CHECK_EQUAL(lines.size(), static_cast<std::size_t>(3));
+ TEST_CHECK(lines.count("e p one"));
+ TEST_CHECK(lines.count("e p three"));
+ TEST_CHECK(lines.count("o p two"));
+ TEST_CHECK_EQUAL(0, p.exit_status());
+ }
+ } test_mixed_prefix;
+
+ struct LongLinesTest : TestCase
+ {
+ LongLinesTest() : TestCase("long lines") { }
+
+ void run()
+ {
+ PStream p(Command("bash output_wrapper_TEST_dir/long_lines.bash"));
+ std::multiset<std::string> lines;
+ std::string line;
+ while (std::getline(p, line))
+ lines.insert(line);
+
+ TestMessageSuffix s("lines=(" + join(lines.begin(), lines.end(), ",") + ")");
+ TEST_CHECK_EQUAL(lines.size(), static_cast<std::size_t>(2));
+ TEST_CHECK(lines.count("e p " + std::string(10000, 'e')));
+ TEST_CHECK(lines.count("o p " + std::string(10000, 'o')));
+ TEST_CHECK_EQUAL(0, p.exit_status());
+ }
+ } test_long_lines;
+
+ struct NoTrailingNewlineTest : TestCase
+ {
+ NoTrailingNewlineTest() : TestCase("no trailing newline") { }
+
+ void run()
+ {
+ PStream p(Command("bash output_wrapper_TEST_dir/no_trailing_newlines.bash 2>&1"));
+ std::multiset<std::string> lines;
+ std::string line;
+ while (std::getline(p, line))
+ lines.insert(line);
+
+ TestMessageSuffix s("lines=(" + join(lines.begin(), lines.end(), ",") + ")");
+ TEST_CHECK_EQUAL(lines.size(), static_cast<std::size_t>(1));
+ TEST_CHECK(lines.count("o p monkeye p pants"));
+ TEST_CHECK_EQUAL(0, p.exit_status());
+ }
+ } test_no_trailing_newline;
+
+ struct ExitStatusTest : TestCase
+ {
+ ExitStatusTest() : TestCase("exit status") { }
+
+ void run()
+ {
+ PStream p(Command("./outputwrapper --stdout-prefix 'o p ' --stderr-prefix 'e p ' -- "
+ "bash output_wrapper_TEST_dir/exit_status.bash 2>&1"));
+ std::multiset<std::string> lines;
+ std::string line;
+ while (std::getline(p, line))
+ lines.insert(line);
+
+ TestMessageSuffix s("lines=(" + join(lines.begin(), lines.end(), ",") + ")");
+ TEST_CHECK_EQUAL(lines.size(), static_cast<std::size_t>(2));
+ TEST_CHECK(lines.count("o p lorem ipsum dolor"));
+ TEST_CHECK(lines.count("e p sit amet"));
+ TEST_CHECK_EQUAL(5, p.exit_status());
+ }
+ } test_exit_status;
+
+ struct NoWrapBlanksTest : TestCase
+ {
+ NoWrapBlanksTest() : TestCase("no wrap blanks") { }
+
+ void run()
+ {
+ PStream p(Command("./outputwrapper --stdout-prefix 'o p ' --stderr-prefix 'e p ' -- "
+ "bash output_wrapper_TEST_dir/no_wrap_blanks.bash 2>&1"));
+ std::multiset<std::string> lines;
+ std::string line;
+ while (std::getline(p, line))
+ lines.insert(line);
+
+ TestMessageSuffix s("lines=(" + join(lines.begin(), lines.end(), ",") + ")");
+ TEST_CHECK_EQUAL(lines.size(), static_cast<std::size_t>(7));
+ TEST_CHECK(lines.count("e p one"));
+ TEST_CHECK(lines.count("e p three"));
+ TEST_CHECK(lines.count("o p two"));
+ TEST_CHECK_EQUAL(lines.count(""), static_cast<std::size_t>(4));
+ TEST_CHECK_EQUAL(0, p.exit_status());
+ }
+ } test_no_wrap_blanks;
+
+ struct WrapBlanksTest : TestCase
+ {
+ WrapBlanksTest() : TestCase("wrap blanks") { }
+
+ void run()
+ {
+ PStream p(Command("./outputwrapper --stdout-prefix 'o p ' --stderr-prefix 'e p ' --wrap-blanks -- "
+ "bash output_wrapper_TEST_dir/wrap_blanks.bash 2>&1"));
+ std::multiset<std::string> lines;
+ std::string line;
+ while (std::getline(p, line))
+ lines.insert(line);
+
+ TestMessageSuffix s("lines=(" + join(lines.begin(), lines.end(), ",") + ")");
+ TEST_CHECK_EQUAL(lines.size(), static_cast<std::size_t>(7));
+ TEST_CHECK(lines.count("e p one"));
+ TEST_CHECK(lines.count("e p three"));
+ TEST_CHECK(lines.count("o p two"));
+ TEST_CHECK_EQUAL(lines.count("e p "), static_cast<std::size_t>(2));
+ TEST_CHECK_EQUAL(lines.count("o p "), static_cast<std::size_t>(2));
+ TEST_CHECK_EQUAL(0, p.exit_status());
+ }
+ } test_wrap_blanks;
+
+ struct DiscardBlankOutputTest : TestCase
+ {
+ DiscardBlankOutputTest() : TestCase("discard blank output") { }
+
+ void run()
+ {
+ PStream p(Command("./outputwrapper --stdout-prefix 'o p ' --stderr-prefix 'e p ' --discard-blank-output -- "
+ "bash output_wrapper_TEST_dir/discard_blank_output.bash 2>&1"));
+ std::multiset<std::string> lines;
+ std::string line;
+ while (std::getline(p, line))
+ lines.insert(line);
+
+ TestMessageSuffix s("lines=(" + join(lines.begin(), lines.end(), ",") + ")");
+ TEST_CHECK_EQUAL(lines.size(), static_cast<std::size_t>(0));
+ TEST_CHECK_EQUAL(0, p.exit_status());
+ }
+ } test_discard_blank_output;
+
+ struct DiscardBlankOutputNotBlankTest : TestCase
+ {
+ DiscardBlankOutputNotBlankTest() : TestCase("discard blank output not blank") { }
+
+ void run()
+ {
+ PStream p(Command("./outputwrapper --stdout-prefix 'o p ' --stderr-prefix 'e p ' --discard-blank-output -- "
+ "bash output_wrapper_TEST_dir/discard_blank_output_not_blank.bash 2>&1"));
+ std::multiset<std::string> lines;
+ std::string line;
+ while (std::getline(p, line))
+ lines.insert(line);
+
+ TestMessageSuffix s("lines=(" + join(lines.begin(), lines.end(), ",") + ")");
+ TEST_CHECK_EQUAL(lines.size(), static_cast<std::size_t>(4));
+ TEST_CHECK(lines.count("o p monkey"));
+ TEST_CHECK_EQUAL(lines.count(""), static_cast<std::size_t>(3));
+ TEST_CHECK_EQUAL(0, p.exit_status());
+ }
+ } test_discard_blank_output_not_blank;
+
+ struct DiscardBlankWrapBlankOutputTest : TestCase
+ {
+ DiscardBlankWrapBlankOutputTest() : TestCase("discard wrap blank output") { }
+
+ void run()
+ {
+ PStream p(Command("./outputwrapper --stdout-prefix 'o p ' --stderr-prefix 'e p ' --discard-blank-output --wrap-blanks -- "
+ "bash output_wrapper_TEST_dir/discard_wrap_blank_output.bash 2>&1"));
+ std::multiset<std::string> lines;
+ std::string line;
+ while (std::getline(p, line))
+ lines.insert(line);
+
+ TestMessageSuffix s("lines=(" + join(lines.begin(), lines.end(), ",") + ")");
+ TEST_CHECK_EQUAL(lines.size(), static_cast<std::size_t>(0));
+ TEST_CHECK_EQUAL(0, p.exit_status());
+ }
+ } test_discard_wrap_blank_output;
+
+ struct DiscardBlankWrapBlankOutputNotBlankTest : TestCase
+ {
+ DiscardBlankWrapBlankOutputNotBlankTest() : TestCase("discard wrap blank output not blank") { }
+
+ void run()
+ {
+ PStream p(Command("./outputwrapper --stdout-prefix 'o p ' --stderr-prefix 'e p ' --discard-blank-output --wrap-blanks -- "
+ "bash output_wrapper_TEST_dir/discard_wrap_blank_output_not_blank.bash 2>&1"));
+ std::multiset<std::string> lines;
+ std::string line;
+ while (std::getline(p, line))
+ lines.insert(line);
+
+ TestMessageSuffix s("lines=(" + join(lines.begin(), lines.end(), ",") + ")");
+ TEST_CHECK_EQUAL(lines.size(), static_cast<std::size_t>(4));
+ TEST_CHECK(lines.count("o p monkey"));
+ TEST_CHECK_EQUAL(lines.count("o p "), static_cast<std::size_t>(3));
+ TEST_CHECK_EQUAL(0, p.exit_status());
+ }
+ } test_discard_wrap_blank_output_not_blank;
+}
+
diff --git a/paludis/util/output_wrapper_TEST_cleanup.sh b/paludis/util/output_wrapper_TEST_cleanup.sh
new file mode 100755
index 0000000..48e4dce
--- /dev/null
+++ b/paludis/util/output_wrapper_TEST_cleanup.sh
@@ -0,0 +1,10 @@
+#!/bin/bash
+# vim: set ft=sh sw=4 sts=4 et :
+
+if [ -d output_wrapper_TEST_dir ] ; then
+ rm -fr output_wrapper_TEST_dir
+else
+ true
+fi
+
+
diff --git a/paludis/util/output_wrapper_TEST_setup.sh b/paludis/util/output_wrapper_TEST_setup.sh
new file mode 100755
index 0000000..b467150
--- /dev/null
+++ b/paludis/util/output_wrapper_TEST_setup.sh
@@ -0,0 +1,109 @@
+#!/bin/bash
+# vim: set ft=sh sw=4 sts=4 et :
+
+mkdir output_wrapper_TEST_dir || exit 2
+cd output_wrapper_TEST_dir
+
+cat <<END > stdout_prefix.bash
+echo one
+echo two
+echo three
+END
+
+cat <<END > stderr_prefix.bash
+echo one 1>&2
+echo two 1>&2
+echo three 1>&2
+END
+
+cat <<END > mixed_prefix.bash
+echo one 1>&2
+echo two
+echo three 1>&2
+END
+
+cat <<END > real_long_lines.bash
+for (( a = 0 ; a < 1000 ; ++a )) ; do
+ echo -n eeeeeeeeee 1>&2
+ echo -n oooooooooo
+done
+echo 1>&2
+echo
+END
+
+cat <<END > long_lines.bash
+./outputwrapper --stdout-prefix 'o p ' --stderr-prefix 'e p ' -- \
+ bash output_wrapper_TEST_dir/real_long_lines.bash \
+ 1>output_wrapper_TEST_dir/long_lines_stdout \
+ 2>output_wrapper_TEST_dir/long_lines_stderr
+cat output_wrapper_TEST_dir/long_lines_stdout output_wrapper_TEST_dir/long_lines_stderr
+END
+
+cat <<END > real_no_trailing_newlines.bash
+echo -n monkey
+echo -n pants 1>&2
+END
+
+cat <<END > no_trailing_newlines.bash
+./outputwrapper --stdout-prefix 'o p ' --stderr-prefix 'e p ' -- \
+ bash output_wrapper_TEST_dir/real_no_trailing_newlines.bash \
+ 1>output_wrapper_TEST_dir/no_trailing_newlines_stdout \
+ 2>output_wrapper_TEST_dir/no_trailing_newlines_stderr
+cat output_wrapper_TEST_dir/no_trailing_newlines_stdout output_wrapper_TEST_dir/no_trailing_newlines_stderr
+END
+
+cat <<END > exit_status.bash
+echo lorem ipsum dolor
+echo sit amet 1>&2
+exit 5
+END
+
+cat <<END > no_wrap_blanks.bash
+echo
+echo one 1>&2
+echo 1>&2
+echo two
+echo three 1>&2
+echo 1>&2
+echo
+END
+
+cat <<END > wrap_blanks.bash
+echo
+echo one 1>&2
+echo 1>&2
+echo two
+echo three 1>&2
+echo 1>&2
+echo
+END
+
+cat <<END > discard_blank_output.bash
+echo
+echo 1>&2
+echo
+END
+
+cat <<END > discard_blank_output_not_blank.bash
+echo
+echo 1>&2
+echo
+echo monkey
+echo
+END
+
+cat <<END > discard_wrap_blank_output.bash
+echo
+echo 1>&2
+echo
+END
+
+cat <<END > discard_wrap_blank_output_not_blank.bash
+echo
+echo 1>&2
+echo
+echo monkey
+echo
+END
+
+