Skip to content

Commit

Permalink
Update CI only on CLI test on Ubuntu Server.
Browse files Browse the repository at this point in the history
  • Loading branch information
huacnlee committed Apr 5, 2024
1 parent 5074efe commit 48abfd7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
19 changes: 18 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,24 @@ jobs:
- name: Build
run: cargo build
- name: Test
run: make test
run: cargo test
cli_test:
name: CLI Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup | Cache Cargo
uses: actions/[email protected]
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ matrix.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Run CLI Test
run: ./tests/cli_test.sh
lint:
name: Lint
runs-on: ubuntu-latest
Expand Down
17 changes: 10 additions & 7 deletions tests/cli_test.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#!/bin/bash
#!/usr/bin/env bash
echo "Running tests for 'pestfmt --stdin'..."

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 48abfd7

Please sign in to comment.