]> git.localhorst.tv Git - blank.git/commitdiff
test missing option arguments
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Fri, 25 Nov 2016 15:04:36 +0000 (16:04 +0100)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Fri, 25 Nov 2016 15:04:36 +0000 (16:04 +0100)
tst/integration/InvocationTest.cpp
tst/integration/InvocationTest.hpp
tst/integration/StandaloneTest.cpp
tst/integration/TestInstance.cpp
tst/integration/TestInstance.hpp

index 70fd47ff4928c7408125077863e5b84fc70c4f2c..fc3ed426344abd476114d6fa072eee7a3131fbcf 100644 (file)
@@ -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<std::string> 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();
+       }
 }
 
 }
index cca53dd52afcff0501c31053b89cc740f728ba49..235b643551b13bdf77822368af3d9909087370c4 100644 (file)
@@ -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();
 
 };
 
index 95dfc3a2568592607b313f9e6ee3398062a605b1..0431b5778d3f9de636674bcd402c69fd377c3850 100644 (file)
@@ -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();
 }
 
index 135d17c02b0d9ce750742fd2f0c81473b8e06ebd..df87bfd4146e6affd4894201182edd5ddf13b99f 100644 (file)
@@ -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()
index 25fb08cae5a464e61ceb02369aabe50bbe677967..01fb25d65fffa74902175a118688f1b77ce86191 100644 (file)
@@ -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: