From 3a8dc11294c2aab1e7de6fbc1d3272320805a893 Mon Sep 17 00:00:00 2001 From: Doron Behar Date: Thu, 4 Mar 2021 14:58:54 +0200 Subject: [PATCH] Always exit with the exit code of the command Previously, in case a command started successfully, but failed eventually, pistol would not exit with the exit code of the command. Fixes #52. --- Makefile | 5 +++++ VERSION | 2 +- flake.lock | 6 +++--- previewer.go | 2 +- tests/34.json.bz2 | Bin 0 -> 117 bytes tests/config | 4 ++++ tests/exit-code.sh | 21 +++++++++++++++++++++ 7 files changed, 35 insertions(+), 5 deletions(-) create mode 100644 tests/34.json.bz2 create mode 100755 tests/exit-code.sh 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 0000000000000000000000000000000000000000..8507007b0bcde99ac842eebc92c2485e43ec311e GIT binary patch literal 117 zcmV-*0E+)YT4*^jL0KkKSw)*Z_W%GWUw{BGPyhfBAQ6ZFKj+@+AOJ{ek4+#nWc3<0 zqb7nWwK1Y-3`S2;rqs5-Htq0+VyGZ|QSWdeut0)Wv`Nt;2C5j%D5Vz}TK9o`D5kGO X5d+*POnXjpK>S_F6yZWa7Hs?6xKA!y literal 0 HcmV?d00001 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