#include "TestInstance.hpp"
-CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(blank::test::InvocationTest, "headed");
+CPPUNIT_TEST_SUITE_REGISTRATION(blank::test::InvocationTest);
namespace blank {
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();
+ }
}
}
CPPUNIT_TEST_SUITE(InvocationTest);
CPPUNIT_TEST(testUnknownArg);
+CPPUNIT_TEST(testIncompleteOption);
+CPPUNIT_TEST(testMissingArgs);
CPPUNIT_TEST_SUITE_END();
void tearDown();
void testUnknownArg();
+ void testIncompleteOption();
+ void testMissingArgs();
};
namespace test {
void StandaloneTest::setUp() {
- instance.reset(new TestInstance({ "--no-vsync" }));
+ instance.reset(new TestInstance({ "--standalone", "--no-vsync" }));
instance->AssertRunning();
}
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");
}
-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()
/// 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: