sstephenson / bats

Bash Automated Testing System
MIT License
7.13k stars 517 forks source link

Helpful test script #252

Open lukechilds opened 6 years ago

lukechilds commented 6 years ago

Great job on bats, it's really nice.

I was kind of confused on how to get my tests running everywhere.

It was kind of a pain.

Anyway, I just thew together this super simple script that pulls bats down into your tests directory, then runs your tests with it. Next time you run the script it won't pull bats down again if it's still there. tests/bats should be added to .gitignore so it's never included in the actual repo.

That means I can just run ./test everywhere; CI, locally and for end users. And it just works. Thought it might be worth sharing. Happy to submit a PR if you think it would be useful.

Script is just:

#!/bin/bash
set -euo pipefail

# Pull down bats
if [ ! -d "tests/bats" ] ; then
    echo "Pulling down github.com/sstephenson/bats test framework..."
    git clone --quiet https://github.com/sstephenson/bats.git tests/bats
fi

# Run tests
echo "Running tests..."
tests/bats/bin/bats tests

And means anyone can just do:

$ ./test
Pulling down github.com/sstephenson/bats test framework...
Running tests...
 ✓ gpg is in PATH
 ✓ CHEST_DIR gets auto created
 ✓ Running with no commands returns usage with error status
 ✓ Option -e encrypts a file and sends it to the chest
 ✓ Option -d decrypts a file from the chest
 ✓ Option -z compresses data before/after sending to chest
 ✓ Option -r removes the original file after sending to the chest
 ✓ Option -l lists items in chest
 ✓ Option -k sets a custom key
 ✓ Directories with children can be added/retrieved form the chest

10 tests, 0 failures

This is the project I created it for if you're interested: https://github.com/lukechilds/chest

Potherca commented 6 years ago

This project is no longer being actively maintained by its original auther (see https://github.com/sstephenson/bats/issues/236).

You might want to migrate to the community maintained fork bats-core and report your issue there.

030 commented 6 years ago

https://medium.com/@pimterry/testing-your-shell-scripts-with-bats-abfca9bdc5b9