<commit_before>function fishtape --description "Test scripts, functions, and plugins in Fish"
    switch "$argv"
        case -v --version
            echo "fishtape, version 3.0.0"
        case "" -h --help
            echo "Usage: fishtape <files ...>  Run test files"
            echo "Options:"
            echo "       -v or --version  Print version"
            echo "       -h or --help     Print this help message"
        case \*
            set --local files (realpath $argv)

            for file in $files
                if test ! -f $file
                    echo "fishtape: Invalid file or file not found: \"$file\"" >&2
                    return 1
                end
            end

            set --local operators -{n,z,b,c,d,e,f,g,G,k,L,O,p,r,s,S,t,u,w,x}
            set --local expectations \
                "a non-zero length string" \
                "a zero length string" \
                "a block device" \
                "a character device" \
                "a directory" \
                "an existing file" \
                "a regular file" \
                "a file with the set-group-ID bit set" \
                "a file with same group ID as the current user" \
                "a file with the sticky bit set" \
                "a symbolic link" \
                "a file owned by the current user" \
                "a named pipe" \
                "a file marked as readable" \
                "a file of size greater than zero" \
                "a socket" \
                "a terminal tty file descriptor" \
                "a file with the set-user-ID bit set" \
                "a file marked as writable" \
                "a file marked as executable"

            set --universal _fishtape_test_number 0
            set --universal _fishtape_test_passed 0
            set --universal _fishtape_test_failed 0

            function @echo
                echo "# $argv"
            end

            function @test --argument-names name --inherit-variable operators --inherit-variable expectations
                set --erase argv[1]
                set --query argv[2] || set --append argv ""

                set _fishtape_test_number (math $_fishtape_test_number + 1)

                if test $argv
                    set _fishtape_test_passed (math $_fishtape_test_passed + 1)

                    echo "ok $_fishtape_test_number $name"
                else
                    set _fishtape_test_failed (math $_fishtape_test_failed + 1)

                    status print-stack-trace |
                        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 "$operator"$argv[2]
                        set expected (string escape -- $argv[3])
                        set actual (string escape -- $argv[1])
                    else
                        set operator "$operator"$argv[1]
                        set expected "$negation"$expectations[(contains --index -- $argv[1] $operators)]
                        set actual (string escape -- $argv[2])
                    end

                    echo "not ok $_fishtape_test_number $name"
                    echo "  ---"
                    echo "    operator: $operator"
                    echo "    expected: $expected"
                    echo "    actual: $actual"
                    echo "    at: $at"
                    echo "  ..."
                end
            end<commit_msg>Move math and stack trace code to bottom<commit_after>function fishtape --description "Test scripts, functions, and plugins in Fish"
    switch "$argv"
        case -v --version
            echo "fishtape, version 3.0.0"
        case "" -h --help
            echo "Usage: fishtape <files ...>  Run test files"
            echo "Options:"
            echo "       -v or --version  Print version"
            echo "       -h or --help     Print this help message"
        case \*
            set --local files (realpath $argv)

            for file in $files
                if test ! -f $file
                    echo "fishtape: Invalid file or file not found: \"$file\"" >&2
                    return 1
                end
            end

            set --local operators -{n,z,b,c,d,e,f,g,G,k,L,O,p,r,s,S,t,u,w,x}
            set --local expectations \
                "a non-zero length string" \
                "a zero length string" \
                "a block device" \
                "a character device" \
                "a directory" \
                "an existing file" \
                "a regular file" \
                "a file with the set-group-ID bit set" \
                "a file with same group ID as the current user" \
                "a file with the sticky bit set" \
                "a symbolic link" \
                "a file owned by the current user" \
                "a named pipe" \
                "a file marked as readable" \
                "a file of size greater than zero" \
                "a socket" \
                "a terminal tty file descriptor" \
                "a file with the set-user-ID bit set" \
                "a file marked as writable" \
                "a file marked as executable"

            set --universal _fishtape_test_number 0
            set --universal _fishtape_test_passed 0
            set --universal _fishtape_test_failed 0

            function @echo
                echo "# $argv"
            end

            function @test --argument-names name --inherit-variable operators --inherit-variable expectations
                set --erase argv[1]
                set --query argv[2] || set --append argv ""

                set _fishtape_test_number (math $_fishtape_test_number + 1)

                if test $argv
                    set _fishtape_test_passed (math $_fishtape_test_passed + 1)

                    echo "ok $_fishtape_test_number $name"
                else
                    if test $argv[1] = "!"
                        set operator "! "
                        set expected "not "
                        set --erase argv[1]
                    end

                    if set --query argv[3]
                        set operator "$operator"$argv[2]
                        set expected (string escape -- $argv[3])
                        set actual (string escape -- $argv[1])
                    else
                        set operator "$operator"$argv[1]
                        set expected "$expected"$expectations[(contains --index -- $argv[1] $operators)]
                        set actual (string escape -- $argv[2])
                    end

                    set _fishtape_test_failed (math $_fishtape_test_failed + 1)

                    status print-stack-trace |
                        string replace --filter --regex -- "\s+called on line (\d+) of file (.+)" '$2:$1' |
                        read --local at

                    echo "not ok $_fishtape_test_number $name"
                    echo "  ---"
                    echo "    operator: $operator"
                    echo "    expected: $expected"
                    echo "    actual: $actual"
                    echo "    at: $at"
                    echo "  ..."
                end
            end
{'fraction_non_alphanumeric': 0.08995621600106143, 'fraction_numerical': 0.00636858166379196, 'mean_word_length': 1.0450352685838307, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6114520', 'n_tokens_mistral': 2020, 'n_tokens_neox': 1837, 'n_words': 634}