From f8af262af7b86b41a1b3c4d98a8dcb533e261552 Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Fri, 7 Feb 2020 22:10:55 +0100 Subject: [PATCH] Port some smaller tests to littlecheck --- .../builtinbuiltin.fish} | 6 ++++ tests/{functions.in => checks/functions.fish} | 10 +++---- tests/{psub.in => checks/psub.fish} | 9 +++++- tests/{random.in => checks/random.fish} | 17 +++++++++++ tests/{status.in => checks/status.fish} | 23 +++++++++++--- tests/checks/vars_as_commands.fish | 30 +++++++++++++++++++ tests/checks/zero_based_array.fish | 18 +++++++++++ tests/functions.err | 0 tests/functions.out | 1 - tests/psub.err | 0 tests/psub.out | 7 ----- tests/random.err | 16 ---------- tests/random.out | 0 tests/status.err | 12 -------- tests/status.out | 16 ---------- tests/test_builtinbuiltin.err | 2 -- tests/test_builtinbuiltin.out | 3 -- tests/vars_as_commands.err | 6 ---- tests/vars_as_commands.in | 19 ------------ tests/vars_as_commands.out | 4 --- tests/zero_based_array.err | 9 ------ tests/zero_based_array.in | 8 ----- tests/zero_based_array.out | 1 - 23 files changed, 102 insertions(+), 115 deletions(-) rename tests/{test_builtinbuiltin.in => checks/builtinbuiltin.fish} (54%) rename tests/{functions.in => checks/functions.fish} (94%) rename tests/{psub.in => checks/psub.fish} (88%) rename tests/{random.in => checks/random.fish} (72%) rename tests/{status.in => checks/status.fish} (62%) create mode 100644 tests/checks/vars_as_commands.fish create mode 100644 tests/checks/zero_based_array.fish delete mode 100644 tests/functions.err delete mode 100644 tests/functions.out delete mode 100644 tests/psub.err delete mode 100644 tests/psub.out delete mode 100644 tests/random.err delete mode 100644 tests/random.out delete mode 100644 tests/status.err delete mode 100644 tests/status.out delete mode 100644 tests/test_builtinbuiltin.err delete mode 100644 tests/test_builtinbuiltin.out delete mode 100644 tests/vars_as_commands.err delete mode 100644 tests/vars_as_commands.in delete mode 100644 tests/vars_as_commands.out delete mode 100644 tests/zero_based_array.err delete mode 100644 tests/zero_based_array.in delete mode 100644 tests/zero_based_array.out diff --git a/tests/test_builtinbuiltin.in b/tests/checks/builtinbuiltin.fish similarity index 54% rename from tests/test_builtinbuiltin.in rename to tests/checks/builtinbuiltin.fish index 4293a96e1..c674e1187 100644 --- a/tests/test_builtinbuiltin.in +++ b/tests/checks/builtinbuiltin.fish @@ -1,7 +1,13 @@ +#RUN: %fish %s # Tests for the "builtin" builtin/keyword. builtin -q string; and echo String exists +#CHECK: String exists builtin -q; and echo None exists builtin -q string echo banana; and echo Some of these exist +#CHECK: Some of these exist builtin -nq string +#CHECKERR: builtin: Invalid combination of options, +#CHECKERR: --query and --names are mutually exclusive echo $status +#CHECK: 2 exit 0 diff --git a/tests/functions.in b/tests/checks/functions.fish similarity index 94% rename from tests/functions.in rename to tests/checks/functions.fish index 0cd4def92..1cf336f1b 100644 --- a/tests/functions.in +++ b/tests/checks/functions.fish @@ -1,5 +1,4 @@ -# vim: set filetype=fish: -# +#RUN: %fish %s # Test the `functions` builtin function f1 @@ -15,10 +14,8 @@ end # ========== # Verify that `functions --details` works as expected when given the name of a # known function. -set x (functions --details f1) -if test "$x" != "stdin" - echo "Unexpected output for 'functions --details f1': $x" >&2 -end +functions --details f1 +#CHECK: {{.*}}checks/functions.fish # ========== # Verify that `functions --details` works as expected when given the name of an @@ -82,3 +79,4 @@ or echo "Failed to find description 2" >&2 # so this is the best we can do. functions --erase ls type -t ls +#CHECK: file diff --git a/tests/psub.in b/tests/checks/psub.fish similarity index 88% rename from tests/psub.in rename to tests/checks/psub.fish index 5a615e540..bf3676c7b 100644 --- a/tests/psub.in +++ b/tests/checks/psub.fish @@ -1,4 +1,4 @@ -# Test psub behavior +#RUN: %fish %s set -l filename (echo foo | psub --testing) test -f $filename or echo 'psub is not a regular file' >&2 @@ -21,6 +21,9 @@ rm $filename cat (echo foo | psub) cat (echo bar | psub --fifo) cat (echo baz | psub) +#CHECK: foo +#CHECK: bar +#CHECK: baz set -l filename (echo foo | psub) if test -e $filename @@ -28,6 +31,7 @@ if test -e $filename else echo 'psub file was deleted' end +#CHECK: psub file was deleted # The --file flag is the default behavior. if count (echo foo | psub -s .cc | string match -r '\.cc$') >/dev/null @@ -35,6 +39,7 @@ if count (echo foo | psub -s .cc | string match -r '\.cc$') >/dev/null else echo 'psub filename does not end with .cc' end +#CHECK: psub filename ends with .cc # Make sure we get the same result if we explicitly ask for a temp file. if count (echo foo | psub -f -s .cc | string match -r '\.cc$') >/dev/null @@ -42,6 +47,7 @@ if count (echo foo | psub -f -s .cc | string match -r '\.cc$') >/dev/null else echo 'psub filename does not end with .cc' end +#CHECK: psub filename ends with .cc set -l filename (echo foo | psub -s .fish) if test -e (dirname $filename) @@ -49,6 +55,7 @@ if test -e (dirname $filename) else echo 'psub directory was deleted' end +#CHECK: psub directory was deleted set -l diffs (comm -3 (__fish_print_help psub | psub) (psub -hs banana | psub)) test -z "$diffs" diff --git a/tests/random.in b/tests/checks/random.fish similarity index 72% rename from tests/random.in rename to tests/checks/random.fish index d8e31df19..6b4e1b718 100644 --- a/tests/random.in +++ b/tests/checks/random.fish @@ -1,3 +1,4 @@ +#RUN: %fish %s set -l max 9223372036854775807 set -l close_max 9223372036854775806 set -l min -9223372036854775807 @@ -6,21 +7,37 @@ set -l diff_max 18446744073709551614 # check failure cases random a +#CHECKERR: random: Argument 'a' is not a valid integer random $diff_max +#CHECKERR: random: Argument '18446744073709551614' is not a valid integer random -- 1 2 3 4 +#CHECKERR: random: Too many arguments random -- 10 -10 +#CHECKERR: random: END must be greater than START random -- 10 $diff_max +#CHECKERR: random: Argument '18446744073709551614' is not a valid integer random -- 1 1d random -- 1 1c 10 +#CHECKERR: random: Argument '1d' is not a valid integer +#CHECKERR: random: Argument '1c' is not a valid integer random -- 10 10 +#CHECKERR: random: END must be greater than START random -- 1 - 10 +#CHECKERR: random: Argument '-' is not a valid integer random -- 1 -1 10 +#CHECKERR: random: Argument '-1' is not a valid integer random -- 1 $min 10 +#CHECKERR: random: Argument '-9223372036854775807' is not a valid integer random -- 1 0 10 +#CHECKERR: random: STEP must be a positive integer random -- 1 11 10 +#CHECKERR: random: range contains only one possible value random -- 0 $diff_max $max +#CHECKERR: random: range contains only one possible value random choice +#CHECKERR: random: nothing to choose from random choic a b c +#CHECKERR: random: Too many arguments function check_boundaries if not test $argv[1] -ge $argv[2] -a $argv[1] -le $argv[3] diff --git a/tests/status.in b/tests/checks/status.fish similarity index 62% rename from tests/status.in rename to tests/checks/status.fish index ad68a9231..96f4d9a6b 100644 --- a/tests/status.in +++ b/tests/checks/status.fish @@ -1,5 +1,4 @@ -# vim: set filetype=fish: - +#RUN: %fish %s status -b and echo '"status -b" unexpectedly returned true at top level' @@ -22,36 +21,52 @@ and echo '"status is-interactive" unexpectedly returned true for a non-interacti # We should get an error message about an invalid combination of flags. status --is-interactive --is-login +#CHECKERR: status: Invalid combination of options, +#CHECKERR: you cannot do both 'is-interactive' and 'is-login' in the same invocation # We should get an error message about an unexpected arg for `status # is-block`. status -b is-interactive +#CHECKERR: status: Invalid combination of options, +#CHECKERR: you cannot do both 'is-block' and 'is-interactive' in the same invocation # Try to set the job control to an invalid mode. status job-control full1 +#CHECKERR: status: Invalid job control mode 'full1' status --job-control=1none +#CHECKERR: status: Invalid job control mode '1none' # Now set it to a valid mode. status job-control none # Check status -u outside functions status current-function +#CHECK: Not a function function test_function status current-function end test_function +#CHECK: test_function eval test_function +#CHECK: test_function -logmsg Future Feature Flags +# Future Feature Flags status features +#CHECK: stderr-nocaret off 3.0 ^ no longer redirects stderr +#CHECK: qmark-noglob off 3.0 ? no longer globs +#CHECK: regex-easyesc off 3.1 string replace -r needs fewer \'s status test-feature stderr-nocaret ; echo $status +#CHECK: 1 status test-feature not-a-feature ; echo $status +#CHECK: 2 -logmsg 'Ensure $status isn\'t reset before a function is executed' +# Ensure $status isn't reset before a function is executed function echo_last echo $status end false; echo_last; echo $status #1 +#CHECK: 1 +#CHECK: 0 diff --git a/tests/checks/vars_as_commands.fish b/tests/checks/vars_as_commands.fish new file mode 100644 index 000000000..55c8bb178 --- /dev/null +++ b/tests/checks/vars_as_commands.fish @@ -0,0 +1,30 @@ +#RUN: %fish %s +# Test that using variables as command names work correctly. + +$EMPTY_VARIABLE +#CHECKERR: {{.*}}checks/vars_as_commands.fish (line {{\d+}}): The expanded command was empty. +#CHECKERR: $EMPTY_VARIABLE +#CHECKERR: ^ +"$EMPTY_VARIABLE" +#CHECKERR: {{.*}}checks/vars_as_commands.fish (line {{\d+}}): The expanded command was empty. +#CHECKERR: "$EMPTY_VARIABLE" +#CHECKERR: ^ + +set CMD1 echo basic command as variable +$CMD1 +#CHECK: basic command as variable + +set CMD2 echo '(' not expanded again +$CMD2 +#CHECK: ( not expanded again + +# Test using variables with the builtin decorator +builtin $CMD1 +#CHECK: basic command as variable + +# Test implicit cd +set CMD3 /usr/bin +$CMD3 && echo $PWD +#CHECK: /usr/bin + +exit 0 diff --git a/tests/checks/zero_based_array.fish b/tests/checks/zero_based_array.fish new file mode 100644 index 000000000..bb41f999b --- /dev/null +++ b/tests/checks/zero_based_array.fish @@ -0,0 +1,18 @@ +#RUN: %fish %s +echo $foo[0] +echo $foo[ 0 ] +echo $foo[ 00 ] +#CHECKERR: {{.*}}checks/zero_based_array.fish (line {{\d+}}): array indices start at 1, not 0. +#CHECKERR: echo $foo[0] +#CHECKERR: ^ +#CHECKERR: {{.*}}checks/zero_based_array.fish (line {{\d+}}): array indices start at 1, not 0. +#CHECKERR: echo $foo[ 0 ] +#CHECKERR: ^ +#CHECKERR: {{.*}}checks/zero_based_array.fish (line {{\d+}}): array indices start at 1, not 0. +#CHECKERR: echo $foo[ 00 ] +#CHECKERR: ^ + +# and make sure these didn't break +set -l foo one two three +echo $foo[001] +#CHECK: one diff --git a/tests/functions.err b/tests/functions.err deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/functions.out b/tests/functions.out deleted file mode 100644 index f73f3093f..000000000 --- a/tests/functions.out +++ /dev/null @@ -1 +0,0 @@ -file diff --git a/tests/psub.err b/tests/psub.err deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/psub.out b/tests/psub.out deleted file mode 100644 index 6f9d6710c..000000000 --- a/tests/psub.out +++ /dev/null @@ -1,7 +0,0 @@ -foo -bar -baz -psub file was deleted -psub filename ends with .cc -psub filename ends with .cc -psub directory was deleted diff --git a/tests/random.err b/tests/random.err deleted file mode 100644 index 0a9572bdf..000000000 --- a/tests/random.err +++ /dev/null @@ -1,16 +0,0 @@ -random: Argument 'a' is not a valid integer -random: Argument '18446744073709551614' is not a valid integer -random: Too many arguments -random: END must be greater than START -random: Argument '18446744073709551614' is not a valid integer -random: Argument '1d' is not a valid integer -random: Argument '1c' is not a valid integer -random: END must be greater than START -random: Argument '-' is not a valid integer -random: Argument '-1' is not a valid integer -random: Argument '-9223372036854775807' is not a valid integer -random: STEP must be a positive integer -random: range contains only one possible value -random: range contains only one possible value -random: nothing to choose from -random: Too many arguments diff --git a/tests/random.out b/tests/random.out deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/status.err b/tests/status.err deleted file mode 100644 index ad52d81c6..000000000 --- a/tests/status.err +++ /dev/null @@ -1,12 +0,0 @@ -status: Invalid combination of options, -you cannot do both 'is-interactive' and 'is-login' in the same invocation -status: Invalid combination of options, -you cannot do both 'is-block' and 'is-interactive' in the same invocation -status: Invalid job control mode 'full1' -status: Invalid job control mode '1none' - -#################### -# Future Feature Flags - -#################### -# Ensure $status isn't reset before a function is executed diff --git a/tests/status.out b/tests/status.out deleted file mode 100644 index 4a94d8cd3..000000000 --- a/tests/status.out +++ /dev/null @@ -1,16 +0,0 @@ -Not a function -test_function -test_function - -#################### -# Future Feature Flags -stderr-nocaret off 3.0 ^ no longer redirects stderr -qmark-noglob off 3.0 ? no longer globs -regex-easyesc off 3.1 string replace -r needs fewer \'s -1 -2 - -#################### -# Ensure $status isn't reset before a function is executed -1 -0 diff --git a/tests/test_builtinbuiltin.err b/tests/test_builtinbuiltin.err deleted file mode 100644 index ff818897a..000000000 --- a/tests/test_builtinbuiltin.err +++ /dev/null @@ -1,2 +0,0 @@ -builtin: Invalid combination of options, ---query and --names are mutually exclusive diff --git a/tests/test_builtinbuiltin.out b/tests/test_builtinbuiltin.out deleted file mode 100644 index 11c0882b4..000000000 --- a/tests/test_builtinbuiltin.out +++ /dev/null @@ -1,3 +0,0 @@ -String exists -Some of these exist -2 diff --git a/tests/vars_as_commands.err b/tests/vars_as_commands.err deleted file mode 100644 index c1eefbf52..000000000 --- a/tests/vars_as_commands.err +++ /dev/null @@ -1,6 +0,0 @@ -fish: The expanded command was empty. -$EMPTY_VARIABLE -^ -fish: The expanded command was empty. -"$EMPTY_VARIABLE" -^ diff --git a/tests/vars_as_commands.in b/tests/vars_as_commands.in deleted file mode 100644 index 3b73c9f00..000000000 --- a/tests/vars_as_commands.in +++ /dev/null @@ -1,19 +0,0 @@ -# Test that using variables as command names work correctly. - -$EMPTY_VARIABLE -"$EMPTY_VARIABLE" - -set CMD1 echo basic command as variable -$CMD1 - -set CMD2 echo '(' not expanded again -$CMD2 - -# Test using variables with the builtin decorator -builtin $CMD1 - -# Test implicit cd -set CMD3 /usr/bin -$CMD3 && echo $PWD - -exit 0 diff --git a/tests/vars_as_commands.out b/tests/vars_as_commands.out deleted file mode 100644 index 64e4976b7..000000000 --- a/tests/vars_as_commands.out +++ /dev/null @@ -1,4 +0,0 @@ -basic command as variable -( not expanded again -basic command as variable -/usr/bin diff --git a/tests/zero_based_array.err b/tests/zero_based_array.err deleted file mode 100644 index 08ed84e77..000000000 --- a/tests/zero_based_array.err +++ /dev/null @@ -1,9 +0,0 @@ -fish: array indices start at 1, not 0. -echo $foo[0] - ^ -fish: array indices start at 1, not 0. -echo $foo[ 0 ] - ^ -fish: array indices start at 1, not 0. -echo $foo[ 00 ] - ^ diff --git a/tests/zero_based_array.in b/tests/zero_based_array.in deleted file mode 100644 index 4dc28ec1f..000000000 --- a/tests/zero_based_array.in +++ /dev/null @@ -1,8 +0,0 @@ -echo $foo[0] -echo $foo[ 0 ] -echo $foo[ 00 ] - -# and make sure these didn't break -set -l foo one two three -echo $foo[001] - diff --git a/tests/zero_based_array.out b/tests/zero_based_array.out deleted file mode 100644 index 5626abf0f..000000000 --- a/tests/zero_based_array.out +++ /dev/null @@ -1 +0,0 @@ -one