-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
tests/cli_test.sh
for unit test cli command.
- Loading branch information
Showing
3 changed files
with
57 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
test: | ||
cargo test | ||
cargo run . tests/fixtures/pest.expected.pest | ||
cat tests/fixtures/json.actual.pest | cargo run . --stdin | ||
sh ./tests/cli_test.sh | ||
update_grammar: | ||
curl -sSL https://github.com/pest-parser/pest/raw/master/meta/src/grammar.pest > src/grammar.pest | ||
patch src/grammar.pest src/grammar.patch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
echo 'Running tests for `pestfmt --stdin`...' | ||
|
||
RED='\033[0;31m' | ||
GREEN='\033[0;32m' | ||
NC="\033[0m" | ||
|
||
trim() { | ||
sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' | ||
} | ||
|
||
assert_format_stdin() { | ||
local input=$1 | ||
local expected=$2 | ||
|
||
# If input is a file, read it | ||
if [ -f "$input" ]; then | ||
input=$(cat $input) | ||
fi | ||
if [ -f "$expected" ]; then | ||
expected=$(cat $expected) | ||
fi | ||
|
||
# Perform pestfmt --stdin test | ||
local acctual=$(cargo run . --stdin <<< "$input" | trim) | ||
if [ "$acctual" != "$expected" ]; then | ||
echo "" | ||
echo "Test failed" | ||
echo "---------------------------------------------------" | ||
echo "${RED}Expected:${NC}\n\n$expected\n" | ||
echo "${GREEN}Acctual:${NC}\n\n$acctual\n" | ||
echo "---------------------------------------------------" | ||
exit 1 | ||
fi | ||
} | ||
|
||
assert_format() { | ||
local input=$1 | ||
local expected=$2 | ||
local acctual=$(cargo run . $input | trim) | ||
if [ "$acctual" != "$expected" ]; then | ||
echo "" | ||
echo "Test failed" | ||
echo "---------------------------------------------------" | ||
echo "${RED}Expected:${NC}\n\n$expected\n" | ||
echo "${GREEN}Acctual:${NC}\n\n$acctual\n" | ||
echo "---------------------------------------------------" | ||
exit 1 | ||
fi | ||
} | ||
|
||
assert_format_stdin 'item={"a"}' 'item = { "a2" }' | ||
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.' |