From 8368621fd8996569e3ca8fc6fd68ac0168742392 Mon Sep 17 00:00:00 2001 From: Daniel Karbach Date: Fri, 25 Nov 2016 16:04:36 +0100 Subject: [PATCH] test missing option arguments --- tst/integration/InvocationTest.cpp | 46 ++++++++++++++++++++++++++++-- tst/integration/InvocationTest.hpp | 4 +++ tst/integration/StandaloneTest.cpp | 2 +- tst/integration/TestInstance.cpp | 17 +++++++---- tst/integration/TestInstance.hpp | 2 +- 5 files changed, 62 insertions(+), 9 deletions(-) diff --git a/tst/integration/InvocationTest.cpp b/tst/integration/InvocationTest.cpp index 70fd47f..fc3ed42 100644 --- a/tst/integration/InvocationTest.cpp +++ b/tst/integration/InvocationTest.cpp @@ -2,7 +2,7 @@ #include "TestInstance.hpp" -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(blank::test::InvocationTest, "headed"); +CPPUNIT_TEST_SUITE_REGISTRATION(blank::test::InvocationTest); namespace blank { @@ -18,9 +18,51 @@ void InvocationTest::tearDown() { void InvocationTest::testUnknownArg() { - TestInstance prog({ "--worscht" }); + TestInstance prog({ "--worscht", "-W", "käs" }); prog.AssertErrorLine("unknown option --worscht"); + prog.AssertErrorLine("unknown option W"); + prog.AssertErrorLine("unable to interpret argument 3 (käs)"); prog.AssertExitStatus(1); + prog.AssertNoError(); + prog.AssertNoOutput(); +} + +void InvocationTest::testIncompleteOption() { + TestInstance prog({ + "-", + "", + "--", + "-" + }, false, false); + prog.AssertErrorLine("warning: incomplete option list at position 1"); + prog.AssertErrorLine("warning: found empty argument at position 2"); + prog.AssertErrorLine("unable to interpret argument 4 (-)"); + prog.AssertExitStatus(1); + prog.AssertNoError(); + prog.AssertNoOutput(); +} + +void InvocationTest::testMissingArgs() { + const std::vector opts_with_args = { + "--asset-path", + "--host", + "--port", + "--cmd-port", + "--player-name", + "--save-path", + "--world-name", + "-m", + "-n", + "-s", + "-t", + }; + for (auto arg : opts_with_args) { + TestInstance prog({ arg }, false, false); + prog.AssertErrorLine("missing argument to " + arg); + prog.AssertExitStatus(1); + prog.AssertNoError(); + prog.AssertNoOutput(); + } } } diff --git a/tst/integration/InvocationTest.hpp b/tst/integration/InvocationTest.hpp index cca53dd..235b643 100644 --- a/tst/integration/InvocationTest.hpp +++ b/tst/integration/InvocationTest.hpp @@ -13,6 +13,8 @@ class InvocationTest CPPUNIT_TEST_SUITE(InvocationTest); CPPUNIT_TEST(testUnknownArg); +CPPUNIT_TEST(testIncompleteOption); +CPPUNIT_TEST(testMissingArgs); CPPUNIT_TEST_SUITE_END(); @@ -21,6 +23,8 @@ public: void tearDown(); void testUnknownArg(); + void testIncompleteOption(); + void testMissingArgs(); }; diff --git a/tst/integration/StandaloneTest.cpp b/tst/integration/StandaloneTest.cpp index 95dfc3a..0431b57 100644 --- a/tst/integration/StandaloneTest.cpp +++ b/tst/integration/StandaloneTest.cpp @@ -10,7 +10,7 @@ namespace blank { namespace test { void StandaloneTest::setUp() { - instance.reset(new TestInstance({ "--no-vsync" })); + instance.reset(new TestInstance({ "--standalone", "--no-vsync" })); instance->AssertRunning(); } diff --git a/tst/integration/TestInstance.cpp b/tst/integration/TestInstance.cpp index 135d17c..df87bfd 100644 --- a/tst/integration/TestInstance.cpp +++ b/tst/integration/TestInstance.cpp @@ -10,13 +10,20 @@ namespace test { namespace { -Process::Arguments combine_args(const TempDir &dir, const Process::Arguments &in, bool cmd) { +Process::Arguments combine_args( + const TempDir &dir, + const Process::Arguments &in, + bool cmd, + bool temp_save +) { Process::Arguments out; out.reserve(in.size() + (cmd ? 5 : 3)); out.emplace_back("blank"); out.insert(out.end(), in.begin(), in.end()); - out.emplace_back("--save-path"); - out.emplace_back(dir.Path()); + if (temp_save) { + out.emplace_back("--save-path"); + out.emplace_back(dir.Path()); + } if (cmd) { out.emplace_back("--cmd-port"); out.emplace_back("12354"); @@ -26,9 +33,9 @@ Process::Arguments combine_args(const TempDir &dir, const Process::Arguments &in } -TestInstance::TestInstance(const Process::Arguments &args, bool cmd) +TestInstance::TestInstance(const Process::Arguments &args, bool cmd, bool temp_save) : dir() -, proc("./blank" BLANK_SUFFIX, combine_args(dir, args, cmd)) +, proc("./blank" BLANK_SUFFIX, combine_args(dir, args, cmd, temp_save)) , conn() , out_buf() , err_buf() diff --git a/tst/integration/TestInstance.hpp b/tst/integration/TestInstance.hpp index 25fb08c..01fb25d 100644 --- a/tst/integration/TestInstance.hpp +++ b/tst/integration/TestInstance.hpp @@ -20,7 +20,7 @@ public: /// will be prepended by the constructor). /// If connect is true, a command service connection will be /// established during construction. - explicit TestInstance(const Process::Arguments &args, bool connect = false); + explicit TestInstance(const Process::Arguments &args, bool connect = false, bool temp_save = true); ~TestInstance(); public: -- 2.39.2