From bd9ca562f4214e51e07844634eac6188c6fc563f Mon Sep 17 00:00:00 2001 From: Jason Lee Date: Fri, 5 Apr 2024 11:43:34 +0800 Subject: [PATCH] Fix test --- tests/cli_test.sh | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/tests/cli_test.sh b/tests/cli_test.sh index 5c3e465..5e8a8d9 100755 --- a/tests/cli_test.sh +++ b/tests/cli_test.sh @@ -5,6 +5,7 @@ RED='\033[0;31m' GREEN='\033[0;32m' NC="\033[0m" +# Trim start and end whitespace trim() { sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' } @@ -16,9 +17,9 @@ assert_eq() { echo "" echo "Test failed" echo "---------------------------------------------------" - printf "${RED}Expected:${NC}\n\n$expected\n" + printf "%bExpected:%b\n\n%s\n" "${RED}" "${NC}" "$expected" echo "" - printf "${GREEN}Acctual:${NC}\n\n$acctual\n" + printf "%bAcctual:%b\n\n%s\n" "${GREEN}" "${NC}" "$acctual" echo "---------------------------------------------------" exit 1 fi @@ -37,14 +38,16 @@ assert_format_stdin() { fi # Perform pestfmt --stdin test - local acctual=$(echo "$input" | cargo run . --stdin | trim) - assert_eq "$acctual" "$expected" + local acctual + acctual=$(cargo run . --stdin <<<"$input" | trim) + assert_eq "$expected" "$acctual" } assert_format() { local input=$1 local expected=$2 - local acctual=$(cargo run . "$input" | trim) + local acctual + acctual=$(cargo run . "$input" | trim) assert_eq "$acctual" "$expected" } @@ -52,4 +55,4 @@ assert_format_stdin 'item={"a"}' 'item = { "a" }' assert_format_stdin "tests/fixtures/json.actual.pest" "tests/fixtures/json.expected.pest" assert_format "tests/fixtures/pest.expected.pest" "Formatted 0 files" -echo 'All `--stdin` tests passed.' +echo "All CLI tests passed."