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 and Busybox AWK, which should help
cover all POSIX-related compatibilies.
  • Loading branch information
deuill committed Apr 9, 2024
1 parent 3302655 commit e9a813e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 14 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
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"
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 e9a813e

Please sign in to comment.