diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2020-09-24 09:50:11 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-24 09:50:11 +0000 |
commit | 08cc91926db1cd17509f8578e2ff00a94747dbd4 (patch) | |
tree | 60da5f1fe45554632f80351f5217bf46db2208d7 | |
parent | 9765619787c494b8cb53ec15e45e0b3c64eee498 (diff) | |
parent | e62848752561640ecad72901938d0c0c5c17ed9a (diff) | |
download | podman-08cc91926db1cd17509f8578e2ff00a94747dbd4.tar.gz podman-08cc91926db1cd17509f8578e2ff00a94747dbd4.tar.bz2 podman-08cc91926db1cd17509f8578e2ff00a94747dbd4.zip |
Merge pull request #7763 from edsantiago/bats_better_parse_table
system tests: helpers: safer parse_table
-rw-r--r-- | test/system/005-info.bats | 6 | ||||
-rw-r--r-- | test/system/helpers.bash | 7 | ||||
-rwxr-xr-x | test/system/helpers.t | 9 |
3 files changed, 18 insertions, 4 deletions
diff --git a/test/system/005-info.bats b/test/system/005-info.bats index ef3e97af0..7452c1901 100644 --- a/test/system/005-info.bats +++ b/test/system/005-info.bats @@ -19,8 +19,8 @@ graphRoot: graphStatus: imageStore:\\\s\\\+number: 1 runRoot: -cgroupManager: -cgroupVersion: v +cgroupManager: \\\(systemd\\\|cgroupfs\\\) +cgroupVersion: v[12] " while read expect; do is "$output" ".*$expect" "output includes '$expect'" @@ -36,6 +36,8 @@ cgroupVersion: v tests=" host.buildahVersion | [0-9.] host.conmon.path | $expr_path +host.cgroupManager | \\\(systemd\\\|cgroupfs\\\) +host.cgroupVersion | v[12] host.ociRuntime.path | $expr_path store.configFile | $expr_path store.graphDriverName | [a-z0-9]\\\+\\\$ diff --git a/test/system/helpers.bash b/test/system/helpers.bash index 514ba249e..112b73962 100644 --- a/test/system/helpers.bash +++ b/test/system/helpers.bash @@ -376,7 +376,12 @@ function parse_table() { while read col; do dprint "col=<<$col>>" row+=("$col") - done < <(echo "$line" | tr '|' '\012' | sed -e 's/^ *//' -e 's/\\/\\\\/g') + done < <(echo "$line" | sed -E -e 's/(^|\s)\|(\s|$)/\n /g' | sed -e 's/^ *//' -e 's/\\/\\\\/g') + # the above seds: + # 1) Convert '|' to newline, but only if bracketed by spaces or + # at beginning/end of line (this allows 'foo|bar' in tests); + # 2) then remove leading whitespace; + # 3) then double-escape all backslashes printf "%q " "${row[@]}" printf "\n" diff --git a/test/system/helpers.t b/test/system/helpers.t index 7a331174b..190e8ba35 100755 --- a/test/system/helpers.t +++ b/test/system/helpers.t @@ -85,7 +85,7 @@ while read x y z; do check_result "$x" "''" "empty string - left-hand" check_result "$y" "''" "empty string - middle" check_result "$z" "''" "empty string - right" -done < <(parse_table " | |") +done < <(parse_table " | |") # Quotes while read x y z;do @@ -108,6 +108,13 @@ while read x y z;do check_result "$3" "g" "double quotes - token split - 3" done < <(parse_table "a 'b c' | d \"e f\" g | h") +# Split on '|' only when bracketed by spaces or at beginning/end of line +while read x y z;do + check_result "$x" "|x" "pipe in strings - pipe at start" + check_result "$y" "y|y1" "pipe in strings - pipe in middle" + check_result "$z" "z|" "pipe in strings - pipe at end" +done < <(parse_table "|x | y|y1 | z|") + # END test the parse_table helper ############################################################################### # BEGIN dprint |