Skip to content

Commit

Permalink
Add test Actions workflow
Browse files Browse the repository at this point in the history
This currently tests against GAWK, NAWK, and Busybox AWK, which should
help cover all POSIX-related compatibilies.
  • Loading branch information
deuill committed Apr 9, 2024
1 parent 3302655 commit 4961b78
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 14 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Grawkit Test
on:
push:
branches:
- master
pull_request:
branches:
- master
jobs:
test-gawk:
runs-on: ubuntu-latest
name: Test with GNU AWK
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Install dependencies
run: |
sudo apt-get update -y
sudo apt-get install -y gawk
- name: Run tests
run: |
make test AWK=gawk
test-busybox-awk:
runs-on: ubuntu-latest
name: Test with Busybox AWK
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Install dependencies
run: |
sudo apt-get update -y
sudo apt-get install -y busybox
- name: Run tests
run: |
make test AWK="busybox awk"
test-busybox-nawk:
runs-on: ubuntu-latest
name: Test with NAWK
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Install dependencies
run: |
sudo apt-get update -y
sudo apt-get install -y nawk
- name: Run tests
run: |
make test AWK=nawk
19 changes: 5 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -63,28 +63,19 @@ doc:
@awk "$$EXTRACT_MARKDOWN" "$(CMD)"

## Execute test suite, accepts list of specific files to run.
test: test-before $(TESTS) test-after

test-before:
@printf ">> $(BOLD)Executing tests...$(RESET)\n"

test-after:
@printf ">> $(BOLD)Finished executing tests.$(RESET)\n"
test: $(TESTS)

$(TESTS):
$(eval TEST_$@ := awk '/<!--/ {f=1;next} /-->/ {exit} f' $@)
$(eval EXPECTED_$@ := awk '/-->/ {f=1;getline;next} f' $@)
$(eval ACTUAL_$@ := $(AWK) -f $(CMD) <($(TEST_$@)))

@printf ">> $(BOLD)Testing file '$@'...$(RESET) "

# Generate diff between expected and actual results and print back to user.
@result=$$($(DIFF) -ud <($(EXPECTED_$@)) <($(ACTUAL_$@)) | tail -n +3); \
@result=$$($(DIFF) -ud \
<(awk '/-->/ {f=1;getline;next} f' $@) <($(AWK) -f $(CMD) \
<(awk '/<!--/ {f=1;next} /-->/ {exit} f' $@)) | tail -n +3); \
if [ -z "$$result" ]; then \
printf "$(GREEN)OK$(RESET)\n"; \
else \
printf "$(RED)FAIL$(RESET)\n"; \
echo "$$result"; \
exit 1; \
fi \

## Show usage information for this Makefile.
Expand Down

0 comments on commit 4961b78

Please sign in to comment.