mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-21 21:25:25 +00:00
virshtest: Add support for testing commands read from input file and adapt alias tests
Add support for reading a file and passing it to virsh in 'batch' mode so that multiple commands can be easily tested with one invocation of virsh. To show how it's used adapt the alias handling tests to be invoked all at once. As in batch mode the arguments are read from a string and separated inside virsh, one test is kept separate to be parsed in argv mode. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
f9dbd34c49
commit
fdaf2ffb04
@ -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;");
|
||||
|
3
tests/virshtestdata/echo-alias.in
Normal file
3
tests/virshtestdata/echo-alias.in
Normal file
@ -0,0 +1,3 @@
|
||||
echo --string hello
|
||||
echo --str hello
|
||||
echo --hi;
|
3
tests/virshtestdata/echo-alias.out
Normal file
3
tests/virshtestdata/echo-alias.out
Normal file
@ -0,0 +1,3 @@
|
||||
hello
|
||||
hello
|
||||
hello
|
Loading…
Reference in New Issue
Block a user