Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yockow/sstest
It's a runner for Shell Script Tests.
https://github.com/yockow/sstest
Last synced: 24 days ago
JSON representation
It's a runner for Shell Script Tests.
- Host: GitHub
- URL: https://github.com/yockow/sstest
- Owner: YOCKOW
- License: mit
- Created: 2021-11-02T03:51:20.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2021-11-14T07:52:21.000Z (almost 3 years ago)
- Last Synced: 2023-03-02T05:27:00.536Z (over 1 year ago)
- Language: Shell
- Size: 39.1 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# What is `SSTest`?
It's a runner for Shell Script Tests.
This tool has been inspired by [XCTest](https://developer.apple.com/documentation/xctest).# Requirements
* clang (only when building)
* zsh
* macOS/Linux# How to install
```console
% git clone https://github.com/YOCKOW/SSTest.git
% cd SSTest
% make test && sudo make install
```# Usage
```console
% SSTest /path/to/tests% SSTRunTestSuite /path/to/tests/test-suite
% SSTRunTestSuite /path/to/tests/test-suite --filter=test-foo
```This repository uses `SSTest` itself. Please see the scripts in [tests](./tests) directory.
# Directory/File Structure for tests
Given the following sample structure.
```
π¦ MyShellScriptProject (Current Directory)
ββ π src
ββ π some-other-resources
ββ π tests
ββ π TestSuiteA
β ββ π₯ test-A1
β ββ π₯ test-A2
ββ π TestSuiteB
ββ π₯ finalize
ββ π₯ init
ββ π₯ set-up
ββ π₯ tear-down
ββ π₯ test-B1
ββ π₯ test-B2
```## Case 1. Run tests only under `TestSuiteA`
Type the following command:
```console
% SSTRunTestSuite ./tests/TestSuiteA
```Then, the files that has prefix "test" (`test-A1` and `test-A2` in this case) will be executed.
## Case 2. Run tests only under `TestSuiteB`
`TestSuiteB` contains some files that don't have prefix "test".
- `init`: Executed only once before the first test starts.
- `finalize`: Executed only once after the last test finishes.
- `set-up`: Executed every time before each test starts.
- `tear-down`: Executed every time after each test finishes.As a result of that, when you run `TestSuiteB` as follows,
```console
% SSTRunTestSuite ./tests/TestSuiteB
```1. `init` is executed.
2. `set-up` is executed.
3. `test-B1` is executed.
4. `tear-down` is executed.
5. `set-up` is executed.
6. `test-B2` is executed.
7. `tear-down` is executed.
8. `finalize` is executed.## Case 3. Run tests under both `TestSuiteA` and `TestSuiteB`
```console
% SSTest ./tests
```# Assertion commands
Each test case (`test*` file) will be decided as failure if the exit status is not `0` or one of assertion commands (`SSTFail` or `SSTAssert*`) fails.
## `SSTFail`
`SSTFail` always fails.
```zsh
#!/bin/zsh
# Any shell can be used.SSTFail "Failure Message" -l ${(%):-%I}
# Line number is viewed when `-l` (a.k.a `--line`) parameter is passed.
```## `SSTAssert*Equal`
```zsh
#!/bin/zshSSTAssertEqual 0 0 -l ${(%):-%I} # Passes
SSTAssertEqual 0 1 -l ${(%):-%I} # Fails
SSTAssertEqual +1.23e-3 0.00123 -l ${(%):-%I} # Passes
SSTAssertEqual "string" string -l ${(%):-%I} # PassesSSTAssertEqual "0" "00" -l ${(%):-%I} # Passes because both "0" and "00" are regarded as integers.
SSTAssertIntegerEqual "0" "00" -l ${(%):-%I} # Passes
SSTAssertStringEqual "0" "00" -l ${(%):-%I} # FailsSSTAssertEqual 0 1 "Not Equalπ₯Ί" -l ${(%):-%I} # You can pass a description of a failure.
```## `SSTAssert*NotEqual`
```zsh
#!/bin/zshSSTAssertNotEqual 0 0 -l ${(%):-%I} # Fails
SSTAssertNotEqual foo bar -l ${(%):-%I} # PassesSSTAssertFloatNotEqual +1.23e-3 0.00123 -l ${(%):-%I} # Fails
SSTAssertFloatNotEqual 0.1 0.12 -l ${(%):-%I} # PassesSSTAssertIntegerNotEqual 0 0 -l ${(%):-%I} # Fails
SSTAssertIntegerNotEqual 0 1 -l ${(%):-%I} # PassesSSTAssertStringNotEqual baz baz -l ${(%):-%I} # Fails
SSTAssertStringNotEqual fizz buzz -l ${(%):-%I} # Passes
```## `SSTAssert*GreaterThan`, `SSTAssert*LessThan`, `SSTAssert*GreaterThanOrEqual`, and `SSTAssert*LessThanOrEqual`
```zsh
#!/bin/zshSSTAssertGreaterThan 2 1 -l ${(%):-%I} # Passes
SSTAssertGreaterThan "ABC" "A12" -l ${(%):-%I} # PassesSSTAssertLessThan 1 2 -l ${(%):-%I} # Passes
SSTAssertLessThan "A12" "ABC" -l ${(%):-%I} # Passes
```There are also the following assertion commands:
- `SSTAssertFloatGreaterThan`
- `SSTAssertFloatGreaterThanOrEqual`
- `SSTAssertFloatLessThan`
- `SSTAssertFloatLessThanOrEqual`
- `SSTAssertIntegerGreaterThan`
- `SSTAssertIntegerGreaterThanOrEqual`
- `SSTAssertIntegerLessThan`
- `SSTAssertIntegerLessThanOrEqual`
- `SSTAssertStringGreaterThan`
- `SSTAssertStringGreaterThanOrEqual`
- `SSTAssertStringLessThan`
- `SSTAssertStringLessThanOrEqual`## `SSTAssertMatch` and `SSTAssertNotMatch`
You can use regular expressions for assertions.
```zsh
#!/bin/zshstring="aabbbccc"
SSTAssertMatch "$string" "^a+b+c+$" -l ${(%):-%I} # Passes
SSTAssertNotMatch "$string" "a{3,}" -l ${(%):-%I} # Passes
```# License
MIT License.
See "LICENSE.txt" for more information.