35

Background:

I have been using Travis CI for my PHP projects and I really like how they give you a link to a picture that shows the status of the current build of your project.

I am currently making a lot of tools using UNIX shell scripting and would like to use Travis CI to test my UNIX scripts.

I have searched the internet trying to find out how to achieve this. I went to the main website, searched Stackoverflow as well as did a bit of Google searching.

It seems like this isn't possible.

I currently use shunit2 to test my shell scripts and functions.

My question(s) is/are:

  1. Is it possible to use Travis CI to test shell scripts?
  2. If not are there any alternatives that I could use that plug into GitHub?
  3. What is the best way to perform integration testing on shell scripts?

3 Answers 3

44

Absolutely.

I made a simple test here: https://travis-ci.org/soulseekah/test-shunit2-travis

My .travis.yml file is:

language: bash

before_script:
    - curl -L "https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/shunit2/shunit2-2.1.6.tgz" | tar zx

script:
    - bash equality_test.sh

Repository: https://github.com/soulseekah/test-shunit2-travis

Sign up to request clarification or add additional context in comments.

5 Comments

Thank you very much. This is just what I was looking for. The Travis CI website is really hard to navigate. I had an extra question. I mainly make include files and I want the files to run the tests when the include is run as a script, but to avoid running tests when they are sourced. What is your method for doing this? I current use something like scriptName=$(basename $_); if [[ "$scriptName" = "$0" ]]. I apologize for not having the actual code on me at the moment. Will update a little later.
If I understood your question correctly, I believe you can simply check for one of the constants that are defined when shunit is running: shunit2.googlecode.com/svn/trunk/source/2.1/doc/…
I guess I was looking for an answer more like this stackoverflow.com/questions/2683279/… , but just as the comments said $_ and $0 are very brittle. I wanted to know if you had a special way of dealing with this. The reason being is, I want to test and validate all my scripts, but since they are includes, I don't want the tests to be run when the scripts are sourced.
But, does this script always exit 0 ? If so, Travis-CI will always think your tests have passed even when some fail. Having looked through the shunit2 docs, I can't see a way to detect how many (or if any) of the tests failed.
FYI the way I get a global exit status is to add "[[ $? == 1 ]] && exitStatus=1" in every function after every assert, where exitStatus is a global variable I set to 0 at the top of the script, and then I exit the script with "exit $exitStatus" at the end.
12

I rolled everything into a Makefile and then call make test...

language: bash
script: make test

I'm using assert.sh, so there was no need for the before_script. You can check it out at https://github.com/wmluke/dokku-domains-plugin.

Comments

2

If you need the latest version of shUnit2, you may need to get it from the master branch.

I got it working like this:

---
language: bash
before_script: "sudo curl -o /usr/local/bin/shunit2 https://raw.githubusercontent.com/kward/shunit2/master/shunit2"
script: "bash shunit2/test_example.sh"

See also my example shunit2 repo here.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.