@@ -34,20 +34,21 @@ function snapshot::match_with_placeholder() {
3434 fi
3535}
3636
37+ # shellcheck disable=SC2155
3738function assert_match_snapshot() {
3839 local actual
3940 actual=$( echo -n " $1 " | tr -d ' \r' )
40- local directory
41- directory= " ./ $( dirname " ${BASH_SOURCE[1]} " ) /snapshots "
42- local test_file
43- test_file= " $( helper::normalize_variable_name " $( basename " $ {BASH_SOURCE[1]}" ) " ) "
44- local snapshot_name
45- snapshot_name=" $( helper::normalize_variable_name " ${FUNCNAME[1]} " ) .snapshot"
46- local snapshot_file
47- snapshot_file= " ${directory} / ${test_file} . ${snapshot_name} "
41+ local snapshot_file= " ${2-} "
42+
43+ if [[ -z " $snapshot_file " ]] ; then
44+ local directory= " ./ $( dirname " ${BASH_SOURCE[1]} " ) /snapshots "
45+ local test_file= " $( helper::normalize_variable_name " $( basename " ${BASH_SOURCE[1]} " ) " ) "
46+ local snapshot_name=" $( helper::normalize_variable_name " ${FUNCNAME[1]} " ) .snapshot"
47+ snapshot_file= " ${directory} / ${test_file} . ${snapshot_name} "
48+ fi
4849
4950 if [[ ! -f " $snapshot_file " ]]; then
50- mkdir -p " $directory "
51+ mkdir -p " $( dirname " $snapshot_file " ) "
5152 echo " $actual " > " $snapshot_file "
5253
5354 state::add_assertions_snapshot
@@ -70,21 +71,21 @@ function assert_match_snapshot() {
7071 state::add_assertions_passed
7172}
7273
74+ # shellcheck disable=SC2155
7375function assert_match_snapshot_ignore_colors() {
7476 local actual
7577 actual=$( echo -n " $1 " | sed -r ' s/\x1B\[[0-9;]*[mK]//g' | tr -d ' \r' )
7678
77- local directory
78- directory=" ./$( dirname " ${BASH_SOURCE[1]} " ) /snapshots"
79- local test_file
80- test_file=" $( helper::normalize_variable_name " $( basename " ${BASH_SOURCE[1]} " ) " ) "
81- local snapshot_name
82- snapshot_name=" $( helper::normalize_variable_name " ${FUNCNAME[1]} " ) .snapshot"
83- local snapshot_file
84- snapshot_file=" ${directory} /${test_file} .${snapshot_name} "
79+ local snapshot_file=" ${2-} "
80+ if [[ -z " $snapshot_file " ]]; then
81+ local directory=" ./$( dirname " ${BASH_SOURCE[1]} " ) /snapshots"
82+ local test_file=" $( helper::normalize_variable_name " $( basename " ${BASH_SOURCE[1]} " ) " ) "
83+ local snapshot_name=" $( helper::normalize_variable_name " ${FUNCNAME[1]} " ) .snapshot"
84+ snapshot_file=" ${directory} /${test_file} .${snapshot_name} "
85+ fi
8586
8687 if [[ ! -f " $snapshot_file " ]]; then
87- mkdir -p " $directory "
88+ mkdir -p " $( dirname " $snapshot_file " ) "
8889 echo " $actual " > " $snapshot_file "
8990
9091 state::add_assertions_snapshot
0 commit comments