diff --git a/Makefile b/Makefile index 3b7f12b..5691f96 100644 --- a/Makefile +++ b/Makefile @@ -37,6 +37,11 @@ test: pistol @echo application/json \(issue '#'34\): @echo ------------------- @./pistol --config tests/config tests/34.json + @tput sgr0 + @echo ------------------- + @echo exit code \(issue '#'52\): + @echo ------------------- + @./tests/exit-code.sh deps: go get github.com/c4milo/github-release diff --git a/VERSION b/VERSION index 699c6c6..1a03094 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.1.8 +0.1.9 diff --git a/flake.lock b/flake.lock index 3abfb97..b41cdab 100644 --- a/flake.lock +++ b/flake.lock @@ -33,11 +33,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1605447878, - "narHash": "sha256-gvO1uqPhXOT9k5Gggfll0ZMipPIJuRu9+NFMkTfOya8=", + "lastModified": 1614535430, + "narHash": "sha256-kZwi0CooIOmFrk9eIteYSZIr4a4DVTEYV7UnURs6DSM=", "owner": "nixos", "repo": "nixpkgs", - "rev": "069f183f16c3ea5d4b6e7625433b92eba77534f7", + "rev": "0aeba64fb26e4defa0842a942757144659c6e29f", "type": "github" }, "original": { diff --git a/previewer.go b/previewer.go index 6fcea00..3f8f1fc 100644 --- a/previewer.go +++ b/previewer.go @@ -171,7 +171,7 @@ func (p *Previewer) Write(w io.Writer) (error) { log.Fatalf("We've had issues running your command: %v, %s", p.Command, p.Args) return err } - cmd.Wait() + return cmd.Wait() } else { // try to match with internal writers internal_writer, err := pistol.MatchInternalWriter(p.MimeType, p.FilePath) diff --git a/tests/34.json.bz2 b/tests/34.json.bz2 new file mode 100644 index 0000000..8507007 Binary files /dev/null and b/tests/34.json.bz2 differ diff --git a/tests/config b/tests/config index 69eddd3..e08d4e3 100644 --- a/tests/config +++ b/tests/config @@ -6,3 +6,7 @@ fpath .*/tests/fpath-with-sh$ sh: bat --map-syntax :Markdown --paging=never --st text/html elinks -dump -dump-color-mode 1 %pistol-filename% # detects: mimetype, sh: yes text/plain sh: bat --map-syntax :Markdown --paging=never --style=numbers --color=always %pistol-filename% | head -1 +# Test exit code is non-zero in case a command does not exist: +application/x-bzip2 not-a-real-command %pistol-filename% +# Test exit code is non-zero in case a command starts but fails to finish +fpath .*/tests$ bat %pistol-filename% diff --git a/tests/exit-code.sh b/tests/exit-code.sh new file mode 100755 index 0000000..1de55d1 --- /dev/null +++ b/tests/exit-code.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash + +if ./pistol --config tests/config tests/34.json.bz2; then + tput setaf 1 + echo "exit code was not non-zero when testing a non real command" + exit 1 +else + tput setaf 2 + echo "exit code was not zero" +fi + +if ./pistol --config tests/config tests; then + tput setaf 1 + echo "exit code was not non-zero when testing a real command with invalid arguments for it" + exit 1 +else + tput setaf 2 + echo "exit code was not zero" +fi +tput sgr0 +exit 0