Skip to content

Example of structured a bash script with tests using a docker image

License

Notifications You must be signed in to change notification settings

supergarotinho/bashtest-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Testing example for bash scripts   Tweet

Fun programming with bash and writing tests
A testing example for bash scripts


 Author: Anderson Santos
Built with ❤︎ by Anderson Santos and contributors

Table of contents

Features

  • Command parsing
    • Parse commands in different orders
    • Check for required commands
    • Parse commands separated by space
  • Testing
    • Generates code coverage
    • Runs linter and checker
  • Build
    • Show elapsed time
    • Fail if the coverage is bellow some threshold
  • Special methods for logging
  • CI
    • Configured to work with travis
    • Cache the docker images
    • Detects if it is building from travis to generate coveralls results
  • Testing Examples:
    • Table testing
    • Functional and unit tests
    • Combination of parameters validation

Getting Started

  • src: Script source files
  • tests: The test files
  • build.sh: The build script to run the tests

Structure:

project/
├── src/
├── test/
│   │── functional-tests.html
│   │── unit-tests.html
└── build.sh

How to use it

Download it; fork or clone it

Running the tests

Just call:

./build.sh

It will execute all tests inside test dir and generate a coverage report at: test/coverage folder

Last test results

Test results

Built With

  • Shunit2 - The bash testing framework
  • kcov - Code coverage tool for compiled programs, Python and Bash which uses debugging information to collect and report data without special compilation options
  • shellcheck - Bash checker

Authors

See also the list of contributors who participated in this project.

License

This project is licensed under the BSD-3 License - see the LICENSE.md file for details

Acknowledgments

We use koalaman/shellcheck image to run shellcheck

About

Example of structured a bash script with tests using a docker image

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages