From: Justin Cinkelj <justin.cink...@xlab.si>
Committer: Nadav Har'El <n...@scylladb.com>
Branch: master

tests: add test for commandline runscript option

Also, double 'return false' is removed from one function.

Signed-off-by: Justin Cinkelj <justin.cink...@xlab.si>
Message-Id: <1479825169-15499-3-git-send-email-justin.cink...@xlab.si>

---
diff --git a/tests/tst-commands.cc b/tests/tst-commands.cc
--- a/tests/tst-commands.cc
+++ b/tests/tst-commands.cc
@@ -9,6 +9,7 @@
 #include <cstdio>

 #include <osv/commands.hh>
+#include <fstream>

 static int tests = 0, fails = 0;

@@ -283,7 +284,6 @@ static bool test_cpiod_haproxy()

     for (size_t i = 0; i < result.size(); i++) {
         if (result[i][0] != cmd[i]) {
-        return false;
             return false;
         }
     }
@@ -299,6 +299,60 @@ static bool test_cpiod_haproxy()
     return true;
 }

+static bool test_runscript_multiple_with_args_quotes()
+{
+    // Script without \n at the end
+    std::ofstream of1("/zpool-list", std::ios::out | std::ios::binary);
+    of1 << "/zpool.so list";
+    of1.close();
+    // Script with \n at the end
+    std::ofstream of2("/myprog-prm");
+    of2 << "/myprog.so prm1 \"prm2a prm2b\" prm3\n";
+    of2.close();
+
+    std::vector<std::vector<std::string> > result;
+    std::vector<std::string> cmd = { "/zpool.so", "/myprog.so" };
+    bool ok;
+
+    result = osv::parse_command_line(
+        std::string("runscript \"/zpool-list\"; runscript /myprog-prm  "),
+        ok);
+
+    if (!ok) {
+        return false;
+    }
+
+    if (result.size() != 2) {
+        return false;
+    }
+
+    if (result[0].size() != 3) {
+        return false;
+    }
+
+    if (result[1].size() != 5) {
+        return false;
+    }
+
+    for (size_t i = 0; i < result.size(); i++) {
+        if (result[i][0] != cmd[i]) {
+            return false;
+        }
+    }
+
+    if (result[1][1] != std::string("prm1")) {
+        return false;
+    }
+    if (result[1][2] != std::string("prm2a prm2b")) {
+        return false;
+    }
+    if (result[1][3] != std::string("prm3")) {
+        return false;
+    }
+
+    return true;
+}
+
 int main(int argc, char *argv[])
 {
     report(test_parse_simplest(), "simplest command line");
@@ -313,6 +367,8 @@ int main(int argc, char *argv[])
            "simple multiple commands with quotes");
     report(test_cpiod_haproxy(),
            "cpiod upload and haproxy launch");
+    report(test_runscript_multiple_with_args_quotes(),
+           "runscript multiple with args and quotes");
     printf("SUMMARY: %d tests, %d failures\n", tests, fails);
     return 0;
 }

--
You received this message because you are subscribed to the Google Groups "OSv 
Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to osv-dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to