Giter Club home page Giter Club logo

best's Introduction

Best

A testing framework designed for Bash, and built with Bash.

Minimum Bash version: 3.2.0
Supported platforms:

  • GNU Linux
  • MacOS

Command Line

bin/best.sh [options] [test...]

Options:

Option Value Description
--jobs / -j [number] Specify the number of tests to run in parallel. Defaults to the current number of logical cores.
--suite [string] Loads a specific test suite.
If this is absent, all suites in $PWD/test will be loaded.
--snapshot:generate Forces all snapshots to be regenerated.
--snapshot:show Prints the difference between test output and output snapshots.
--snapshot:skip Skips snapshot testing.
--verbose Prints STDOUT and STDERR of failed tests.
--strict Treat skipped tests as though they were failed tests.
--failed Only show failed tests.
--VERBOSE Prints STDOUT and STDERR of all tests.
--debug Prints debug information.
This only prints information about best itself.
--porcelain Changes the printing mode to something machine-friendly.
--color Enable color output.
--no-color Disable color output.

Subcommands:

Subcommand Description
--list Prints a list of tests in the loaded suites.
--version Prints the version and exits.
--repl Enters a minimal REPL similar to the IPC API.

Environment Variables:

Variable Description Default
$BEST_BASH A path to the version of Bash to execute tests with.
$TEST_ENV_TMPDIR The value of $TMPDIR inside the testing environment. Inherited
$TEST_ENV_PATH The value of $PATH inside the testing environment. Inherited
$TEST_ENV_HOME The value of $HOME inside the testing environment. Inherited
$TEST_ENV_TERM The value of $TERM inside the testing environment. xterm-color
$TEST_LIB_PREFIX A variable that prepends a sequence to the test functions. This can be used to prevent function name conflicts with best and the scripts that it's testing. None
$TEST_SHIM_PATH The path to the shims loadable by use_shim. None
$TEST_DIR The directory where test suites are stored. $PWD/test
$SNAPSHOT_DIR The directory where snapshots are stored. $PWD/test-data

Tests

Suites

Test suites are located inside $(PWD)/test as .sh files.

test:my_test() {
    description 'This is your first test.'

    assert_equal 1 1
    assert [ "a" = "b" ]
}

Functions

Setup / Teardown

The functions named setup and teardown are used for test suite setup and teardown. The former will be called when the suite is loaded, and the latter will be called after all tests are run.

setup() {
    MY_VAR=3
}

teardown() {
    unset MY_VAR
}

test:check_setup() {
    assert_equal "$MY_VAR" 3
}

best's People

Contributors

eth-p avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

best's Issues

Add support for `assert_exit`.

In some cases, we want a script to fail. best should have some mechanism for declaring what the exit code should be, and failing the test if it doesn't match what it received.

Add tests for `best`.

This is getting a bit meta, but there should be tests to ensure that best does not run into regressions.

Prefix functions.

There's a remote possibility that some of the functions provided by best will override (or be overridden by) some of the functions that would be tested by a test suite. Should I prefix the functions with a colon?

test:something() {
    :description "My test"
    :expect [ 1 = 3 ]
}

Fails if TMPDIR environment variable not set

I tried to install your bat-extras in a Ubuntu 20.04 docker container, and it failed during the verification step with a bunch of error messages like this:

/home/jetzerb/tmp/install/bat-extras/.test-framework/libexec/best-runner.sh: line 173: /96419.async_96445.report: Permission denied
/home/jetzerb/tmp/install/bat-extras/.test-framework/libexec/best-runner.sh: line 63: /96419.test_version.stdout: Permission denied
mv: cannot stat '/96419.async_96445.report': No such file or directory

Turns out the TMPDIR environment variable isn't set. After setting the variable to a suitable tmp dir, I tried again and everything ran to completion as expected.

FYI: I also have a Manjaro system that doesn't set TMPDIR by default, so perhaps it's not a very reliable variable?

Could you update to check whether TMPDIR is set, and if not then set it to a suitable value, such as one of the following:

  • a newly-created dir within $__BEST_ROOT
  • the output of mktemp -d
  • /var/tmp
  • /tmp

thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.