├── .gitignore ├── output.sh ├── line.sh ├── status.sh ├── helper.bash ├── .travis.yml ├── README.md ├── test.bats └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | *.log 2 | -------------------------------------------------------------------------------- /output.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "hogehoge" 4 | -------------------------------------------------------------------------------- /line.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo " 4 | hoge 5 | foo 6 | bar 7 | " 8 | -------------------------------------------------------------------------------- /status.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ ${1:-0} -eq 0 ]; then 4 | exit 0 5 | else 6 | exit 1 7 | fi 8 | 9 | -------------------------------------------------------------------------------- /helper.bash: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | assert_equal() { 4 | if [ "${1}" != "${2}" ]; then 5 | echo "${1} != ${2}" 6 | return 1 7 | fi 8 | } 9 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: bash 3 | addons: 4 | apt: 5 | sources: 6 | - sourceline: 'ppa:duggan/bats' 7 | packages: 8 | - bats 9 | - bc 10 | script: bats ./test.bats 11 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | bats-travis-ci [![Build Status](https://travis-ci.org/tkuchiki/bats-travis-ci.svg?branch=master)](https://travis-ci.org/tkuchiki/bats-travis-ci) 2 | ============== 3 | 4 | Using Bats with Travis CI 5 | 6 | ## .travis.yml 7 | 8 | ### Container-based 9 | 10 | ```yaml 11 | sudo: false 12 | language: bash 13 | addons: 14 | apt: 15 | sources: 16 | - sourceline: 'ppa:duggan/bats' 17 | packages: 18 | - bats 19 | - bc 20 | script: bats /path/to/bats 21 | ``` 22 | 23 | ### Sudo-enabled VM 24 | 25 | ```yaml 26 | language: bash 27 | before_install: 28 | - sudo add-apt-repository ppa:duggan/bats --yes 29 | - sudo apt-get update -qq 30 | - sudo apt-get install -qq bats 31 | script: 32 | - bats /path/to/bats 33 | ``` 34 | -------------------------------------------------------------------------------- /test.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | setup() { 4 | echo "setup ${BATS_TEST_NAME} ..." >> ./bats.log 5 | } 6 | 7 | teardown() { 8 | echo "teardown ${BATS_TEST_NAME} ..." >> ./bats.log 9 | } 10 | 11 | @test "addition using bc" { 12 | result="$(echo 2 + 2 | bc)" 13 | 14 | [ "${result}" -eq 4 ] 15 | } 16 | 17 | @test "status code" { 18 | run ./status.sh 19 | 20 | [ "${status}" -eq 0 ] 21 | 22 | run ./status.sh 1 23 | 24 | [ "${status}" -eq 1 ] 25 | } 26 | 27 | @test "output" { 28 | run ./output.sh 29 | 30 | [ "${output}" = "hogehoge" ] 31 | } 32 | 33 | @test "lines" { 34 | run ./line.sh 35 | 36 | [ "${lines[0]}" = "hoge" ] 37 | [ "${lines[1]}" = "foo" ] 38 | [ "${lines[2]}" = "bar" ] 39 | } 40 | 41 | @test "run command" { 42 | run bash -c "echo '1,2,3' | awk -F ',' '{ print \$3 }'" 43 | 44 | [ "${output}" = "3" ] 45 | } 46 | 47 | load helper 48 | 49 | @test "load" { 50 | run ./output.sh 51 | 52 | assert_equal "${output}" "hogehoge" 53 | } 54 | 55 | @test "skip" { 56 | skip "skipped" 57 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 tkuchiki 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | --------------------------------------------------------------------------------