2014-09-08 02:11:34 +00:00
|
|
|
#!/usr/local/bin/fish
|
|
|
|
#
|
|
|
|
# Interactive tests using `expect`
|
|
|
|
|
2015-12-23 23:24:45 +00:00
|
|
|
# Change to directory containing this script
|
|
|
|
cd (dirname (status -f))
|
|
|
|
|
|
|
|
# Test files specified on commandline, or all *.expect files
|
|
|
|
if set -q argv[1]
|
|
|
|
set files_to_test $argv.expect
|
|
|
|
else
|
|
|
|
set files_to_test *.expect
|
|
|
|
end
|
|
|
|
|
|
|
|
source test_util.fish (status -f) $argv; or exit
|
2014-09-23 23:29:36 +00:00
|
|
|
|
|
|
|
say -o cyan "Testing interactive functionality"
|
|
|
|
if not type -q expect
|
|
|
|
say red "Tests disabled: `expect` not found"
|
|
|
|
exit 0
|
2014-09-08 02:11:34 +00:00
|
|
|
end
|
|
|
|
|
2014-09-23 23:29:36 +00:00
|
|
|
function test_file
|
2014-09-08 02:11:34 +00:00
|
|
|
rm -Rf tmp.interactive.config; or die "Couldn't remove tmp.interactive.config"
|
|
|
|
mkdir -p tmp.interactive.config/fish; or die "Couldn't create tmp.interactive.config/fish"
|
2014-10-28 02:42:19 +00:00
|
|
|
cat $XDG_CONFIG_HOME/fish/config.fish interactive.config > tmp.interactive.config/fish/config.fish
|
|
|
|
or die "Couldn't create tmp.interactive.config/fish/config.fish"
|
2014-09-08 02:11:34 +00:00
|
|
|
|
2014-09-23 23:29:36 +00:00
|
|
|
set -l file $argv[1]
|
|
|
|
|
|
|
|
echo -n "Testing file $file ... "
|
|
|
|
|
2014-09-08 02:11:34 +00:00
|
|
|
begin
|
|
|
|
set -lx XDG_CONFIG_HOME $PWD/tmp.interactive.config
|
|
|
|
set -lx TERM dumb
|
2014-09-23 23:29:36 +00:00
|
|
|
expect -n -c 'source interactive.expect.rc' -f $file >$file.tmp.out ^$file.tmp.err
|
2014-09-08 02:11:34 +00:00
|
|
|
end
|
|
|
|
set -l tmp_status $status
|
2014-09-23 23:29:36 +00:00
|
|
|
set -l res ok
|
|
|
|
mv -f interactive.tmp.log $file.tmp.log
|
2014-09-08 02:11:34 +00:00
|
|
|
|
2014-09-23 23:29:36 +00:00
|
|
|
diff $file.tmp.out $file.out >/dev/null
|
|
|
|
set -l out_status $status
|
|
|
|
diff $file.tmp.err $file.err >/dev/null
|
|
|
|
set -l err_status $status
|
|
|
|
set -l exp_status (cat $file.status)[1]
|
2014-09-08 02:11:34 +00:00
|
|
|
|
2014-09-23 23:29:36 +00:00
|
|
|
if test $out_status -eq 0 -a $err_status -eq 0 -a $exp_status -eq $tmp_status
|
|
|
|
say green "ok"
|
2014-09-18 22:45:07 +00:00
|
|
|
# clean up tmp files
|
2014-09-23 23:29:36 +00:00
|
|
|
rm -f $file.tmp.{err,out,log}
|
|
|
|
return 0
|
2014-09-08 02:11:34 +00:00
|
|
|
else
|
2014-09-23 23:29:36 +00:00
|
|
|
say red "fail"
|
|
|
|
if test $out_status -ne 0
|
|
|
|
say yellow "Output differs for file $file. Diff follows:"
|
|
|
|
colordiff -u $file.tmp.out $file.out
|
|
|
|
end
|
|
|
|
if test $err_status -ne 0
|
|
|
|
say yellow "Error output differs for file $file. Diff follows:"
|
|
|
|
colordiff -u $file.tmp.err $file.err
|
|
|
|
end
|
|
|
|
if test $exp_status -ne $tmp_status
|
|
|
|
say yellow "Exit status differs for file $file."
|
|
|
|
echo "Expected $exp_status, got $tmp_status."
|
|
|
|
end
|
|
|
|
if set -q SHOW_INTERACTIVE_LOG
|
2014-09-19 21:50:34 +00:00
|
|
|
# dump the interactive log
|
|
|
|
# primarily for use in travis where we can't check it manually
|
2014-09-23 23:29:36 +00:00
|
|
|
say yellow "Log for file $file:"
|
|
|
|
cat $file.tmp.log
|
2014-09-19 21:50:34 +00:00
|
|
|
end
|
2014-09-23 23:29:36 +00:00
|
|
|
return 1
|
2014-09-08 02:11:34 +00:00
|
|
|
end
|
|
|
|
end
|
2014-09-23 23:29:36 +00:00
|
|
|
|
2014-10-02 19:31:46 +00:00
|
|
|
set -l failed
|
2015-12-23 23:24:45 +00:00
|
|
|
for i in $files_to_test
|
2014-09-23 23:29:36 +00:00
|
|
|
if not test_file $i
|
2014-10-02 19:31:46 +00:00
|
|
|
set failed $failed $i
|
2014-09-23 23:29:36 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-10-02 19:31:46 +00:00
|
|
|
set failed (count $failed)
|
2014-09-23 23:29:36 +00:00
|
|
|
if test $failed -eq 0
|
|
|
|
say green "All tests completed successfully"
|
|
|
|
exit 0
|
|
|
|
else
|
2014-09-24 05:50:28 +00:00
|
|
|
set plural (test $failed -eq 1; or echo s)
|
|
|
|
say red "$failed test$plural failed"
|
2014-09-23 23:29:36 +00:00
|
|
|
exit 1
|
|
|
|
end
|