aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorEgor Tensin <egor@tensin.name>2026-10-14 22:50:19 +0500
committerEgor Tensin <egor@tensin.name>2026-10-14 22:50:19 +0500
commit1113be584b46e7e037a2bc4ece9b3b938969ec75 (patch)
tree937e7a6cf516db8c27c5373aae5ccfcbf9c8cd55
parentmain.sh: add proper command line parameters & usage info (diff)
downloadtest-harness-1113be584b46e7e037a2bc4ece9b3b938969ec75.tar.gz
test-harness-1113be584b46e7e037a2bc4ece9b3b938969ec75.zip
shuffle files around, add the top-level symlinkv0.3.0
-rw-r--r--README.md33
l---------harness1
-rw-r--r--src/log.sh (renamed from lib/log.sh)0
-rwxr-xr-xsrc/main.sh (renamed from main.sh)14
-rw-r--r--src/test.sh (renamed from lib/test.sh)0
5 files changed, 34 insertions, 14 deletions
diff --git a/README.md b/README.md
index df58098..015b544 100644
--- a/README.md
+++ b/README.md
@@ -8,22 +8,39 @@ Used in a bunch of projects of mine, for example:
* [tag-release](https://github.com/egor-tensin/tag-release/tree/master/test)
* [config-links](https://github.com/egor-tensin/config-links/tree/master/test)
+Integration
+-----------
+
+* Can be added as a submodule like so:
+
+ > cd my/project/test
+ > git submodule add https://github.com/egor-tensin/test-harness.git runner
+
+ * Run tests using the `harness` script:
+
+ > ./test/runner/harness
+
+ * This will pick up all test files in "project/test/".
+
+* Alternatively, check out this repo somewhere and use the `-d` parameter to
+specify the path to the tests directory.
+
Usage
-----
-Supposed to be added as a submodule like so:
+* By default, all tests in the parent directory are run:
- > cd my/project/test
- > git submodule add https://github.com/egor-tensin/test-harness.git runner
+ ./test/runner/harness # Runs all tests in the test/ directory
-This will add it as a submodule in `test/runner/` in your project's directory.
+* You can filter tests to run using the `-f`/`--filter` parameter (uses
+fnmatch(3)):
-Run tests using the main.sh script:
+ ./test/runner/harness -f '*' # Runs all tests still
+ ./test/runner/harness -f '*label*' # Collects all test files containing "label"
- > ./test/runner/main.sh
+* Specify a directory to collect tests from using the `-d`/`--dir` parameter:
-The script will discover all your tests in the parent directory, run them and
-print a short summary.
+ ./harness -d path/to/tests/
API
---
diff --git a/harness b/harness
new file mode 120000
index 0000000..2dfaae6
--- /dev/null
+++ b/harness
@@ -0,0 +1 @@
+src/main.sh \ No newline at end of file
diff --git a/lib/log.sh b/src/log.sh
index db2c498..db2c498 100644
--- a/lib/log.sh
+++ b/src/log.sh
diff --git a/main.sh b/src/main.sh
index a6de982..ff5aeac 100755
--- a/main.sh
+++ b/src/main.sh
@@ -9,18 +9,20 @@ set -o errexit -o nounset -o pipefail
shopt -s inherit_errexit 2> /dev/null || true
shopt -s lastpipe
-_script_dir="$( dirname -- "${BASH_SOURCE[0]}" )"
-_script_dir="$( cd -- "$_script_dir" && pwd )"
-readonly _script_dir
_script_name="$( basename -- "${BASH_SOURCE[0]}" )"
readonly _script_name
+_script_path="$( realpath -e -- "${BASH_SOURCE[0]}" )"
+readonly _script_path
+_script_dir="$( dirname -- "$_script_path" )"
+_script_dir="$( cd -- "$_script_dir" && pwd )"
+readonly _script_dir
-source "$_script_dir/lib/log.sh"
+source "$_script_dir/log.sh"
_test_run_file() {
local test_file
for test_file; do
- source "$_script_dir/lib/test.sh"
+ source "$_script_dir/test.sh"
local lib_file
find "$tests_dir/lib" \
@@ -69,7 +71,7 @@ _test_usage() {
}
_test_parse_args() {
- tests_dir="$_script_dir/.."
+ tests_dir="$_script_dir/../.."
_test_pattern='*'
while [ "$#" -gt 0 ]; do
diff --git a/lib/test.sh b/src/test.sh
index 7c5844b..7c5844b 100644
--- a/lib/test.sh
+++ b/src/test.sh