Skip to content

Commit

Permalink
tests: add test suite and GitHub action to run it with coverage
Browse files Browse the repository at this point in the history
- [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.
  • Loading branch information
tgamblin committed Oct 28, 2020
1 parent da0b5af commit d4c9923
Show file tree
Hide file tree
Showing 26 changed files with 396 additions and 6 deletions.
13 changes: 13 additions & 0 deletions .codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
coverage:
precision: 2
round: nearest
range: 60...90
status:
project:
default:
threshold: 0.2%

ignore:
- test/.*

comment: off
19 changes: 19 additions & 0 deletions .github/workflows/linux-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: linux

on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
unit-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: run unit tests
run: |
make -C test test
27 changes: 27 additions & 0 deletions .github/workflows/macos-tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: macos

on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
unit-tests:
runs-on: macos-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Setup Homebrew packages
run: |
brew install kcov
- name: Run unit tests
env:
COVERAGE: true
run: make -C test test
- uses: codecov/codecov-action@v1
with:
directory: ./coverage
flags: unittests
22 changes: 22 additions & 0 deletions .github/workflows/shellcheck.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: shellcheck

on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
shellcheck:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: install shellcheck
run: |
sudo apt-get update
sudo apt-get install shellcheck
- name: run unit tests
run: make -C test shellcheck
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
coverage
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# sbang
![linux](https://github.com/spack/sbang/workflows/linux/badge.svg)
![macos](https://github.com/spack/sbang/workflows/macos/badge.svg)
![shellcheck](https://github.com/spack/sbang/workflows/shellcheck/badge.svg)
[![codecov](https://codecov.io/gh/spack/sbang/branch/main/graph/badge.svg?token=IKH7mB5qq7)](undefined)

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

Expand Down
12 changes: 6 additions & 6 deletions sbang
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/sh
#
# Copyright 2013-2020 Lawrence Livermore National Security, LLC and other
# sbang Project Developers. See the top-level COPYRIGHT file for details.
# sbang project developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)

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

# error if we did not find any interpreter
if [ -z "$shebang_line" ]; then
die "error: sbang found no interpreter in $script"
fi

# handle scripts with sbang parameters, e.g.:
#
# #!/<some-long-path>/perl -w
Expand All @@ -79,11 +84,6 @@ set -- "$@"
interpreter="$1"
arg1="$2"

# error if we did not find any interpreter
if [ -z "$interpreter" ]; then
die "error: sbang found no interpreter in $script"
fi

# Determine if the interpreter is a particular program, accounting for the
# '#!/usr/bin/env PROGRAM' convention. So:
#
Expand Down
17 changes: 17 additions & 0 deletions test/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2013-2020 Lawrence Livermore National Security, LLC and other
# sbang project developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)

# Run make to run the test suite with just sbang.
# Run make COVERAGE=TRUE to run with kcov
COVERAGE_DIR = ../coverage
SBANG_SCRIPT = ../sbang
SBANG = $(if $(COVERAGE),kcov $(COVERAGE_DIR) ,)$(SBANG_SCRIPT)

test:
echo $(SBANG)
SBANG="$(SBANG)" ./test-suite.sh

shellcheck:
shellcheck $(SBANG_SCRIPT)
2 changes: 2 additions & 0 deletions test/shebangs/bash.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env sbang
#!/bin/bash
2 changes: 2 additions & 0 deletions test/shebangs/lua.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env sbang
--!/path/to/lua
2 changes: 2 additions & 0 deletions test/shebangs/no-interpreter
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This is a simple file.
It has no shebang and no interpreter.
2 changes: 2 additions & 0 deletions test/shebangs/node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env sbang
//!/path/to/node
2 changes: 2 additions & 0 deletions test/shebangs/perl-env.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env sbang
#!/usr/bin/env perl
2 changes: 2 additions & 0 deletions test/shebangs/perl-w-env.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env sbang
#!/usr/bin/env perl -w
2 changes: 2 additions & 0 deletions test/shebangs/perl-w.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env sbang
#!/usr/bin/perl -w
2 changes: 2 additions & 0 deletions test/shebangs/perl.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env sbang
#!/usr/bin/perl
3 changes: 3 additions & 0 deletions test/shebangs/php.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env sbang
<?php #!/usr/bin/php ?>
<?php echo "hello\n" ?>
6 changes: 6 additions & 0 deletions test/shebangs/python-env.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env sbang
#!/usr/bin/env python

from __future__ import print_function

print("python")
6 changes: 6 additions & 0 deletions test/shebangs/python.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env sbang
#!/usr/bin/python

from __future__ import print_function

print("python")
4 changes: 4 additions & 0 deletions test/shebangs/ruby-env.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sbang
#!/usr/bin/env ruby

puts "ruby"
4 changes: 4 additions & 0 deletions test/shebangs/ruby.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sbang
#!/usr/bin/ruby

puts "ruby"
2 changes: 2 additions & 0 deletions test/shebangs/sbang
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env sbang
#!/path/to/sbang
2 changes: 2 additions & 0 deletions test/shebangs/sbang-env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env sbang
#!/usr/bin/env sbang
2 changes: 2 additions & 0 deletions test/shebangs/sh.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env sbang
#!/bin/sh
Loading

0 comments on commit d4c9923

Please sign in to comment.