From 6a94f7837dbc295911ca65ac64ab17c3e9f3c4ee Mon Sep 17 00:00:00 2001 From: Eugene Triguba Date: Sat, 12 Jul 2025 11:09:18 -0400 Subject: Use exit code 0 for -h --- src/main.c | 4 +++- tests/justify.bats | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main.c b/src/main.c index 8ed128c..ffa5ab4 100644 --- a/src/main.c +++ b/src/main.c @@ -28,9 +28,11 @@ int main(int argc, char *argv[]) { print_usage(argv[0]); return EXIT_FAILURE; } - linebuffer_capacity= (size_t) width; + linebuffer_capacity = (size_t) width; break; case 'h': + print_usage(argv[0]); + return EXIT_SUCCESS; default: print_usage(argv[0]); return EXIT_FAILURE; diff --git a/tests/justify.bats b/tests/justify.bats index 6b7a275..a581c94 100644 --- a/tests/justify.bats +++ b/tests/justify.bats @@ -6,11 +6,19 @@ load 'vendor/bats-file/load' JUSTIFY_BIN="./build/justify" +@test "-h should show the usage mesage" { + run "${JUSTIFY_BIN}" -h + assert_success + assert_output --partial "Usage:" +} + @test "-w should reject invalid values" { run "${JUSTIFY_BIN}" -w 0 assert_failure + assert_output --partial "Usage:" run "${JUSTIFY_BIN}" -w -1 assert_failure + assert_output --partial "Usage:" } @test "last line of the output is left aligned" { -- cgit v1.2.3