Skip to content

Commit

Permalink
[#906] replace variable with TimeUnit enum values before sourcing scr…
Browse files Browse the repository at this point in the history
…ipt; test --timeUnit values
  • Loading branch information
remkop committed Jan 13, 2020
1 parent fa2276b commit a054f50
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 41 deletions.
3 changes: 2 additions & 1 deletion src/test/dejagnu.tests/completion/basic.exp
Expand Up @@ -18,7 +18,8 @@ set script "$srcdir/../resources/basic.bash"
#set script "/mnt/c/Users/remko/IdeaProjects/picocli3/src/test/resources/basic.bash"

verbose "sending 'source $script\r' to the shell..."
send "source $script\r"
#send "source $script\r"
send "source <(cat $script | sed s/%2\\\$s/NANOSECONDS\\ MICROSECONDS\\ MILLISECONDS\\ SECONDS\\ MINUTES\\ HOURS\\ DAYS/g)\r"

set cmd "basicExample"
assert_source_completions "$cmd"
Expand Down
3 changes: 2 additions & 1 deletion src/test/dejagnu.tests/completion/picocompletion.exp
Expand Up @@ -19,7 +19,8 @@ set script "$srcdir/../resources/picocompletion-demo_completion.bash"
#set script "/mnt/c/Users/remko/IdeaProjects/picocli3/src/test/resources/picocompletion-demo_completion.bash"

verbose "sending 'source $script\r' to the shell..."
send "source $script\r"
#send "source $script\r"
send "source <(cat $script | sed s/%2\\\$s/NANOSECONDS\\ MICROSECONDS\\ MILLISECONDS\\ SECONDS\\ MINUTES\\ HOURS\\ DAYS/g)\r"

set cmd "picocompletion-demo"
assert_source_completions "$cmd"
47 changes: 28 additions & 19 deletions src/test/dejagnu.tests/lib/completions/basicExample.exp
Expand Up @@ -6,33 +6,42 @@ proc teardown {} {
assert_env_unmodified {/OLDPWD=/d}
}

proc run_completion_test {cmd test candidates} {
verbose "Sending ${cmd}\t..."
send "${cmd}\t"

expect "${cmd}\r\n"
expect {
-re $candidates { pass "$test" }
-re /@ { unresolved "$test at prompt" }
default { unresolved "$test" }
}
sync_after_int
}

setup


# Try completion with one hyphen
set cmd "basicExample -"
set test "Tab should complete '$cmd'"
verbose "Sending $cmd\t..."
send "$cmd\t"
#exp_internal 1 # tell Expect to print diagnostics on its internal operations
expect {
-re "--timeUnit\\s*--timeout\\s*-t\\s*-u\r\n/@$cmd" { pass "'$cmd' COMPLETED OK"}
-re /@ { unresolved "$test at prompt" }
default { unresolved "$test" }
}
sync_after_int
set test "Tab should show options for '$cmd'"
set candidates "--timeUnit\\s*--timeout\\s*-t\\s*-u\r\n/@$cmd"
run_completion_test $cmd $test $candidates


# Try completion with two hyphens
set cmd "basicExample --"
set test "Tab should complete '$cmd'"
verbose "Sending ${cmd}\t..."
send "$cmd\t"
expect {
-re "--timeUnit\\s*--timeout\r\n/@${cmd}time" { pass "'$cmd' COMPLETED OK"}
-re /@ { unresolved "$test at prompt" }
default { unresolved "$test" }
}
sync_after_int
set test "Tab should show options for '$cmd' and add shared prefix 'time' after command"
set candidates "--timeUnit\\s*--timeout\r\n/@${cmd}time"
run_completion_test $cmd $test $candidates


#exp_internal 1 # tell Expect to print diagnostics on its internal operations
# Try completion with --timeUnit
set cmd "basicExample --timeUnit "
set test "Tab should show time unit enum values for '$cmd'"
set candidates "DAYS\\s*HOURS\\s*MICROSECONDS\\s*MILLISECONDS\\s*MINUTES\\s*NANOSECONDS\\s*SECONDS\r\n/@${cmd}"
run_completion_test $cmd $test $candidates


teardown
40 changes: 20 additions & 20 deletions src/test/dejagnu.tests/lib/completions/picocompletion-demo.exp
Expand Up @@ -7,7 +7,7 @@ proc teardown {} {
assert_env_unmodified {/OLDPWD=/d}
}

proc runtest {cmd test candidates} {
proc run_completion_test {cmd test candidates} {
verbose "Sending ${cmd}\t..."
send "${cmd}\t"

Expand All @@ -27,7 +27,7 @@ setup
set cmd "picocompletion-demo "
set test "Tab should should show sub1 and sub2 for '${cmd}'"
set candidates "sub1\\s*sub2\r\n/@${cmd}sub"
runtest $cmd $test $candidates
run_completion_test $cmd $test $candidates

# Try completion for sub1 without options
set cmd "picocompletion-demo sub1 "
Expand All @@ -49,88 +49,88 @@ sync_after_int
set cmd "picocompletion-demo sub1 -"
set test "Tab should show sub1 options for '${cmd}'"
set candidates "--candidates\\s*--num\\s*--str\r\n/@${cmd}-"
runtest $cmd $test $candidates
run_completion_test $cmd $test $candidates

# Try completion for sub1 --candidates
set cmd "picocompletion-demo sub1 --candidates "
set test "Tab should show enum values for '${cmd}'"
set candidates "aaa\\s*bbb\\s*ccc\r\n/@${cmd}"
runtest $cmd $test $candidates
run_completion_test $cmd $test $candidates

# Try completion for sub2
set cmd "picocompletion-demo sub2 "
set test "Tab should show positionals and subcommands for '${cmd}'"
set candidates "Aaa\\s*Bbb\\s*Ccc\\s*subsub1\\s*subsub2\\s*subsub3\r\n/@${cmd}"
runtest $cmd $test $candidates
run_completion_test $cmd $test $candidates

# Try completion for sub2 -
set cmd "picocompletion-demo sub2 -"
set test "Tab should show options for '${cmd}'"
set candidates "--directory\\s*--num2\\s*-d\r\n/@${cmd}"
runtest $cmd $test $candidates
run_completion_test $cmd $test $candidates

# Try completion for sub2 Aaa
set cmd "picocompletion-demo sub2 Aaa "
set test "Tab should show positionals and subcommands for '${cmd}'"
set candidates "Aaa\\s*Bbb\\s*Ccc\\s*subsub1\\s*subsub2\\s*subsub3\r\n/@${cmd}"
runtest $cmd $test $candidates
run_completion_test $cmd $test $candidates

# Try completion for sub2 Aaa s
set cmd "picocompletion-demo sub2 Aaa s"
set test "Tab should show subcommands for '${cmd}'"
set candidates "subsub1\\s*subsub2\\s*subsub3\r\n/@${cmd}ubsub"
runtest $cmd $test $candidates
run_completion_test $cmd $test $candidates

# Try completion for sub2 Aaa subsub1 -
set cmd "picocompletion-demo sub2 Aaa subsub1 -"
set test "Tab should show options for '${cmd}'"
set candidates "--host\\s*-h\r\n/@${cmd}"
runtest $cmd $test $candidates
run_completion_test $cmd $test $candidates

# Try completion for sub2 Aaa subsub2
set cmd "picocompletion-demo sub2 Aaa subsub2 "
set test "Tab should show enum values for positional0'${cmd}'"
set candidates "aaa\\s*bbb\\s*ccc\r\n/@${cmd}"
runtest $cmd $test $candidates
run_completion_test $cmd $test $candidates

# Try completion for sub2 Aaa subsub2 -
set cmd "picocompletion-demo sub2 Aaa subsub2 -"
set test "Tab should show options for '${cmd}'"
set candidates "--timeUnit\\s*--timeout\\s*-t\\s*-u\r\n/@${cmd}"
runtest $cmd $test $candidates
run_completion_test $cmd $test $candidates

#exp_internal 1 # tell Expect to print diagnostics on its internal operations
# # Try completion for sub2 Aaa subsub2 --timeUnit # TODO
#set cmd "picocompletion-demo sub2 Aaa subsub2 --timeUnit"
#set test "Tab should show options for '${cmd}'"
#set candidates "${cmd} \\%2"
#runtest $cmd $test $candidates
# Try completion for sub2 Aaa subsub2 --timeUnit
set cmd "picocompletion-demo sub2 Aaa subsub2 --timeUnit "
set test "Tab should show time unit enum values for '${cmd}'"
set candidates "DAYS\\s*HOURS\\s*MICROSECONDS\\s*MILLISECONDS\\s*MINUTES\\s*NANOSECONDS\\s*SECONDS\r\n/@${cmd}"
run_completion_test $cmd $test $candidates

# Try completion for sub2 Aaa subsub3
set cmd "picocompletion-demo sub2 Aaa subsub3 "
set test "Tab should show enum values for positional0'${cmd}'"
set candidates "aaa\\s*bbb\\s*ccc\r\n/@${cmd}"
runtest $cmd $test $candidates
run_completion_test $cmd $test $candidates

#exp_internal 1 # tell Expect to print diagnostics on its internal operations
# Try completion for sub2 Aaa subsub3 aaa
set cmd "picocompletion-demo sub2 Aaa subsub3 aaa "
set test "Tab should show directories for positional1'${cmd}'"
set candidates "README.adoc\\s*completion/\\s*config/\\s*lib/.*run\\s*runCompletion.*\r\n/@${cmd}"
runtest $cmd $test $candidates
run_completion_test $cmd $test $candidates

# Try completion for sub2 Aaa subsub3 aaa xxx
set cmd "picocompletion-demo sub2 Aaa subsub3 aaa xxx "
set test "Tab should show directories for positional2'${cmd}'"
set candidates "README.adoc\\s*completion/\\s*config/\\s*lib/.*run\\s*runCompletion.*\r\n/@${cmd}"
runtest $cmd $test $candidates
run_completion_test $cmd $test $candidates

#exp_internal 1 # tell Expect to print diagnostics on its internal operations
# Try completion for sub2 Aaa subsub3 aaa xxx yyy # TODO make more robust with fixtures in setup
set cmd "picocompletion-demo sub2 Aaa subsub3 aaa xxx yyy "
set test "Tab should show hosts for positional3'${cmd}'"
set candidates "::1.*localhost\r\n/@${cmd}"
runtest $cmd $test $candidates
run_completion_test $cmd $test $candidates


teardown

0 comments on commit a054f50

Please sign in to comment.