From e9a813eaa72e0c57f5b9ecfc04b48769b1519fc9 Mon Sep 17 00:00:00 2001 From: Alex Palaistras Date: Tue, 9 Apr 2024 19:47:04 +0100 Subject: [PATCH] Add test Actions workflow This currently tests against GAWK and Busybox AWK, which should help cover all POSIX-related compatibilies. --- .github/workflows/test.yaml | 35 +++++++++++++++++++++++++++++++++++ Makefile | 19 +++++-------------- 2 files changed, 40 insertions(+), 14 deletions(-) create mode 100644 .github/workflows/test.yaml diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000..3a60b2c --- /dev/null +++ b/.github/workflows/test.yaml @@ -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" diff --git a/Makefile b/Makefile index 8f6cf88..3443ce6 100644 --- a/Makefile +++ b/Makefile @@ -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 '// {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 '// {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.