From 6c347a1dc0eb5d4640946a527d80b9a2aba974af Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Sat, 1 Jan 2022 15:49:17 +0000 Subject: [PATCH] add github workflow to run tests --- .github/workflows/main.yml | 18 ++++++++++ .gitignore | 3 ++ test.sh | 67 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 88 insertions(+) create mode 100644 .github/workflows/main.yml create mode 100755 test.sh diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..a0da37f --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,18 @@ +name: CI +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + workflow_dispatch: +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Setup Zig + uses: goto-bus-stop/setup-zig@v1.3.0 + with: + version: master + - name: Tests + run: ./test.sh diff --git a/.gitignore b/.gitignore index 68a2909..76d6532 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,6 @@ zig-cache/ zig-out/ .zigmod deps.zig +/test.in +/test.out +/test.expect diff --git a/test.sh b/test.sh new file mode 100755 index 0000000..0d090fc --- /dev/null +++ b/test.sh @@ -0,0 +1,67 @@ +#!/usr/bin/env bash + +set -e + +echo "Unit tests..." +zig build test + +echo "Build..." +zig build + +echo -n "Created: " +ls zig-out/bin/skip +export PATH=$PWD/zig-out/bin/:$PATH + +echo "> skip a line when reading from stdin" +INPUT=$(cat< test.expect +echo "$INPUT" | skip 1 > test.out +diff --brief test.expect test.out + +echo "> skip a line when reading from a file" +cat< test.in +line 1 +line 2 +EOF +echo "line 2" > test.expect +skip 1 test.in > test.out +diff --brief test.expect test.out + +echo "> skip until 2 matching lines seen" +cat< test.in +alpha +beta +alpha +gamma +EOF +echo "gamma" > test.expect +skip 2 test.in --line alpha > test.out +diff --brief test.expect test.out + +echo "> skip lines until 2 tokens seen" +cat< test.in +Lorem ipsum dolor sit amet, +consectetur adipiscing elit, +sed do eiusmod tempor incididunt +ut labore et dolore magna aliqua. +Ut enim ad minim veniam, +quis nostrud exercitation ullamco +laboris nisi ut aliquip ex ea +commodo consequat. +EOF +cat< test.expect +Ut enim ad minim veniam, +quis nostrud exercitation ullamco +laboris nisi ut aliquip ex ea +commodo consequat. +EOF +skip 2 test.in --token dolor > test.out +diff --brief test.expect test.out + +rm test.in test.out test.expect + +echo done