Add test Actions workflow
Grawkit Test / Test with GNU AWK (push) Successful in 55s Details
Grawkit Test / Test with Busybox AWK (push) Successful in 1m9s Details

This currently tests against GAWK and Busybox AWK, which should help
cover all POSIX-related compatibilies.
This commit is contained in:
Alex Palaistras 2024-04-09 19:47:04 +01:00
parent 3302655dcd
commit e9a813eaa7
2 changed files with 40 additions and 14 deletions

35
.github/workflows/test.yaml vendored Normal file
View File

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

View File

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