From 930cc59318cfea32f8bae5932a7e012d7b618d9c Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Mon, 18 Jun 2018 11:05:51 +1000 Subject: [PATCH] Removed all external processes from test script (minus shellcheck) --- test.sh | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/test.sh b/test.sh index c76604b..2e772bf 100755 --- a/test.sh +++ b/test.sh @@ -158,11 +158,17 @@ assert_equals() { } main() { - # Run shellcheck on the code. - awk '/```sh$/{f=1;next}/```/{f=0}f' README.md > readme_code - shellcheck -s bash --exclude=SC2034,SC2154 readme_code || exit 1 + trap 'rm readme_code' EXIT - # Source the code blocks from README.md + # Extract code blocks from the README. + while read -r line; do + [[ "$code" && "$line" != \`\`\` ]] && printf '%s\n' "$line" + [[ "$line" =~ ^\`\`\`sh$ ]] && code=1 + [[ "$line" =~ ^\`\`\`$ ]] && code= + done < README.md > readme_code + + # Run shellcheck and source the code. + shellcheck -s bash readme_code || exit 1 . readme_code head="-> Running tests on the Pure Bash Bible.." @@ -176,7 +182,6 @@ main() { comp="Completed $tot tests. ${pass:-0} passed, ${fail:-0} failed." printf '%s\n%s\n\n' "${comp//?/-}" "$comp" - rm readme_code # If a test failed, exit with '1'. ((fail>0)) || exit 0 && exit 1