From 08a941869a11c883cf755f9d7dbf67591f26df39 Mon Sep 17 00:00:00 2001 From: Danny Ben Shitrit Date: Fri, 8 Mar 2024 06:12:42 +0000 Subject: [PATCH] update tests --- approvals.bash | 6 ++-- test/approvals/ls_no_such_dir | 1 + test/approve | 58 ++++++++++++++++++++--------------- 3 files changed, 37 insertions(+), 28 deletions(-) create mode 100644 test/approvals/ls_no_such_dir diff --git a/approvals.bash b/approvals.bash index 1e3c9b5..227a51d 100644 --- a/approvals.bash +++ b/approvals.bash @@ -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 diff --git a/test/approvals/ls_no_such_dir b/test/approvals/ls_no_such_dir new file mode 100644 index 0000000..9c3861f --- /dev/null +++ b/test/approvals/ls_no_such_dir @@ -0,0 +1 @@ +ls: cannot access 'no-such-dir': No such file or directory diff --git a/test/approve b/test/approve index 7d5c929..c49eeb4 100755 --- a/test/approve +++ b/test/approve @@ -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