mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 13:45:38 +00:00
virshtest: Add test cases for command completion helper
Add both single invocations as well as a script containing the same commands. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
9950aef282
commit
b41bde935d
@ -96,6 +96,7 @@ struct testInfo {
|
|||||||
bool expensive;
|
bool expensive;
|
||||||
const char *const *env; /* extra environment variables to pass */
|
const char *const *env; /* extra environment variables to pass */
|
||||||
bool forbid_root;
|
bool forbid_root;
|
||||||
|
bool need_readline;
|
||||||
};
|
};
|
||||||
|
|
||||||
static int testCompare(const void *data)
|
static int testCompare(const void *data)
|
||||||
@ -109,6 +110,11 @@ static int testCompare(const void *data)
|
|||||||
if (info->forbid_root && geteuid() == 0)
|
if (info->forbid_root && geteuid() == 0)
|
||||||
return EXIT_AM_SKIP;
|
return EXIT_AM_SKIP;
|
||||||
|
|
||||||
|
# ifndef WITH_READLINE
|
||||||
|
if (info->need_readline)
|
||||||
|
return EXIT_AM_SKIP;
|
||||||
|
# endif
|
||||||
|
|
||||||
if (info->testname) {
|
if (info->testname) {
|
||||||
outfile = g_strdup_printf("%s/virshtestdata/%s.out",
|
outfile = g_strdup_printf("%s/virshtestdata/%s.out",
|
||||||
abs_srcdir, info->testname);
|
abs_srcdir, info->testname);
|
||||||
@ -206,6 +212,7 @@ static int
|
|||||||
mymain(void)
|
mymain(void)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
bool need_readline = false;
|
||||||
|
|
||||||
custom_uri = g_strdup_printf("test://%s/../examples/xml/test/testnode.xml",
|
custom_uri = g_strdup_printf("test://%s/../examples/xml/test/testnode.xml",
|
||||||
abs_srcdir);
|
abs_srcdir);
|
||||||
@ -217,7 +224,7 @@ mymain(void)
|
|||||||
abs_srcdir, testname); \
|
abs_srcdir, testname); \
|
||||||
const char *myargv[] = { __VA_ARGS__, NULL, NULL }; \
|
const char *myargv[] = { __VA_ARGS__, NULL, NULL }; \
|
||||||
const char **tmp = myargv; \
|
const char **tmp = myargv; \
|
||||||
const struct testInfo info = { testname, testfilter, myargv, expensive, NULL, false}; \
|
const struct testInfo info = { testname, testfilter, myargv, expensive, NULL, false, need_readline}; \
|
||||||
g_autofree char *scriptarg = NULL; \
|
g_autofree char *scriptarg = NULL; \
|
||||||
if (virFileReadAll(infile, 256 * 1024, &scriptarg) < 0) { \
|
if (virFileReadAll(infile, 256 * 1024, &scriptarg) < 0) { \
|
||||||
fprintf(stderr, "\nfailed to load '%s'\n", infile); \
|
fprintf(stderr, "\nfailed to load '%s'\n", infile); \
|
||||||
@ -246,7 +253,7 @@ mymain(void)
|
|||||||
# define DO_TEST_FULL(testname, filter, ...) \
|
# define DO_TEST_FULL(testname, filter, ...) \
|
||||||
do { \
|
do { \
|
||||||
const char *myargv[] = { __VA_ARGS__, NULL }; \
|
const char *myargv[] = { __VA_ARGS__, NULL }; \
|
||||||
const struct testInfo info = { testname, NULL, myargv, false, NULL, false }; \
|
const struct testInfo info = { testname, NULL, myargv, false, NULL, false, need_readline }; \
|
||||||
DO_TEST_INFO(&info); \
|
DO_TEST_INFO(&info); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
@ -342,6 +349,48 @@ mymain(void)
|
|||||||
"checkpoint-create test --redefine checkpoint-c2.xml ;"
|
"checkpoint-create test --redefine checkpoint-c2.xml ;"
|
||||||
"checkpoint-info test c2");
|
"checkpoint-info test c2");
|
||||||
|
|
||||||
|
/* completion doesn't work on non-readline builds */
|
||||||
|
need_readline = true;
|
||||||
|
|
||||||
|
DO_TEST_FULL("completion-command", NULL, VIRSH_CUSTOM,
|
||||||
|
"complete", "--", "ech");
|
||||||
|
DO_TEST_FULL("completion-command-complete", NULL, VIRSH_CUSTOM,
|
||||||
|
"complete", "--", "echo");
|
||||||
|
DO_TEST_FULL("completion-args", NULL, VIRSH_CUSTOM,
|
||||||
|
"complete", "--", "echo", "");
|
||||||
|
DO_TEST_FULL("completion-arg-partial", NULL, VIRSH_CUSTOM,
|
||||||
|
"complete", "--", "echo", "--xm", "--s");
|
||||||
|
DO_TEST_FULL("completion-arg-full-bool", NULL, VIRSH_CUSTOM,
|
||||||
|
"complete", "--", "echo", "--nonexistant-arg", "--xml");
|
||||||
|
DO_TEST_FULL("completion-arg-full-bool-next", NULL, VIRSH_CUSTOM,
|
||||||
|
"complete", "--", "echo", "--nonexistant-arg", "--xml", "");
|
||||||
|
DO_TEST_FULL("completion-arg-full-string", NULL, VIRSH_CUSTOM,
|
||||||
|
"complete", "--", "echo", "--nonexistant-arg", "--prefix");
|
||||||
|
DO_TEST_FULL("completion-arg-full-string-next", NULL, VIRSH_CUSTOM,
|
||||||
|
"complete", "--", "echo", "--nonexistant-arg", "--prefix", "");
|
||||||
|
DO_TEST_FULL("completion-arg-full-argv", NULL, VIRSH_CUSTOM,
|
||||||
|
"complete", "--", "domstats", "--domain");
|
||||||
|
DO_TEST_FULL("completion-arg-full-argv-next", NULL, VIRSH_DEFAULT,
|
||||||
|
"complete", "--", "domstats", "--domain", "");
|
||||||
|
DO_TEST_FULL("completion-argv-multiple", NULL, VIRSH_CUSTOM,
|
||||||
|
"complete", "--", "domstats", "--domain", "fc", "--domain", "fv");
|
||||||
|
DO_TEST_FULL("completion-argv-multiple-next", NULL, VIRSH_CUSTOM,
|
||||||
|
"complete", "--", "domstats", "--domain", "fv", "--domain", "fc", "");
|
||||||
|
DO_TEST_FULL("completion-argv-multiple-positional", NULL, VIRSH_CUSTOM,
|
||||||
|
"complete", "--", "domstats", "--domain", "fc", "fv");
|
||||||
|
DO_TEST_FULL("completion-argv-multiple-positional-next", NULL, VIRSH_CUSTOM,
|
||||||
|
"complete", "--", "domstats", "--domain", "fc", "fv", "");
|
||||||
|
DO_TEST_FULL("completion-arg-positional-empty", NULL, VIRSH_CUSTOM,
|
||||||
|
"complete", "--", "domstate", "");
|
||||||
|
DO_TEST_FULL("completion-arg-positional-partial", NULL, VIRSH_CUSTOM,
|
||||||
|
"complete", "--", "domstate", "fv");
|
||||||
|
DO_TEST_FULL("completion-arg-positional-partial-next", NULL, VIRSH_CUSTOM,
|
||||||
|
"complete", "--", "domstate", "fv", "");
|
||||||
|
|
||||||
|
DO_TEST_SCRIPT("completion", NULL, VIRSH_DEFAULT);
|
||||||
|
|
||||||
|
need_readline = false;
|
||||||
|
|
||||||
if (virTestRun("read-big-pipe", testVirshPipe, NULL) < 0)
|
if (virTestRun("read-big-pipe", testVirshPipe, NULL) < 0)
|
||||||
ret = -1;
|
ret = -1;
|
||||||
|
|
||||||
@ -369,7 +418,7 @@ mymain(void)
|
|||||||
const char *uriTest = "uri; connect; uri";
|
const char *uriTest = "uri; connect; uri";
|
||||||
const char *myargv_noconnect[] = { abs_top_builddir "/tools/virsh", uriTest, NULL };
|
const char *myargv_noconnect[] = { abs_top_builddir "/tools/virsh", uriTest, NULL };
|
||||||
const char *xdgDirBad = "XDG_CONFIG_HOME=" abs_srcdir "/virshtestdata/uriprecedence-xdg/bad/";
|
const char *xdgDirBad = "XDG_CONFIG_HOME=" abs_srcdir "/virshtestdata/uriprecedence-xdg/bad/";
|
||||||
struct testInfo info = { NULL, NULL, myargv_noconnect, false, NULL, false };
|
struct testInfo info = { NULL, NULL, myargv_noconnect, false, NULL, false, false };
|
||||||
|
|
||||||
/* test 1 - default from config */
|
/* test 1 - default from config */
|
||||||
{
|
{
|
||||||
|
2
tests/virshtestdata/completion-arg-full-argv-next.out
Normal file
2
tests/virshtestdata/completion-arg-full-argv-next.out
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
test
|
||||||
|
|
2
tests/virshtestdata/completion-arg-full-argv.out
Normal file
2
tests/virshtestdata/completion-arg-full-argv.out
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
--domain
|
||||||
|
|
7
tests/virshtestdata/completion-arg-full-bool-next.out
Normal file
7
tests/virshtestdata/completion-arg-full-bool-next.out
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
--shell
|
||||||
|
--xml
|
||||||
|
--split
|
||||||
|
--err
|
||||||
|
--prefix
|
||||||
|
--string
|
||||||
|
|
2
tests/virshtestdata/completion-arg-full-bool.out
Normal file
2
tests/virshtestdata/completion-arg-full-bool.out
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
--xml
|
||||||
|
|
7
tests/virshtestdata/completion-arg-full-string-next.out
Normal file
7
tests/virshtestdata/completion-arg-full-string-next.out
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
--shell
|
||||||
|
--xml
|
||||||
|
--split
|
||||||
|
--err
|
||||||
|
--prefix
|
||||||
|
--string
|
||||||
|
|
2
tests/virshtestdata/completion-arg-full-string.out
Normal file
2
tests/virshtestdata/completion-arg-full-string.out
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
--prefix
|
||||||
|
|
4
tests/virshtestdata/completion-arg-partial.out
Normal file
4
tests/virshtestdata/completion-arg-partial.out
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
--shell
|
||||||
|
--split
|
||||||
|
--string
|
||||||
|
|
3
tests/virshtestdata/completion-arg-positional-empty.out
Normal file
3
tests/virshtestdata/completion-arg-positional-empty.out
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
--domain
|
||||||
|
--reason
|
||||||
|
|
@ -0,0 +1,2 @@
|
|||||||
|
--reason
|
||||||
|
|
@ -0,0 +1,2 @@
|
|||||||
|
fv0
|
||||||
|
|
7
tests/virshtestdata/completion-args.out
Normal file
7
tests/virshtestdata/completion-args.out
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
--shell
|
||||||
|
--xml
|
||||||
|
--split
|
||||||
|
--err
|
||||||
|
--prefix
|
||||||
|
--string
|
||||||
|
|
25
tests/virshtestdata/completion-argv-multiple-next.out
Normal file
25
tests/virshtestdata/completion-argv-multiple-next.out
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
--state
|
||||||
|
--cpu-total
|
||||||
|
--balloon
|
||||||
|
--vcpu
|
||||||
|
--interface
|
||||||
|
--block
|
||||||
|
--perf
|
||||||
|
--iothread
|
||||||
|
--memory
|
||||||
|
--dirtyrate
|
||||||
|
--vm
|
||||||
|
--list-active
|
||||||
|
--list-inactive
|
||||||
|
--list-persistent
|
||||||
|
--list-transient
|
||||||
|
--list-running
|
||||||
|
--list-paused
|
||||||
|
--list-shutoff
|
||||||
|
--list-other
|
||||||
|
--raw
|
||||||
|
--enforce
|
||||||
|
--backing
|
||||||
|
--nowait
|
||||||
|
--domain
|
||||||
|
|
@ -0,0 +1,25 @@
|
|||||||
|
--state
|
||||||
|
--cpu-total
|
||||||
|
--balloon
|
||||||
|
--vcpu
|
||||||
|
--interface
|
||||||
|
--block
|
||||||
|
--perf
|
||||||
|
--iothread
|
||||||
|
--memory
|
||||||
|
--dirtyrate
|
||||||
|
--vm
|
||||||
|
--list-active
|
||||||
|
--list-inactive
|
||||||
|
--list-persistent
|
||||||
|
--list-transient
|
||||||
|
--list-running
|
||||||
|
--list-paused
|
||||||
|
--list-shutoff
|
||||||
|
--list-other
|
||||||
|
--raw
|
||||||
|
--enforce
|
||||||
|
--backing
|
||||||
|
--nowait
|
||||||
|
--domain
|
||||||
|
|
@ -0,0 +1,2 @@
|
|||||||
|
fv0
|
||||||
|
|
2
tests/virshtestdata/completion-argv-multiple.out
Normal file
2
tests/virshtestdata/completion-argv-multiple.out
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
fv0
|
||||||
|
|
2
tests/virshtestdata/completion-command-complete.out
Normal file
2
tests/virshtestdata/completion-command-complete.out
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
echo
|
||||||
|
|
2
tests/virshtestdata/completion-command.out
Normal file
2
tests/virshtestdata/completion-command.out
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
echo
|
||||||
|
|
16
tests/virshtestdata/completion.in
Normal file
16
tests/virshtestdata/completion.in
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
complete -- ech
|
||||||
|
complete -- echo
|
||||||
|
complete -- echo ''
|
||||||
|
complete -- echo --xm --s
|
||||||
|
complete -- echo --nonexistant-arg --xml
|
||||||
|
complete -- echo --nonexistant-arg --xml ''
|
||||||
|
complete -- echo --nonexistant-arg --prefix
|
||||||
|
complete -- echo --nonexistant-arg --prefix ''
|
||||||
|
complete -- domstats --domain
|
||||||
|
complete -- domstats --domain ''
|
||||||
|
complete -- domstats --domain f
|
||||||
|
complete -- domstats --domain fc --domain fv
|
||||||
|
complete -- domstats --domain fv --domain fc ''
|
||||||
|
complete -- domstats --domain fc fv
|
||||||
|
complete -- domstate ''
|
||||||
|
complete -- domstate fv
|
71
tests/virshtestdata/completion.out
Normal file
71
tests/virshtestdata/completion.out
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
echo
|
||||||
|
|
||||||
|
echo
|
||||||
|
|
||||||
|
--shell
|
||||||
|
--xml
|
||||||
|
--split
|
||||||
|
--err
|
||||||
|
--prefix
|
||||||
|
--string
|
||||||
|
|
||||||
|
--shell
|
||||||
|
--split
|
||||||
|
--string
|
||||||
|
|
||||||
|
--xml
|
||||||
|
|
||||||
|
--shell
|
||||||
|
--xml
|
||||||
|
--split
|
||||||
|
--err
|
||||||
|
--prefix
|
||||||
|
--string
|
||||||
|
|
||||||
|
--prefix
|
||||||
|
|
||||||
|
--shell
|
||||||
|
--xml
|
||||||
|
--split
|
||||||
|
--err
|
||||||
|
--prefix
|
||||||
|
--string
|
||||||
|
|
||||||
|
--domain
|
||||||
|
|
||||||
|
test
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
--state
|
||||||
|
--cpu-total
|
||||||
|
--balloon
|
||||||
|
--vcpu
|
||||||
|
--interface
|
||||||
|
--block
|
||||||
|
--perf
|
||||||
|
--iothread
|
||||||
|
--memory
|
||||||
|
--dirtyrate
|
||||||
|
--vm
|
||||||
|
--list-active
|
||||||
|
--list-inactive
|
||||||
|
--list-persistent
|
||||||
|
--list-transient
|
||||||
|
--list-running
|
||||||
|
--list-paused
|
||||||
|
--list-shutoff
|
||||||
|
--list-other
|
||||||
|
--raw
|
||||||
|
--enforce
|
||||||
|
--backing
|
||||||
|
--nowait
|
||||||
|
--domain
|
||||||
|
|
||||||
|
|
||||||
|
--domain
|
||||||
|
--reason
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## Exit code: 1
|
Loading…
Reference in New Issue
Block a user