Skip to content

Commit

Permalink
Merge pull request #359 from Okeanos/universal-tests
Browse files Browse the repository at this point in the history
test: make test script universally executable
  • Loading branch information
bgilbert authored Oct 5, 2022
2 parents 2e85fb9 + f763643 commit 789632b
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 16 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ jobs:
go-version: ${{ matrix.go-version }}
- name: Check out repository
uses: actions/checkout@v3
- name: Install GNU utils on macOS
if: runner.os == 'macOS'
shell: bash
run: brew install coreutils
- name: Run tests
shell: bash
run: ./test
Expand Down
4 changes: 4 additions & 0 deletions docs/release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ nav_order: 9

### Misc. changes

- The `test` script now executes all tests on all platforms if the necessary GNU
utilities are available
- CI jobs now include macOS specific instructions to install GNU utilities for
improved test coverage

### Docs changes

Expand Down
54 changes: 38 additions & 16 deletions test
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
set -euo pipefail

SRC=$(find . -name '*.go' -not -path "./vendor/*")
Expand All @@ -21,7 +21,29 @@ source ./build
echo "Running tests"
go test ./... -cover

csplit=""
head=""

if [ "$(go env GOOS)" = linux ]; then
csplit="csplit"
head="head"
elif [ "$(go env GOOS)" = darwin ]; then
# macOS has BSD versions of csplit and head that behave differently;
# check whether brew/macports supplied GNU versions exist
if hash gcsplit &> /dev/null; then
csplit="gcsplit"
fi
if hash ghead &> /dev/null; then
head="ghead"
fi
elif [ "$(go env GOOS)" = windows ]; then
# if we find a Bash on Windows we can comparatively safely assume
# Git Bash with GNU utils is being used
csplit="csplit"
head="head"
fi

if [ -n "${csplit}" ] && [ -n "${head}" ]; then
echo "Checking docs"
shopt -s nullglob
mkdir tmpdocs
Expand All @@ -32,23 +54,23 @@ if [ "$(go env GOOS)" = linux ]; then

for doc in docs/*md
do
echo "Checking $doc"
# split each doc into a bunch of tmpfiles then run butane on them
sed -n '/^<!-- butane-config -->/,/^```$/ p' < ${doc} \
| csplit - '/<!-- butane-config -->/' '{*}' -z --prefix "tmpdocs/config_$(basename ${doc%.*})_" -q

for i in tmpdocs/config_*
do
echo "Checking $i"
cat "$i" | tail -n +3 | head -n -1 \
| ${BIN_PATH}/${NAME} --strict --files-dir tmpdocs/files-dir > /dev/null \
|| (cat -n "$i" && false)
done
rm -f tmpdocs/config_*
echo "Checking ${doc}"
# split each doc into a bunch of tmpfiles then run butane on them
sed -n '/^<!-- butane-config -->/,/^```$/ p' <"${doc}" \
| ${csplit} - '/<!-- butane-config -->/' '{*}' -z --prefix "tmpdocs/config_$(basename ${doc%.*})_" -q

for i in tmpdocs/config_*
do
echo "Checking ${i}"
tail -n +3 "${i}" | ${head} -n -1 \
| "${BIN_PATH}/${NAME}" --strict --files-dir tmpdocs/files-dir >/dev/null \
|| (cat -n "${i}" && false)
done
rm -f tmpdocs/config_*
done
else
# Avoid dealing with presence/behavior of csplit
echo "skipping docs check on non-Linux"
# Avoid dealing with presence/behavior of csplit and head
echo "skipping docs check because GNU csplit and head are unavailable"
fi

echo ok

0 comments on commit 789632b

Please sign in to comment.