Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DannyBen committed Mar 8, 2024
1 parent 5f22af7 commit 08a9418
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 28 deletions.
6 changes: 3 additions & 3 deletions approvals.bash
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,12 @@ trap 'onerror' ERR
describe_string="$(bold ▌ describe) %s"
context_string="$(bold ▌ context) %s"
it_string="$(bold ▌ it) %s"
fail_string=" $(red FAILED) %s"
fail_string=" $(red_bold failed) %s"
pass_string=" $(green approved) %s"
exit_success_string="$(green ▌ exit) $(bold %s finished successfully)"
exit_failed_string="$(red ▌ exit) $(bold %s finished with errors)"
exit_failed_string="$(red_bold ▌ exit) $(bold %s finished with errors)"
new_diff_string="────┤ $(yellow new): $(bold %s) ├────"
changed_diff_string="────┤ $(cyan changed): $(bold %s) ├────"
changed_diff_string="────┤ $(blue changed): $(bold %s) ├────"
approval_string="[A]pprove? "

if diff --help | grep -- --color >/dev/null 2>&1; then
Expand Down
1 change: 1 addition & 0 deletions test/approvals/ls_no_such_dir
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ls: cannot access 'no-such-dir': No such file or directory
58 changes: 33 additions & 25 deletions test/approve
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,41 @@
# Source the approvals script
source "approvals.bash"

# Test commands
# Test everything inside the test directory
cd ./test || exit
context "standard operation"
describe "sample cli test"
approve "./sample-cli-app.sh"
approve "./sample-cli-app.sh --help"
approve "./sample-cli-app.sh say"
approve "./sample-cli-app.sh say hello"
approve "./sample-cli-app.sh say hello" "alternative_fixture_file"

# ignore the part matching this regex in the following approve call
allow_diff "[0-9]+"
approve "./sample-cli-app.sh random"

context "when APPROVALS_DIR is set"
APPROVALS_DIR=alt-approvals

it "writes approvals to a different directory"
approve "./sample-cli-app.sh"

unset APPROVALS_DIR
# Test commands
describe "approve"
approve "./sample-cli-app.sh"
approve "./sample-cli-app.sh --help"
approve "./sample-cli-app.sh say"
approve "./sample-cli-app.sh say hello"
approve "./sample-cli-app.sh say hello" "alternative_fixture_file"

context "when APPROVALS_DIR is set"
APPROVALS_DIR=alt-approvals

it "writes approvals to a different directory"
approve "./sample-cli-app.sh"

context "when AUTO_APPROVE is set"
AUTO_APPROVE=1
rm -f approvals/ls
unset APPROVALS_DIR

it "writes approvals without prompting the user"
approve "ls"
context "when AUTO_APPROVE is set"
AUTO_APPROVE=1
rm -f approvals/ls

it "writes approvals without prompting the user"
approve "ls"

unset AUTO_APPROVE

describe "allow_diff"
it "ignores anything matching the regex in the next approve call"
allow_diff "[0-9]+"
approve "./sample-cli-app.sh random"

unset AUTO_APPROVE
describe "expect_exit_code"
context "when the previous approve exited with the expected code"
it "passes"
approve "ls no-such-dir"
expect_exit_code 2

0 comments on commit 08a9418

Please sign in to comment.