Skip to content

Commit d4c9923

Browse files
committed
tests: add test suite and GitHub action to run it with coverage
- [x] add test subdirectory with a suite of tests for sbang - [x] add workflow for linux tests - [x] add workflow for macos tests - [x] add workflow for shellcheck - [x] add codecov to macos tests TODO: It seems like kcov doesn't work on linux tests for some reason. Will need to debug later.
1 parent da0b5af commit d4c9923

26 files changed

+396
-6
lines changed

.codecov.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
coverage:
2+
precision: 2
3+
round: nearest
4+
range: 60...90
5+
status:
6+
project:
7+
default:
8+
threshold: 0.2%
9+
10+
ignore:
11+
- test/.*
12+
13+
comment: off

.github/workflows/linux-test.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: linux
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
jobs:
11+
unit-tests:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v2
15+
with:
16+
fetch-depth: 0
17+
- name: run unit tests
18+
run: |
19+
make -C test test

.github/workflows/macos-tests.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: macos
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
jobs:
11+
unit-tests:
12+
runs-on: macos-latest
13+
steps:
14+
- uses: actions/checkout@v2
15+
with:
16+
fetch-depth: 0
17+
- name: Setup Homebrew packages
18+
run: |
19+
brew install kcov
20+
- name: Run unit tests
21+
env:
22+
COVERAGE: true
23+
run: make -C test test
24+
- uses: codecov/codecov-action@v1
25+
with:
26+
directory: ./coverage
27+
flags: unittests

.github/workflows/shellcheck.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: shellcheck
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
jobs:
11+
shellcheck:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v2
15+
with:
16+
fetch-depth: 0
17+
- name: install shellcheck
18+
run: |
19+
sudo apt-get update
20+
sudo apt-get install shellcheck
21+
- name: run unit tests
22+
run: make -C test shellcheck

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
coverage

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
# sbang
2+
![linux](https://github.com/spack/sbang/workflows/linux/badge.svg)
3+
![macos](https://github.com/spack/sbang/workflows/macos/badge.svg)
4+
![shellcheck](https://github.com/spack/sbang/workflows/shellcheck/badge.svg)
5+
[![codecov](https://codecov.io/gh/spack/sbang/branch/main/graph/badge.svg?token=IKH7mB5qq7)](undefined)
26

37
`sbang` lets you run scripts with very long shebang (`#!`) lines.
48

sbang

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/sh
22
#
33
# Copyright 2013-2020 Lawrence Livermore National Security, LLC and other
4-
# sbang Project Developers. See the top-level COPYRIGHT file for details.
4+
# sbang project developers. See the top-level COPYRIGHT file for details.
55
#
66
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
77

@@ -67,6 +67,11 @@ done < "$script"
6767
# this saves arguments for later and intentionally assigns as an array
6868
args="$@"
6969

70+
# error if we did not find any interpreter
71+
if [ -z "$shebang_line" ]; then
72+
die "error: sbang found no interpreter in $script"
73+
fi
74+
7075
# handle scripts with sbang parameters, e.g.:
7176
#
7277
# #!/<some-long-path>/perl -w
@@ -79,11 +84,6 @@ set -- "$@"
7984
interpreter="$1"
8085
arg1="$2"
8186

82-
# error if we did not find any interpreter
83-
if [ -z "$interpreter" ]; then
84-
die "error: sbang found no interpreter in $script"
85-
fi
86-
8787
# Determine if the interpreter is a particular program, accounting for the
8888
# '#!/usr/bin/env PROGRAM' convention. So:
8989
#

test/Makefile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Copyright 2013-2020 Lawrence Livermore National Security, LLC and other
2+
# sbang project developers. See the top-level COPYRIGHT file for details.
3+
#
4+
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
5+
6+
# Run make to run the test suite with just sbang.
7+
# Run make COVERAGE=TRUE to run with kcov
8+
COVERAGE_DIR = ../coverage
9+
SBANG_SCRIPT = ../sbang
10+
SBANG = $(if $(COVERAGE),kcov $(COVERAGE_DIR) ,)$(SBANG_SCRIPT)
11+
12+
test:
13+
echo $(SBANG)
14+
SBANG="$(SBANG)" ./test-suite.sh
15+
16+
shellcheck:
17+
shellcheck $(SBANG_SCRIPT)

test/shebangs/bash.bash

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/usr/bin/env sbang
2+
#!/bin/bash

test/shebangs/lua.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/usr/bin/env sbang
2+
--!/path/to/lua

0 commit comments

Comments
 (0)