From 07fe18af75856d3af5450f6a6cd615a5cc4bfe46 Mon Sep 17 00:00:00 2001 From: Ismo Vuorinen Date: Mon, 30 Jun 2025 08:51:06 +0300 Subject: [PATCH] fix(scripts): correct usage and help exit status (#143) --- local/bin/x-gh-get-latest-version | 2 +- local/bin/x-mkd | 2 +- tests/x-gh-get-latest-version.bats | 2 +- tests/x-localip.bats | 6 ++++++ tests/x-mkd.bats | 6 ++++++ tests/x-path.bats | 6 ++++++ 6 files changed, 21 insertions(+), 3 deletions(-) diff --git a/local/bin/x-gh-get-latest-version b/local/bin/x-gh-get-latest-version index dc8e0fa..61a87c4 100755 --- a/local/bin/x-gh-get-latest-version +++ b/local/bin/x-gh-get-latest-version @@ -97,7 +97,7 @@ Examples: # Use GitHub Enterprise API GITHUB_API_URL="https://github.example.com/api/v3/repos" $BIN ivuorinen/dotfiles EOF - exit 1 + exit 0 } # Check that required dependencies are installed diff --git a/local/bin/x-mkd b/local/bin/x-mkd index 9932ed0..7daa2f8 100755 --- a/local/bin/x-mkd +++ b/local/bin/x-mkd @@ -1,7 +1,7 @@ #!/usr/bin/env bash # # Create a directory and cd into it -# Usage: mkcd +# Usage: x-mkd set -euo pipefail diff --git a/tests/x-gh-get-latest-version.bats b/tests/x-gh-get-latest-version.bats index 9dfa4c5..3852008 100644 --- a/tests/x-gh-get-latest-version.bats +++ b/tests/x-gh-get-latest-version.bats @@ -2,6 +2,6 @@ @test "x-gh-get-latest-version help" { run bash local/bin/x-gh-get-latest-version --help - [ "$status" -eq 1 ] + [ "$status" -eq 0 ] [[ "$output" == "Usage: x-gh-get-latest-version"* ]] } diff --git a/tests/x-localip.bats b/tests/x-localip.bats index fc9d9c8..3d8d716 100644 --- a/tests/x-localip.bats +++ b/tests/x-localip.bats @@ -5,3 +5,9 @@ [ "$status" -eq 0 ] [[ "$output" == "x-localip version"* ]] } + +@test "x-localip help" { + run bash local/bin/x-localip --help + [ "$status" -eq 0 ] + [[ "$output" == "Usage:"* ]] +} diff --git a/tests/x-mkd.bats b/tests/x-mkd.bats index ce7a4b9..06985e3 100644 --- a/tests/x-mkd.bats +++ b/tests/x-mkd.bats @@ -6,3 +6,9 @@ [ "$status" -eq 0 ] [ -d "$dir" ] } + +@test "x-mkd with no args shows usage" { + run bash local/bin/x-mkd + [ "$status" -eq 1 ] + [[ "$output" == "Usage:"* ]] +} diff --git a/tests/x-path.bats b/tests/x-path.bats index 629e214..0f4fec2 100644 --- a/tests/x-path.bats +++ b/tests/x-path.bats @@ -20,3 +20,9 @@ VERBOSE=1 source local/bin/x-path-remove "$BATS_TMPDIR/dir" [ "$PATH" = "/usr/bin" ] } + +@test "x-path-append skips missing directory" { + PATH="/usr/bin" + VERBOSE=1 source local/bin/x-path-append "$BATS_TMPDIR/no-such" + [ "$PATH" = "/usr/bin" ] +}