Skip to content

Integration with Travis

Sandro Cirulli edited this page Oct 30, 2016 · 2 revisions

Travis is a popular Continuous Integration service for testing GitHub hosted projets.

The following example taken from the XSpec project illustrates how to run XSpec tests in a Travis build for a project hosted on GitHub.

  1. Create the following .travis.yml:

    before_script:
        - git clone -b master https://github.com/cirulls/xspec.git /tmp/xspec
        - export SAXON_CP=/tmp/xspec/saxon9he.jar
    
    script:
        - cd test
        - echo "execute XSpec unit tests"
        - ./run-xspec-tests.sh

    The commands in before_script clone the XSpec project from GitHub, store it in tmp/xpecand set up the path for Saxon. The commands in script navigate into the test directory and run a shell script that executes all the XSpec test suite. Modify the test directory to the location where your XSpec tests are stored.

  2. Create the shell script run-xspec-tests.sh that runs all the XSpec tests in the test directory (modify the relative path ../bin/xspec.sh in the second line if needed):

    for xspectest in *.xspec; 
        do ../bin/xspec.sh $xspectest &> result.log; 
        if grep -q ".*failed:\s[1-9]" result.log || grep -q "*\sError\srunning\sthe\stest\ssuite" result.log; 
    	    then echo "$xspectest failed" && exit 1; 
    	    else echo "ok $xspectest";
        fi	
    done

    This shell script outputs the name of the successful XSpec test executed. If an XSpec fails, the script stops and provides the name of failing test with the error message stored in result.log

  3. Push to your GitHub repository the following files:

    • .travis.yml: this must be pushed to the root of the GitHub repository you want to test. You can have different .travis.yml for different branches.
    • run-xspec-tests.sh: ideally this should be pushed to the same directory when your XSpec tests are located.
    • your XSpec tests

Here is an output of a successful build with XSpec tests on Travis:

Integration with Travis