diff --git a/tests/virshtest.c b/tests/virshtest.c index e0b5cd3150..376fb861ed 100644 --- a/tests/virshtest.c +++ b/tests/virshtest.c @@ -561,6 +561,26 @@ mymain(void) testIOThreadPin, NULL) != 0) ret = -1; +# define DO_TEST_SCRIPT(testname_, testfilter, ...) \ + { \ + const char *testname = testname_; \ + g_autofree char *infile = g_strdup_printf("%s/virshtestdata/%s.in", \ + abs_srcdir, testname); \ + const char *myargv[] = { __VA_ARGS__, NULL, NULL }; \ + const char **tmp = myargv; \ + const struct testInfo info = { testname, testfilter, myargv, NULL }; \ + g_autofree char *scriptarg = NULL; \ + if (virFileReadAll(infile, 256 * 1024, &scriptarg) < 0) { \ + fprintf(stderr, "\nfailed to load '%s'\n", infile); \ + ret = -1; \ + } \ + while (*tmp) \ + tmp++; \ + *tmp = scriptarg; \ + if (virTestRun(testname, testCompare, &info) < 0) \ + ret = -1; \ + } while (0); + /* It's a bit awkward listing result before argument, but that's a * limitation of C99 vararg macros. */ # define DO_TEST(i, result, ...) \ @@ -644,11 +664,8 @@ mymain(void) "echo \t '-'\"-\" \t --shell \t a"); /* Tests of alias handling. */ - DO_TEST(31, "hello\n", "echo", "--string", "hello"); - DO_TEST(32, "hello\n", "echo --string hello"); + DO_TEST_SCRIPT("echo-alias", NULL, VIRSH_DEFAULT); DO_TEST(33, "hello\n", "echo", "--str", "hello"); - DO_TEST(34, "hello\n", "echo --str hello"); - DO_TEST(35, "hello\n", "echo --hi"); /* Tests of multiple commands. */ DO_TEST(36, "a\nb\n", " echo a; echo b;"); diff --git a/tests/virshtestdata/echo-alias.in b/tests/virshtestdata/echo-alias.in new file mode 100644 index 0000000000..f123437490 --- /dev/null +++ b/tests/virshtestdata/echo-alias.in @@ -0,0 +1,3 @@ +echo --string hello +echo --str hello +echo --hi; diff --git a/tests/virshtestdata/echo-alias.out b/tests/virshtestdata/echo-alias.out new file mode 100644 index 0000000000..640bb73cf1 --- /dev/null +++ b/tests/virshtestdata/echo-alias.out @@ -0,0 +1,3 @@ +hello +hello +hello