Skip to content

Commit

Permalink
2.1.0
Browse files Browse the repository at this point in the history
- Add new $current_dirname (and rename $filename to $current_file) #39
- Add ability to get the abutesol path from a given file, but without
  following symlinks (similar behavior as fish >=2.3 `realpath` and
  can eventually use that instead)
- Improve `@test` so it can be used to check if two array are equal
  or not (the downside is that test descriptions are now required)
- Reset $status to 0 after running `setup` function hook
  • Loading branch information
jorgebucaran committed Feb 12, 2019
1 parent d5da1c4 commit b195bc1
Showing 1 changed file with 83 additions and 85 deletions.
168 changes: 83 additions & 85 deletions fishtape.fish
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
set -g fishtape_version 2.0.0
set -g fishtape_version 2.1.0

complete -xc fishtape -n __fish_use_subcommand -a --help -d "Show usage help"
complete -xc fishtape -n __fish_use_subcommand -a --version -d "$fishtape_version"
Expand All @@ -10,81 +10,120 @@ function fishtape -d "TAP-based test runner"
end
end
switch "$argv[1]"
case {,-}-h{elp,} ""
echo "usage: fishtape <files...> Run tests in <files>"
echo " fishtape --help Show this help"
echo " fishtape --version Show the current version"
echo "examples:"
echo " fishtape <test.fish"
echo " fishtape test/*.fish"
echo " fish -c \"fishtape test/*.fish\" | tap-nyan"
case {,-}-v{ersion,}
echo "fishtape version $fishtape_version"
case @mesg
echo -s {$argv[2],mesg,$argv[3]}\t
case @test
if set -q argv[4]
set -l rest (printf "%s\n" $argv[-1..3] | command awk '
set -l rest (printf "%s\n" $argv[4..-1] | command awk '
BEGIN { i = 0 }
{
args[i++] = $0
if (NR == 1 && $0 == "!") {
not = "!"
} else if (NR <= 2 && !operator && /^-(n|z|b|c|d|e|f|g|G|k|L|O|p|r|s|S|t|u|w|x)$/) {
operator = $0
} else if (NR > 1 && !i && !(not && NR == 2) && /^(!?=|-(eq|ne|gt|ge|lt|le))$/) {
a[i] = operator ? (a[i] ? a[i] " " : "") operator : a[i]
operator = $0
i++
} else {
a[i] = (a[i] ? a[i]" " : "") $0
}
}
END {
right = args[0]
left = is_binary(operator = args[1]) ? args[2] : ""
is = args[i = (left || (left == 0) ? 3 : 2)] == "!" ? "!" : ""
desc = args[is ? ++i : i]
print\
desc "\n"\
left "\n" \
(is ? is" " : "") operator "\n"\
right "\n"\
(is ? is"\n" : "") (""left ? left"\n" : "") operator "\n" right
}
function is_binary(s) {
return s ~ /^(!?=|-(eq|ne|gt|ge|lt|le))$/
print not operator "\n" a[0] "\n" (i ? a[i]\
: operator == "-n" ? "a non-zero length string"\
: operator == "-z" ? "a zero length string"\
: operator == "-b" ? "a block device"\
: operator == "-c" ? "a character device"\
: operator == "-d" ? "a directory"\
: operator == "-e" ? "an existing file"\
: operator == "-f" ? "a regular file"\
: operator == "-g" ? "a file with the set-group-ID bit set"\
: operator == "-G" ? "a file with same group ID as the current user"\
: operator == "-L" ? "a symbolic link"\
: operator == "-O" ? "a file owned by the current user"\
: operator == "-p" ? "a named pipe"\
: operator == "-r" ? "a file marked as readable"\
: operator == "-s" ? "a file of size greater than zero"\
: operator == "-S" ? "a socket"\
: operator == "-t" ? "a terminal tty file descriptor"\
: operator == "-u" ? "a file with the set-user-ID bit set"\
: operator == "-w" ? "a file marked as writable"\
: operator == "-x" ? "a file marked as executable"\
: "a valid operator") "\n"\
(not ? not "\n" : "") (i ? a[0] "\n" operator "\n" a[1] : operator "\n" a[0])
}
')
if test $rest[5..-1]
echo -s {$argv[2],1,$rest[1]}\t
if test $rest[4..-1] 2>/dev/null
echo -s {$argv[2],1,$argv[3]}\t
else
echo -s {$argv[2],0,$rest[1],$rest[2],$rest[3],$rest[4]}\t
echo -s {$argv[2],0,$argv[3],$rest[1],$rest[2],$rest[3]}\t
end
functions -q teardown; and teardown
else
echo -s {$argv[2],todo,$argv[3]\ \#\ TODO}\t
end
case {,-}-v{ersion,}
echo "fishtape version $fishtape_version"
case {,-}-h{elp,} ""
echo "usage: fishtape <files...> Run tests in <files>"
echo " fishtape --help Show this help"
echo " fishtape --version Show the current version"
echo "examples:"
echo " fishtape <test.fish"
echo " fishtape test/*.fish"
echo " fish -c \"fishtape test/*.fish\" | tap-nyan"
case \*
for f in $argv
if test $f != - -a ! -f $f
echo "fishtape: can't open file \"$f\" -- is this a valid file?"
set -l files (printf "%s\n" $argv | command awk -v PWD="$PWD" '
/^-$/ {
print; next
}
{
n = split((/^\// ? "" : PWD "/") $0, tree, "/")
for (i = k = 0; ++i <= n; ) {
node = tree[i]
k += (_k = node == ".." ? k ? -1 : 0 : node && node != "." ? 1 : 0)
path[k] = _k > 0 ? node : path[k]
}
out = ""
for (i = 1; i <= k || !out; i++) {
out = out "/" path[i]
}
print out
}
')
for file in $files
if test $file != - -a ! -f $file
echo "fishtape: can't open file \"$file\" -- is this a valid file?"
return 1
end
end
command awk '
FNR == 1 {
print (NR > 1 ? end()";" : "") "fish -c \'"
print (NR > 1 ? end_batch()";" : "") begin_batch()
id++
}
!/^[[:space:]]*#/ && $0 {
gsub(/\'/, "\\\\\'")
gsub(/\$filename/, f[split(FILENAME, f, "/")])
gsub(/\$current_dirname/, d[split(FILENAME, d, /\/[^\/]*$/) - 1])
gsub(/\$current_filename/, f[split(FILENAME, f, "/")])
sub(/^[[:space:]]*@mesg/, "fishtape @mesg " id)
sub(/^[[:space:]]*@test/, "functions -q setup; and setup; fishtape @test " id)
sub(/^[[:space:]]*@test/, "functions -q setup; and setup; true; fishtape @test " id)
print
}
END {
print end()wait()
print end_batch()";while for j in $jobs;contains -- $j "jobs()";and break;end;end"
}
function end() {
return "echo " id "\'&;set -l js $js " jobs(" -l")
function begin_batch() {
return "fish -c \'"
}
function wait() {
return ";while for j in $js;contains -- $j "jobs()";and break;end;end"
function end_batch() {
return "echo " id "\'&;set -l jobs $jobs " jobs(" -l")
}
function jobs(opt) {
return "(jobs"opt" | command awk \'/^[0-9]+\\\t/ { print $1 }\')"
}
' $argv | fish -c source | command awk -F\t '
' $files | fish -c source | command awk -F\t '
BEGIN {
print "TAP version 13"
}
Expand All @@ -108,52 +147,11 @@ function fishtape -d "TAP-based test runner"
batch[id] = batch[id $2] = "ok " $3
} else {
batch[id] = "not ok " $3
is = (split($5, ops, " ") && ops[1] == "!" && ($5 = ops[2])) ? "not " : ""
$4 = $4 ? $4\
: $5 == "-n" \
? is "a non-zero length string" \
: $5 == "-z" \
? is "a zero length string" \
: $5 == "-b" \
? is "a block device" \
: $5 == "-c" \
? is "a character device" \
: $5 == "-d" \
? is "a directory" \
: $5 == "-e" \
? is "an existing file" \
: $5 == "-f" \
? is "a regular file" \
: $5 == "-g" \
? is "a file with the set-group-ID bit set" \
: $5 == "-G" \
? is "a file with same group ID as the current user" \
: $5 == "-L" \
? is "a symbolic link" \
: $5 == "-O" \
? is "a file owned by the current user" \
: $5 == "-p" \
? is "a named pipe" \
: $5 == "-r" \
? is "a file marked as readable" \
: $5 == "-s" \
? is "a file of size greater than zero" \
: $5 == "-S" \
? is "a socket" \
: $5 == "-t" \
? is "a terminal tty file descriptor" \
: $5 == "-u" \
? is "a file with the set-user-ID bit set" \
: $5 == "-w" \
? is "a file marked as writable" \
: $5 == "-x" \
? is "a file marked as executable" \
: $4
batch[id "error"] =\
" ---\n"\
" operator: "(is ? "!" : "")$5"\n"\
" expected: "$6"\n"\
" actual: "$4"\n"\
" operator: "$4 "\n"\
" expected: "$6 "\n"\
" actual: "$5 "\n"\
" ..."
}
}
Expand Down

0 comments on commit b195bc1

Please sign in to comment.