From 4e620255b11a19bae7214de141be144d7b58daaf Mon Sep 17 00:00:00 2001 From: mattmc3 Date: Fri, 22 Jan 2021 04:06:13 -0500 Subject: [PATCH] Support failed not (!) tests (#59) --- README.md | 2 +- functions/fishtape.fish | 12 +++++++++--- tests/files.fish | 2 ++ 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index d8b7838..0b88a8b 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ Tests are defined with the `@test` function. Each test begins with a description @test description [actual] operator expected -> Operators to combine expressions are not currently supported: `!`, `-a`, `-o`. +> Operators to combine expressions are not currently supported: `-a`, `-o`. Sometimes you need to test the exit status of running one or more commands and for that, you use command substitutions. Just make sure to suppress stdout to avoid cluttering your `test` expression. diff --git a/functions/fishtape.fish b/functions/fishtape.fish index 9408945..cf1f05a 100644 --- a/functions/fishtape.fish +++ b/functions/fishtape.fish @@ -65,13 +65,19 @@ function fishtape --description "Test scripts, functions, and plugins in Fish" string replace --filter --regex -- "\s+called on line (\d+) of file (.+)" '$2:$1' | read --local at + if test $argv[1] = "!" + set operator "! " + set negation "not " + set --erase argv[1] + end + if set --query argv[3] - set operator $argv[2] + set operator "$operator"$argv[2] set expected (string escape -- $argv[3]) set actual (string escape -- $argv[1]) else - set operator $argv[1] - set expected $expectations[(contains --index -- $operator $operators)] + set operator "$operator"$argv[1] + set expected "$negation"$expectations[(contains --index -- $argv[1] $operators)] set actual (string escape -- $argv[2]) end diff --git a/tests/files.fish b/tests/files.fish index f9cfd52..2930004 100644 --- a/tests/files.fish +++ b/tests/files.fish @@ -5,7 +5,9 @@ set temp (command mktemp -d) builtin cd $temp @test "a directory" -d $temp +@test "a non-existent directory" ! -d $temp.fake @test "a regular file" (command touch file) -f file +@test "a non-existent regular file" ! -f file.fake @test "nothing to see here" -z (read