From fbf20d48af8ae6a18e44aa89e58e47c09fe06147 Mon Sep 17 00:00:00 2001 From: Dominic Ricottone Date: Fri, 16 Sep 2022 21:36:53 -0500 Subject: [PATCH] vimsplit update Test suite added. Error messages were being incorrectly suppressed. --- core/test/vimsplit.bats | 102 ++++++++++++++++++++++++++++++++++++++++ core/vimsplit | 4 +- 2 files changed, 104 insertions(+), 2 deletions(-) create mode 100644 core/test/vimsplit.bats diff --git a/core/test/vimsplit.bats b/core/test/vimsplit.bats new file mode 100644 index 0000000..200398c --- /dev/null +++ b/core/test/vimsplit.bats @@ -0,0 +1,102 @@ +#!/usr/bin/env bats +bats_require_minimum_version 1.5.0 + +@test "vimsplit version" { + run --separate-stderr vimsplit --version + [ "$status" -eq 0 ] + [ "$output" = "vimsplit 1.0" ] + [ "$stderr" = "" ] +} + +@test "vimsplit version short" { + run --separate-stderr vimsplit -v + [ "$status" -eq 0 ] + [ "$output" = "vimsplit 1.0" ] + [ "$stderr" = "" ] +} + +@test "vimsplit help" { + run --separate-stderr vimsplit --help + [ "$status" -eq 0 ] + [ "${lines[0]}" = "Open two files in split windows" ] + [ "${lines[1]}" = "Usage: vimsplit FILE1 FILE2" ] + [ "${lines[2]}" = "Options:" ] + [ "${lines[3]}" = " -h, --help print this message and exit" ] + [ "${lines[4]}" = " -v, --version print version number and exit" ] + [ "$stderr" = "" ] +} + +@test "vimsplit help short" { + run --separate-stderr vimsplit -h + [ "$status" -eq 0 ] + [ "${lines[0]}" = "Open two files in split windows" ] + [ "${lines[1]}" = "Usage: vimsplit FILE1 FILE2" ] + [ "${lines[2]}" = "Options:" ] + [ "${lines[3]}" = " -h, --help print this message and exit" ] + [ "${lines[4]}" = " -v, --version print version number and exit" ] + [ "$stderr" = "" ] +} + +@test "vimsplit 1 file" { + run --separate-stderr vimsplit foobarbaz + [ "$status" -eq 1 ] + [ "$output" = "" ] + [ "$stderr" = "vimsplit: Expected 2 arguments (given 1)" ] +} + +@test "vimsplit 1 file - quiet" { + run --separate-stderr vimsplit foobarbaz --quiet + [ "$status" -eq 1 ] + [ "$output" = "" ] + [ "$stderr" = "" ] +} + +@test "vimsplit 1 file - quiet short" { + run --separate-stderr vimsplit foobarbaz -q + [ "$status" -eq 1 ] + [ "$output" = "" ] + [ "$stderr" = "" ] +} + +@test "vimsplit no such file" { + run --separate-stderr vimsplit foo bar + [ "$status" -eq 1 ] + [ "$output" = "" ] + [ "$stderr" = "vimsplit: No such file 'foo'" ] +} + +@test "vimsplit no such file - quiet" { + run --separate-stderr vimsplit foo bar --quiet + [ "$status" -eq 1 ] + [ "$output" = "" ] + [ "$stderr" = "" ] +} + +@test "vimsplit no such file - quiet short" { + run --separate-stderr vimsplit foo bar -q + [ "$status" -eq 1 ] + [ "$output" = "" ] + [ "$stderr" = "" ] +} + +@test "vimsplit 3 file" { + run --separate-stderr vimsplit foo bar baz + [ "$status" -eq 1 ] + [ "$output" = "" ] + [ "$stderr" = "vimsplit: Expected 2 arguments (given 3)" ] +} + +@test "vimsplit 3 file - quiet" { + run --separate-stderr vimsplit foo bar baz --quiet + [ "$status" -eq 1 ] + [ "$output" = "" ] + [ "$stderr" = "" ] +} + +@test "vimsplit 3 file - quiet short" { + run --separate-stderr vimsplit foo bar baz -q + [ "$status" -eq 1 ] + [ "$output" = "" ] + [ "$stderr" = "" ] +} + diff --git a/core/vimsplit b/core/vimsplit index ee7ee58..02d7036 100755 --- a/core/vimsplit +++ b/core/vimsplit @@ -43,12 +43,12 @@ done # check files if [ ! -f "$file1" ]; then - if [ "$quiet" -eq 1 ]; then + if [ "$quiet" -eq 0 ]; then (>&2 /usr/bin/printf "%s: No such file '%s'\n" "$name" "$file1") fi exit 1 elif [ ! -f "$file2" ]; then - if [ "$quiet" -eq 1 ]; then + if [ "$quiet" -eq 0 ]; then (>&2 /usr/bin/printf "%s: No such file '%s'\n" "$name" "$file2") fi exit 1 -- 2.45.2