Ver código fonte

Merge pull request #147 from eza-community/cafk-vhs-init

tests: vhs for integration testing
Christina Sørensen 2 anos atrás
pai
commit
f1a945f68b

+ 4 - 0
.gitignore

@@ -24,3 +24,7 @@ prime
 stage
 *.snap
 .direnv
+
+# VHS testing stuff
+out.gif
+tests/tmp

+ 3 - 0
Justfile

@@ -36,6 +36,9 @@ all-release: build-release test-release
 @test-release:
     cargo test --workspace --release --verbose
 
+alias itest := integration_tests
+@integration_tests:
+    VHS_PUBLISH=false ./tests/vhs-runner.sh
 
 #------------------------#
 # running extended tests #

+ 1 - 1
flake.nix

@@ -71,7 +71,7 @@
 
         # For `nix develop`:
         devShells.default = pkgs.mkShell {
-          nativeBuildInputs = with pkgs; [toolchain just pandoc];
+          nativeBuildInputs = with pkgs; [ toolchain just pandoc vhs ];
         };
 
         # for `nix flake check`

+ 0 - 0
tests/itest/a


+ 0 - 0
tests/itest/b


+ 0 - 0
tests/itest/c


+ 0 - 0
tests/itest/d


+ 0 - 0
tests/itest/e


+ 0 - 0
tests/itest/f


+ 0 - 0
tests/itest/g


+ 0 - 0
tests/itest/h


+ 0 - 0
tests/itest/i


+ 0 - 0
tests/itest/j


+ 0 - 0
tests/itest/k


+ 0 - 0
tests/itest/l


+ 0 - 0
tests/itest/m


+ 0 - 0
tests/itest/n


+ 0 - 0
tests/itest/o


+ 0 - 0
tests/itest/p


+ 0 - 0
tests/itest/q


+ 152 - 0
tests/references/eza-blocksize.txt

@@ -0,0 +1,152 @@
+>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+────────────────────────────────────────────────────────────────────────────────
+> cd tests/itest/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+────────────────────────────────────────────────────────────────────────────────
+> cd tests/itest
+>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+────────────────────────────────────────────────────────────────────────────────
+> cd tests/itest
+>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+────────────────────────────────────────────────────────────────────────────────
+> cd tests/itest
+> cargo run -q -- -l --blocksize
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+────────────────────────────────────────────────────────────────────────────────
+> cd tests/itest
+> cargo run -q -- -l --blocksize
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+────────────────────────────────────────────────────────────────────────────────
+> cd tests/itest
+> cargo run -q -- -l --blocksize
+.rw-r--r-- 0 0 ces 20 Aug 06:45 a
+.rw-r--r-- 0 0 ces 20 Aug 06:45 b
+.rw-r--r-- 0 0 ces 20 Aug 06:45 c
+.rw-r--r-- 0 0 ces 20 Aug 06:45 d
+.rw-r--r-- 0 0 ces 20 Aug 06:45 e
+.rw-r--r-- 0 0 ces 20 Aug 06:45 f
+.rw-r--r-- 0 0 ces 20 Aug 06:45 g
+.rw-r--r-- 0 0 ces 20 Aug 06:45 h
+.rw-r--r-- 0 0 ces 20 Aug 06:45 i
+.rw-r--r-- 0 0 ces 20 Aug 06:45 j
+.rw-r--r-- 0 0 ces 20 Aug 06:45 k
+.rw-r--r-- 0 0 ces 20 Aug 06:45 l
+.rw-r--r-- 0 0 ces 20 Aug 06:45 m
+.rw-r--r-- 0 0 ces 20 Aug 06:45 n
+.rw-r--r-- 0 0 ces 20 Aug 06:45 o
+.rw-r--r-- 0 0 ces 20 Aug 06:45 p
+────────────────────────────────────────────────────────────────────────────────
+> cd tests/itest
+> cargo run -q -- -l --blocksize
+.rw-r--r-- 0 0 ces 20 Aug 06:45 a
+.rw-r--r-- 0 0 ces 20 Aug 06:45 b
+.rw-r--r-- 0 0 ces 20 Aug 06:45 c
+.rw-r--r-- 0 0 ces 20 Aug 06:45 d
+.rw-r--r-- 0 0 ces 20 Aug 06:45 e
+.rw-r--r-- 0 0 ces 20 Aug 06:45 f
+.rw-r--r-- 0 0 ces 20 Aug 06:45 g
+.rw-r--r-- 0 0 ces 20 Aug 06:45 h
+.rw-r--r-- 0 0 ces 20 Aug 06:45 i
+.rw-r--r-- 0 0 ces 20 Aug 06:45 j
+.rw-r--r-- 0 0 ces 20 Aug 06:45 k
+.rw-r--r-- 0 0 ces 20 Aug 06:45 l
+.rw-r--r-- 0 0 ces 20 Aug 06:45 m
+.rw-r--r-- 0 0 ces 20 Aug 06:45 n
+.rw-r--r-- 0 0 ces 20 Aug 06:45 o
+.rw-r--r-- 0 0 ces 20 Aug 06:45 p
+────────────────────────────────────────────────────────────────────────────────

+ 266 - 0
tests/references/eza-long.txt

@@ -0,0 +1,266 @@
+>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+────────────────────────────────────────────────────────────────────────────────
+> cd tests/itest/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+────────────────────────────────────────────────────────────────────────────────
+> cd tests/itest
+>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+────────────────────────────────────────────────────────────────────────────────
+> cd tests/itest
+>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+────────────────────────────────────────────────────────────────────────────────
+> cd tests/itest
+> cargo run -q -- -l
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+────────────────────────────────────────────────────────────────────────────────
+> cd tests/itest
+> cargo run -q -- -l
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+────────────────────────────────────────────────────────────────────────────────
+> cd tests/itest
+> cargo run -q -- -l
+.rw-r--r-- 0 ces 20 Aug 06:45 a
+.rw-r--r-- 0 ces 20 Aug 06:45 b
+.rw-r--r-- 0 ces 20 Aug 06:45 c
+.rw-r--r-- 0 ces 20 Aug 06:45 d
+.rw-r--r-- 0 ces 20 Aug 06:45 e
+.rw-r--r-- 0 ces 20 Aug 06:45 f
+.rw-r--r-- 0 ces 20 Aug 06:45 g
+.rw-r--r-- 0 ces 20 Aug 06:45 h
+.rw-r--r-- 0 ces 20 Aug 06:45 i
+.rw-r--r-- 0 ces 20 Aug 06:45 j
+.rw-r--r-- 0 ces 20 Aug 06:45 k
+.rw-r--r-- 0 ces 20 Aug 06:45 l
+.rw-r--r-- 0 ces 20 Aug 06:45 m
+.rw-r--r-- 0 ces 20 Aug 06:45 n
+.rw-r--r-- 0 ces 20 Aug 06:45 o
+.rw-r--r-- 0 ces 20 Aug 06:45 p
+────────────────────────────────────────────────────────────────────────────────
+> cd tests/itest
+> cargo run -q -- -l
+.rw-r--r-- 0 ces 20 Aug 06:45 a
+.rw-r--r-- 0 ces 20 Aug 06:45 b
+.rw-r--r-- 0 ces 20 Aug 06:45 c
+.rw-r--r-- 0 ces 20 Aug 06:45 d
+.rw-r--r-- 0 ces 20 Aug 06:45 e
+.rw-r--r-- 0 ces 20 Aug 06:45 f
+.rw-r--r-- 0 ces 20 Aug 06:45 g
+.rw-r--r-- 0 ces 20 Aug 06:45 h
+.rw-r--r-- 0 ces 20 Aug 06:45 i
+.rw-r--r-- 0 ces 20 Aug 06:45 j
+.rw-r--r-- 0 ces 20 Aug 06:45 k
+.rw-r--r-- 0 ces 20 Aug 06:45 l
+.rw-r--r-- 0 ces 20 Aug 06:45 m
+.rw-r--r-- 0 ces 20 Aug 06:45 n
+.rw-r--r-- 0 ces 20 Aug 06:45 o
+.rw-r--r-- 0 ces 20 Aug 06:45 p
+────────────────────────────────────────────────────────────────────────────────
+> cd tests/itest
+> cargo run -q -- -l
+.rw-r--r-- 0 ces 20 Aug 06:45 a
+.rw-r--r-- 0 ces 20 Aug 06:45 b
+.rw-r--r-- 0 ces 20 Aug 06:45 c
+.rw-r--r-- 0 ces 20 Aug 06:45 d
+.rw-r--r-- 0 ces 20 Aug 06:45 e
+.rw-r--r-- 0 ces 20 Aug 06:45 f
+.rw-r--r-- 0 ces 20 Aug 06:45 g
+.rw-r--r-- 0 ces 20 Aug 06:45 h
+.rw-r--r-- 0 ces 20 Aug 06:45 i
+.rw-r--r-- 0 ces 20 Aug 06:45 j
+.rw-r--r-- 0 ces 20 Aug 06:45 k
+.rw-r--r-- 0 ces 20 Aug 06:45 l
+.rw-r--r-- 0 ces 20 Aug 06:45 m
+.rw-r--r-- 0 ces 20 Aug 06:45 n
+.rw-r--r-- 0 ces 20 Aug 06:45 o
+.rw-r--r-- 0 ces 20 Aug 06:45 p
+────────────────────────────────────────────────────────────────────────────────
+> cd tests/itest
+> cargo run -q -- -l
+.rw-r--r-- 0 ces 20 Aug 06:45 a
+.rw-r--r-- 0 ces 20 Aug 06:45 b
+.rw-r--r-- 0 ces 20 Aug 06:45 c
+.rw-r--r-- 0 ces 20 Aug 06:45 d
+.rw-r--r-- 0 ces 20 Aug 06:45 e
+.rw-r--r-- 0 ces 20 Aug 06:45 f
+.rw-r--r-- 0 ces 20 Aug 06:45 g
+.rw-r--r-- 0 ces 20 Aug 06:45 h
+.rw-r--r-- 0 ces 20 Aug 06:45 i
+.rw-r--r-- 0 ces 20 Aug 06:45 j
+.rw-r--r-- 0 ces 20 Aug 06:45 k
+.rw-r--r-- 0 ces 20 Aug 06:45 l
+.rw-r--r-- 0 ces 20 Aug 06:45 m
+.rw-r--r-- 0 ces 20 Aug 06:45 n
+.rw-r--r-- 0 ces 20 Aug 06:45 o
+.rw-r--r-- 0 ces 20 Aug 06:45 p
+────────────────────────────────────────────────────────────────────────────────
+> cd tests/itest
+> cargo run -q -- -l
+.rw-r--r-- 0 ces 20 Aug 06:45 a
+.rw-r--r-- 0 ces 20 Aug 06:45 b
+.rw-r--r-- 0 ces 20 Aug 06:45 c
+.rw-r--r-- 0 ces 20 Aug 06:45 d
+.rw-r--r-- 0 ces 20 Aug 06:45 e
+.rw-r--r-- 0 ces 20 Aug 06:45 f
+.rw-r--r-- 0 ces 20 Aug 06:45 g
+.rw-r--r-- 0 ces 20 Aug 06:45 h
+.rw-r--r-- 0 ces 20 Aug 06:45 i
+.rw-r--r-- 0 ces 20 Aug 06:45 j
+.rw-r--r-- 0 ces 20 Aug 06:45 k
+.rw-r--r-- 0 ces 20 Aug 06:45 l
+.rw-r--r-- 0 ces 20 Aug 06:45 m
+.rw-r--r-- 0 ces 20 Aug 06:45 n
+.rw-r--r-- 0 ces 20 Aug 06:45 o
+.rw-r--r-- 0 ces 20 Aug 06:45 p
+────────────────────────────────────────────────────────────────────────────────
+> cd tests/itest
+> cargo run -q -- -l
+.rw-r--r-- 0 ces 20 Aug 06:45 a
+.rw-r--r-- 0 ces 20 Aug 06:45 b
+.rw-r--r-- 0 ces 20 Aug 06:45 c
+.rw-r--r-- 0 ces 20 Aug 06:45 d
+.rw-r--r-- 0 ces 20 Aug 06:45 e
+.rw-r--r-- 0 ces 20 Aug 06:45 f
+.rw-r--r-- 0 ces 20 Aug 06:45 g
+.rw-r--r-- 0 ces 20 Aug 06:45 h
+.rw-r--r-- 0 ces 20 Aug 06:45 i
+.rw-r--r-- 0 ces 20 Aug 06:45 j
+.rw-r--r-- 0 ces 20 Aug 06:45 k
+.rw-r--r-- 0 ces 20 Aug 06:45 l
+.rw-r--r-- 0 ces 20 Aug 06:45 m
+.rw-r--r-- 0 ces 20 Aug 06:45 n
+.rw-r--r-- 0 ces 20 Aug 06:45 o
+.rw-r--r-- 0 ces 20 Aug 06:45 p
+────────────────────────────────────────────────────────────────────────────────
+> cd tests/itest
+> cargo run -q -- -l
+.rw-r--r-- 0 ces 20 Aug 06:45 a
+.rw-r--r-- 0 ces 20 Aug 06:45 b
+.rw-r--r-- 0 ces 20 Aug 06:45 c
+.rw-r--r-- 0 ces 20 Aug 06:45 d
+.rw-r--r-- 0 ces 20 Aug 06:45 e
+.rw-r--r-- 0 ces 20 Aug 06:45 f
+.rw-r--r-- 0 ces 20 Aug 06:45 g
+.rw-r--r-- 0 ces 20 Aug 06:45 h
+.rw-r--r-- 0 ces 20 Aug 06:45 i
+.rw-r--r-- 0 ces 20 Aug 06:45 j
+.rw-r--r-- 0 ces 20 Aug 06:45 k
+.rw-r--r-- 0 ces 20 Aug 06:45 l
+.rw-r--r-- 0 ces 20 Aug 06:45 m
+.rw-r--r-- 0 ces 20 Aug 06:45 n
+.rw-r--r-- 0 ces 20 Aug 06:45 o
+.rw-r--r-- 0 ces 20 Aug 06:45 p
+────────────────────────────────────────────────────────────────────────────────
+> cd tests/itest
+> cargo run -q -- -l
+.rw-r--r-- 0 ces 20 Aug 06:45 a
+.rw-r--r-- 0 ces 20 Aug 06:45 b
+.rw-r--r-- 0 ces 20 Aug 06:45 c
+.rw-r--r-- 0 ces 20 Aug 06:45 d
+.rw-r--r-- 0 ces 20 Aug 06:45 e
+.rw-r--r-- 0 ces 20 Aug 06:45 f
+.rw-r--r-- 0 ces 20 Aug 06:45 g
+.rw-r--r-- 0 ces 20 Aug 06:45 h
+.rw-r--r-- 0 ces 20 Aug 06:45 i
+.rw-r--r-- 0 ces 20 Aug 06:45 j
+.rw-r--r-- 0 ces 20 Aug 06:45 k
+.rw-r--r-- 0 ces 20 Aug 06:45 l
+.rw-r--r-- 0 ces 20 Aug 06:45 m
+.rw-r--r-- 0 ces 20 Aug 06:45 n
+.rw-r--r-- 0 ces 20 Aug 06:45 o
+.rw-r--r-- 0 ces 20 Aug 06:45 p
+────────────────────────────────────────────────────────────────────────────────

+ 114 - 0
tests/references/main.txt

@@ -0,0 +1,114 @@
+>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+────────────────────────────────────────────────────────────────────────────────
+> cargo run -q --
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+────────────────────────────────────────────────────────────────────────────────
+> cargo run -q --
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+────────────────────────────────────────────────────────────────────────────────
+> cargo run -q --
+build.rs            CONTRIBUTING.md  out.gif              src
+Cargo.lock          devtools         README.md            target
+Cargo.toml          flake.lock       result               tests
+CHANGELOG.md        flake.nix        rust-toolchain.toml  treefmt.nix
+cliff.toml          Justfile         screenshots.png      Vagrantfile
+CODE_OF_CONDUCT.md  LICENCE          SECURITY.md          xtests
+completions         man              snap
+>
+
+
+
+
+
+
+
+
+
+────────────────────────────────────────────────────────────────────────────────
+> cargo run -q --
+build.rs            CONTRIBUTING.md  out.gif              src
+Cargo.lock          devtools         README.md            target
+Cargo.toml          flake.lock       result               tests
+CHANGELOG.md        flake.nix        rust-toolchain.toml  treefmt.nix
+cliff.toml          Justfile         screenshots.png      Vagrantfile
+CODE_OF_CONDUCT.md  LICENCE          SECURITY.md          xtests
+completions         man              snap
+>
+
+
+
+
+
+
+
+
+
+────────────────────────────────────────────────────────────────────────────────
+> cargo run -q --
+build.rs            CONTRIBUTING.md  out.gif              src
+Cargo.lock          devtools         README.md            target
+Cargo.toml          flake.lock       result               tests
+CHANGELOG.md        flake.nix        rust-toolchain.toml  treefmt.nix
+cliff.toml          Justfile         screenshots.png      Vagrantfile
+CODE_OF_CONDUCT.md  LICENCE          SECURITY.md          xtests
+completions         man              snap
+>
+
+
+
+
+
+
+
+
+
+────────────────────────────────────────────────────────────────────────────────

+ 15 - 0
tests/tapes/eza-blocksize.tape

@@ -0,0 +1,15 @@
+Output outfile
+
+Set Shell fish
+Sleep 2s
+
+Type "cd tests/itest"
+Enter
+Sleep 1s
+
+Type "cargo run -q -- -l --blocksize"
+Enter
+Sleep 3s
+
+Ctrl+D
+

+ 23 - 0
tests/tapes/eza-long.tape

@@ -0,0 +1,23 @@
+Output outfile
+
+Set Shell fish
+Sleep 2s
+
+Type "cd tests/itest"
+Enter
+Sleep 1s
+
+Type "cargo run -q -- -l"
+Enter
+Sleep 3s
+
+Type "cargo run -q -- -l --grid"
+Enter
+Sleep 3s
+
+Type "cargo run -q -- -l --grid --icons"
+Enter
+Sleep 3s
+
+Ctrl+D
+

+ 10 - 0
tests/tapes/main.tape

@@ -0,0 +1,10 @@
+Output outfile
+
+Set Shell fish
+Sleep 2s
+Type "cargo run -q -- -l"
+Enter
+Sleep 3s
+Sleep 3s
+Ctrl+D
+

+ 30 - 0
tests/vhs-runner.sh

@@ -0,0 +1,30 @@
+#!/usr/bin/env fish
+
+set TEST_DIR tests
+set TAPES $TEST_DIR/tapes
+set REFERENCES $TEST_DIR/references
+set TEMP $TEST_DIR/tmp
+
+set EZA_GREEN 0D0
+set EZA_RED D00
+set EZA_YELLOW DD0
+
+function main
+
+    # Fixes command line output
+    echo ""
+
+    # TODO: automatic reference deletion
+    for file in $TAPES/*
+
+        set filename (basename $file .tape)
+
+        command fish $TEST_DIR/vhs-util.fish $filename &
+
+    end
+
+    wait 
+
+end
+
+main

+ 83 - 0
tests/vhs-util.fish

@@ -0,0 +1,83 @@
+#!/usr/bin/env fish
+
+set TEST_DIR tests
+set TAPES $TEST_DIR/tapes
+set REFERENCES $TEST_DIR/references
+set TEMP $TEST_DIR/tmp
+
+set EZA_GREEN 0D0
+set EZA_RED D00
+set EZA_YELLOW DD0
+
+alias ffmpeg="echo skipping ffmpeg" 
+
+function print_msg -a ARG -a OP -a NAME -a MSG
+    # Write operator, e.g. [+]
+    # [*]: indicates neutral result
+    # [+]: indicates positive result
+    # [-]: indicates negative result
+    set_color reset
+    echo -n "[$OP] "
+
+    # Write source, e.g. [ blocksize ]:
+    set_color reset
+    set_color -b $ARG
+    set_color 000
+    echo -n "[ $NAME ]:"
+
+    # Write message, e.g.
+    set_color reset
+    echo " $MSG"
+
+    set_color reset
+end
+
+function run_test -d "Run VHS test" -a NAME
+
+    set FUNCTION_NAME "$NAME > run_test"
+
+    set NAME_TAPE "$NAME.tape"
+
+    set SUCCESS (print_msg "$EZA_GREEN" "+" "$FUNCTION_NAME" "Success")
+    set FAILURE (print_msg "$EZA_RED" "-" "$FUNCTION_NAME" "Failure")
+
+    set GEN_DIR $TEMP
+    set GEN_FILE $GEN_DIR/$NAME.txt
+    set GEN_FILE_ESCAPE (echo $GEN_FILE | sed "s/\//\\\\\//g")
+
+    print_msg $EZA_YELLOW "*" $FUNCTION_NAME "Testing..."
+
+    cat $TAPES/$NAME_TAPE | sed s/outfile/$GEN_FILE_ESCAPE/ | vhs &>/dev/null
+
+    cmp -s -- $REFERENCES/$NAME.txt $TEMP/$NAME.txt && echo $SUCCESS || echo $FAILURE
+end
+
+function gen_test -d "Generate VHS test" -a NAME
+
+    set FUNCTION_NAME "$NAME > gen_test"
+
+    set NAME_TAPE "$NAME.tape"
+
+    set SUCCESS (print_msg "$EZA_GREEN" "+" "$FUNCTION_NAME" "Success")
+    set FAILURE (print_msg "$EZA_RED" "-" "$FUNCTION_NAME" "Failure")
+
+    set GEN_DIR $REFERENCES
+    set GEN_FILE $GEN_DIR/$NAME.txt
+    set GEN_FILE_ESCAPE (echo $GEN_FILE | sed "s/\//\\\\\//g")
+
+    # The idea behind this is that it makes it easier for users of this system
+    # to change the reference. They should now only have to delete the old
+    # reference, and a new one will be generated.
+    if builtin test -f $GEN_FILE
+        print_msg $EZA_GREEN "+" $FUNCTION_NAME "$GEN_FILE exists"
+        return
+    end
+
+    print_msg $EZA_YELLOW "*" $FUNCTION_NAME "Generating..."
+
+    cat $TAPES/$NAME_TAPE | sed s/outfile/$GEN_FILE_ESCAPE/ | vhs &>/dev/null && echo $SUCCESS || echo $FAILURE
+
+end
+
+gen_test $argv[1]
+run_test $argv[1]