Giter Club home page Giter Club logo

bash-test's Introduction

bash-test

Build Status Code Climate Issue Count

Simple test runner for Bash.

Installation

Just download the file (preferably somewhere in your $PATH) and give it execution permissions:

$ curl -L https://git.io/bash-test > /usr/local/bin/bash-test &&\
  chmod +x /usr/local/bin/bash-test

Usage

Write test cases as Shell Functions, starting with test_ and export the variable SOURCE with the relative path to the directory where your scripts are located.

Example:

#!/usr/bin/env bash

export SOURCE='../src'

test_something() {
  echo "foo" | grep "bar"
}

test_something_else() {
  test 2 -eq 2
}

test_my_script() {
  test $(my-script 'some input') -eq 'some output'
}

To run the tests, simply:

$ bash-test path/to/tests.sh
bash-test v0.3.0 by Campanda GmbH and contributors.

tests.sh
  ✓ test_my_script
  ✗ test_something
  ✓ test_something_else

 1 of 3 tests failed.

Test Generators

Consider the following files:

my_test_cases.txt

/       200
/login  302
/foobar 404

And my_test_generator.sh:

#!/usr/bin/env bash

data_provider_for_test_status_code=/path/to/my_test_cases.txt
function _test_status_code {
  path="$1"
  expected_status_code="$2"

  $actual=$(curl -sI http://my.website.com/$path)
  echo "$actual" | grep -q "$expected_status_code"
}

That would produce the following output:

$ bash-test /path/to/my_test_generator.sh
bash-test v0.3.0 by Campanda GmbH and contributors.

my_test_generator.sh
  ✓ _test_status_code /       200
  ✓ _test_status_code /login  302
  ✓ _test_status_code /foobar 404

 3 tests completed.

Setup and Teardown

In some_test.sh:

#!/usr/bin/env bash

before() {
  export CAKE_FILLER='chocolate'
}

test_app_configuration_through_env {
  $response=$(curl -s http://my.website.com/cake-filler)
  echo "$response" | grep -q "chocolate"
}

after() {
  unset CAKE_FILLER
}

before and after functions are executed before and after executing the tests from the current file.

License

bash-test is released under the MIT License.

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.