Skip to content

Commit

Permalink
Fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
huacnlee committed Apr 5, 2024
1 parent 5074efe commit bd9ca56
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions tests/cli_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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:]]*$//'
}
Expand All @@ -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
Expand All @@ -37,19 +38,21 @@ 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"
}

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."

0 comments on commit bd9ca56

Please sign in to comment.