File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11#! /usr/bin/env bash
22
3-
43function snapshot::match_with_placeholder() {
54 local actual=" $1 "
65 local snapshot=" $2 "
@@ -13,11 +12,26 @@ function snapshot::match_with_placeholder() {
1312 regex=" ${regex// $token / (.|\\ n)* } "
1413 regex=" ^${regex} $"
1514
16- if REGEX=" $regex " perl -0 -e ' my $r=$ENV{REGEX}; exit((join("",<>)) =~ /$r/s ? 0 : 1);' <<< " $actual" ; then
17- return 0
15+ if command -v perl > /dev/null 2>&1 ; then
16+ if REGEX=" $regex " perl -0 -e ' my $r=$ENV{REGEX}; exit((join("",<>)) =~ /$r/s ? 0 : 1);' <<< " $actual" ; then
17+ return 0
18+ else
19+ return 1
20+ fi
21+ else
22+ # fallback: only supports single-line ignores
23+ local fallback_pattern
24+ fallback_pattern=$( printf ' %s' " $snapshot " | sed " s|$placeholder |.*|g" )
25+ # escape other special regex chars
26+ fallback_pattern=$( printf ' %s' " $fallback_pattern " | sed -e ' s/[][\.^$*+?{}|()]/\\&/g' )
27+ fallback_pattern=" ^${fallback_pattern} $"
28+
29+ if printf ' %s\n' " $actual " | grep -Eq " $fallback_pattern " ; then
30+ return 0
31+ else
32+ return 1
33+ fi
1834 fi
19-
20- return 1
2135}
2236
2337function assert_match_snapshot() {
You can’t perform that action at this time.
0 commit comments