diff options
Diffstat (limited to 'test')
21 files changed, 74 insertions, 47 deletions
diff --git a/test/Makefile.am b/test/Makefile.am index e05abf5f..d955be8a 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -3,7 +3,6 @@ AM_RUNTESTFLAGS = --outdir log EXTRA_DIST = completion \ config \ - fixture1 \ fixtures \ lib \ unit diff --git a/test/completion/perldoc.exp b/test/completion/perldoc.exp index e06e594f..d0d49b1a 100644 --- a/test/completion/perldoc.exp +++ b/test/completion/perldoc.exp @@ -1,3 +1 @@ -if {[assert_bash_type perl]} { - source "lib/completions/perldoc.exp" -}; # if +assert_source_completions perldoc diff --git a/test/fixtures/lftp/.lftp/bookmarks b/test/fixtures/lftp/.lftp/bookmarks new file mode 100644 index 00000000..31ec9303 --- /dev/null +++ b/test/fixtures/lftp/.lftp/bookmarks @@ -0,0 +1 @@ +lftptest ftp://ftp.funet.fi/ diff --git a/test/fixture1/bar b/test/fixtures/shared/default/bar index e69de29b..e69de29b 100644 --- a/test/fixture1/bar +++ b/test/fixtures/shared/default/bar diff --git a/test/fixture1/bar bar.d/foo b/test/fixtures/shared/default/bar bar.d/foo index e69de29b..e69de29b 100644 --- a/test/fixture1/bar bar.d/foo +++ b/test/fixtures/shared/default/bar bar.d/foo diff --git a/test/fixture1/foo b/test/fixtures/shared/default/foo index 257cc564..257cc564 100644 --- a/test/fixture1/foo +++ b/test/fixtures/shared/default/foo diff --git a/test/fixture1/foo.d/foo b/test/fixtures/shared/default/foo.d/foo index e69de29b..e69de29b 100644 --- a/test/fixture1/foo.d/foo +++ b/test/fixtures/shared/default/foo.d/foo diff --git a/test/generate b/test/generate index 5c184d56..aa282a2c 100755 --- a/test/generate +++ b/test/generate @@ -14,9 +14,7 @@ generate_test_completion() { #if [ ! -f "$path" ]; then # No, file doesn't exist; generate file cat <<EXPECT > "$path" -if {[assert_bash_type $1]} { - source "lib/completions/$1.exp" -}; # if +assert_source_completions $1 EXPECT #fi } # generate_test_completion() diff --git a/test/lib/completions/acroread.exp b/test/lib/completions/acroread.exp index d21d0f55..4f11f905 100644 --- a/test/lib/completions/acroread.exp +++ b/test/lib/completions/acroread.exp @@ -1,11 +1,11 @@ proc setup {} { save_env - assert_bash_exec "touch fixture1/t.pdf"; # Create temporary files + assert_bash_exec "touch fixtures/shared/default/t.pdf"; # Create temporary files }; # setup() proc teardown {} { - assert_bash_exec "rm fixture1/t.pdf"; # Remove temporary files + assert_bash_exec "rm fixtures/shared/default/t.pdf"; # Remove temporary files assert_env_unmodified }; # teardown() @@ -13,7 +13,7 @@ proc teardown {} { setup -assert_complete {"bar bar.d/" foo.d/ t.pdf} "acroread fixture1/" +assert_complete {"bar bar.d/" foo.d/ t.pdf} "acroread fixtures/shared/default/" sync_after_int diff --git a/test/lib/completions/cancel.exp b/test/lib/completions/cancel.exp index ac41c282..764497c3 100644 --- a/test/lib/completions/cancel.exp +++ b/test/lib/completions/cancel.exp @@ -12,7 +12,7 @@ setup # Adding a print job is successful? -if {[assert_exec {lp -H hold fixture1/foo} job]} { +if {[assert_exec {lp -H hold fixtures/shared/default/foo} job]} { # Yes, adding a print-job is successful; # Retrieve job-id, so we can cancel the job after the test set job_id [lindex [split $job] 3] diff --git a/test/lib/completions/cd.exp b/test/lib/completions/cd.exp index d4c06d9d..58233575 100644 --- a/test/lib/completions/cd.exp +++ b/test/lib/completions/cd.exp @@ -12,7 +12,7 @@ setup set test "Tab should complete" -assert_complete {"bar bar.d/" foo.d/} "cd fixture1/" $test +assert_complete {"bar bar.d/" foo.d/} "cd fixtures/shared/default/" $test sync_after_int @@ -20,13 +20,13 @@ sync_after_int set test "Tab should complete cd at cursor position" # Try completion -set cmd "cd fixture1/foo" +set cmd "cd fixtures/shared/default/foo" append cmd \002\002\002; # \002 = ^B = Move cursor left in bash emacs mode #append cmd \033\0133D; # Escape-[-D = Cursor left send "$cmd\t" expect { - -re "cd fixture1/foo\b\b\b\r\n(\.svn/ +|)bar bar.d/ +foo.d/ *(\.svn/ *|)\r\n/@cd fixture1/foo\b\b\b$" { pass "$test" } - -re "^cd fixture1/foo\b\b\bfoo.d/foo\b\b\b$" { fail "$test: Wrong cursor position" } + -re "cd fixtures/shared/default/foo\b\b\b\r\n(\.svn/ +|)bar bar.d/ +foo.d/ *(\.svn/ *|)\r\n/@cd fixtures/shared/default/foo\b\b\b$" { pass "$test" } + -re "^cd fixtures/shared/default/foo\b\b\bfoo.d/foo\b\b\b$" { fail "$test: Wrong cursor position" } -re /@ { unresolved "$test at prompt" } default { unresolved "$test" } }; # expect @@ -38,7 +38,7 @@ sync_after_int set test "Tab should complete CDPATH" # Set CDPATH assert_bash_exec "CDPATH=\$PWD"; -assert_complete "fixture1/foo.d/" "cd fixture1/fo" $test +assert_complete "fixtures/shared/default/foo.d/" "cd fixtures/shared/default/fo" $test sync_after_int # Reset CDPATH assert_bash_exec "unset CDPATH" diff --git a/test/lib/completions/chown.exp b/test/lib/completions/chown.exp index b1207eed..953b2b02 100644 --- a/test/lib/completions/chown.exp +++ b/test/lib/completions/chown.exp @@ -10,7 +10,10 @@ proc teardown {} { setup -assert_complete_any "chown " +set users [exec bash -c "compgen -A user"] +assert_complete $users "chown " + + sync_after_int diff --git a/test/lib/completions/find.exp b/test/lib/completions/find.exp index 0fb5c62c..8009fddc 100644 --- a/test/lib/completions/find.exp +++ b/test/lib/completions/find.exp @@ -29,7 +29,7 @@ sync_after_int set test "-wholename should complete files/dirs" -set dir fixture1 +set dir fixtures/shared/default set files [split [exec bash -c "cd $dir && ls -p"] "\n"] assert_complete_dir $files "find -wholename " $dir diff --git a/test/lib/completions/lftp.exp b/test/lib/completions/lftp.exp index 4bdde376..a49a1935 100644 --- a/test/lib/completions/lftp.exp +++ b/test/lib/completions/lftp.exp @@ -1,4 +1,5 @@ proc setup {} { + assert_bash_exec {HOME=$TESTDIR/fixtures/lftp} save_env }; # setup() @@ -11,7 +12,10 @@ proc teardown {} { setup -assert_complete_any "lftp " +set expected [get_hosts] +# `lftptest' is defined in ./fixtures/lftp/.lftp/bookmarks +lappend expected lftptest +assert_complete $expected "lftp " sync_after_int diff --git a/test/lib/completions/perl.exp b/test/lib/completions/perl.exp index 4b463383..2199c994 100644 --- a/test/lib/completions/perl.exp +++ b/test/lib/completions/perl.exp @@ -18,7 +18,7 @@ sync_after_int set test "Second argument should file complete" -set cmd "perl foo fixture1/f" +set cmd "perl foo fixtures/shared/default/f" send "$cmd\t" expect { -re "^$cmd\r\nfoo +foo.d/ *\r\n/@${cmd}oo$" { pass "$test" } @@ -31,7 +31,7 @@ sync_after_int set test "-I without space should complete directories" -set cmd "perl -Ifixture1/" +set cmd "perl -Ifixtures/shared/default/" send "$cmd\t" expect { -re "^$cmd\r\nbar bar.d/ +foo.d/ *\r\n/@$cmd$" { pass "$test" } @@ -44,7 +44,7 @@ sync_after_int set test "-I with space should complete directories" -set cmd "perl -I fixture1/" +set cmd "perl -I fixtures/shared/default/" send "$cmd\t" expect { -re "^$cmd\r\nbar bar.d/ +foo.d/ *\r\n/@$cmd$" { pass "$test" } @@ -57,7 +57,7 @@ sync_after_int set test "-x without space should complete directories" -set cmd "perl -xfixture1/b" +set cmd "perl -xfixtures/shared/default/b" send "$cmd\t" expect { -re "^${cmd}ar\\\\ bar.d/ *$" { pass "$test" } @@ -70,7 +70,7 @@ sync_after_int set test "-x with space should complete directories" -set cmd "perl -x fixture1/b" +set cmd "perl -x fixtures/shared/default/b" send "$cmd\t" expect { -re "^${cmd}ar\\\\ bar.d/ *$" { pass "$test" } diff --git a/test/lib/completions/sbcl-mt.exp b/test/lib/completions/sbcl-mt.exp index 1188f197..45e81f79 100644 --- a/test/lib/completions/sbcl-mt.exp +++ b/test/lib/completions/sbcl-mt.exp @@ -11,7 +11,7 @@ proc teardown {} { setup -assert_complete {bar "bar bar.d/" foo foo.d/} "sbcl-mt fixture1/" +assert_complete {bar "bar bar.d/" foo foo.d/} "sbcl-mt fixtures/shared/default/" sync_after_int diff --git a/test/lib/completions/sbcl.exp b/test/lib/completions/sbcl.exp index d5f2c8c2..b68b2dce 100644 --- a/test/lib/completions/sbcl.exp +++ b/test/lib/completions/sbcl.exp @@ -11,7 +11,7 @@ proc teardown {} { setup -assert_complete {bar "bar bar.d/" foo foo.d/} "sbcl fixture1/" +assert_complete {bar "bar bar.d/" foo foo.d/} "sbcl fixtures/shared/default/" sync_after_int diff --git a/test/lib/completions/screen.exp b/test/lib/completions/screen.exp index 4bd5ad0a..53e94b18 100644 --- a/test/lib/completions/screen.exp +++ b/test/lib/completions/screen.exp @@ -18,7 +18,7 @@ sync_after_int set test "-c should complete files/dirs" -set dir fixture1 +set dir fixtures/shared/default set prompt "/$dir/@" assert_bash_exec "cd $dir" "" $prompt set cmd "screen -c " diff --git a/test/lib/completions/ssh.exp b/test/lib/completions/ssh.exp index c3341294..2bec70c1 100644 --- a/test/lib/completions/ssh.exp +++ b/test/lib/completions/ssh.exp @@ -52,30 +52,17 @@ sync_after_int set test "First argument shouldn't complete with commands" -# NOTE: This test assumes the machine running this test has a command "bash" -# but no host named "bash" ... +# NOTE: This test assumes there's a command "bash" and no host named "bash" set cmd "ssh bas" -send "$cmd\t" -expect -ex "$cmd" -expect { - -timeout 1 - # In case multiple commands `bas*' - besides `bash' - are completed - -re "^\r\n.*bash.*\r\n/@$cmd$" { fail "$test" } - # In case the single command `bash' is completed - -re "h $" { fail "$test" } - # In case the hostname `bash_completion' is completed. - # See `scp' tests in `lib/completions/scp.exp' - -re "h_completion $" { pass "$test" } - -re ".+" { unresolved "$test" } - timeout { pass "$test" } -}; # expect +assert_complete [get_known_hosts "bas"] $cmd $test sync_after_int set test "First argument should complete partial hostname" -assert_complete_partial [get_hosts] ssh "" $test /@ 20 [list "ltrim_colon_completions"] +assert_complete_partial [get_hosts] ssh "" $test /@ 20 \ + [list "ltrim_colon_completions"] sync_after_int diff --git a/test/lib/completions/sudo.exp b/test/lib/completions/sudo.exp index 3dc98da3..1299a6da 100644 --- a/test/lib/completions/sudo.exp +++ b/test/lib/completions/sudo.exp @@ -11,7 +11,7 @@ proc teardown {} { setup -assert_complete "fixture1/foo.d/" "sudo cd fixture1/fo" +assert_complete "fixtures/shared/default/foo.d/" "sudo cd fixtures/shared/default/fo" sync_after_int diff --git a/test/lib/library.exp b/test/lib/library.exp index 45949006..3de310bf 100644 --- a/test/lib/library.exp +++ b/test/lib/library.exp @@ -451,6 +451,23 @@ proc assert_no_complete {{cmd} {test ""}} { }; # assert_no_complete() +# Source/run file with additional tests if completion for the specified command +# is installed in bash. +# @param string $command Command to check completion availability for. +# @param string $file (optional) File to source/run. Default is +# "lib/completions/$cmd.exp". +proc assert_source_completions {command {file ""}} { + if {[is_bash_completion_installed_for $command]} { + if {[string length $file] == 0} { + set file "lib/completions/$command.exp" + } + source $file + } else { + untested $command + } +}; # assert_source_completions() + + # Sort list. # `exec sort' is used instead of `lsort' to achieve exactly the # same sort order as in bash. @@ -462,10 +479,12 @@ proc bash_sort {items} { # Get 'known' hostnames. Looks also in ssh's 'known_hosts' files. +# @param string cword (optional) Word, hosts should start with. # @return list Hostnames # @see get_hosts() -proc get_known_hosts {} { - assert_bash_exec {_known_hosts_real ''; echo_array COMPREPLY} {} /@ result +proc get_known_hosts {{cword ''}} { + assert_bash_exec "_known_hosts_real '$cword'; echo_array COMPREPLY" \ + {} /@ result return $result }; # get_known_hosts() @@ -532,6 +551,24 @@ proc init_tcl_bash_globals {} { }; # init_tcl_bash_globals() +# Check whether completion is installed for the specified command by executing +# `complete -p ...' in bash. +# @param string $command Command to check completion availability for. +# @return boolean True (1) if completion is installed, False (0) if not. +proc is_bash_completion_installed_for {command} { + set test "$command should have completion installed in bash" + set cmd "complete -p $command &> /dev/null && echo -n 0 || echo -n 1" + send "$cmd\r" + expect "$cmd\r\n" + expect { + -ex 0 { set result true } + -ex 1 { set result false } + } + expect "/@" + return $result +}; # is_bash_completion_installed_for() + + # Detect if test suite is running under Cygwin/Windows proc is_cygwin {} { expr {[string first [string tolower [exec uname -s]] cygwin] >= 0} |