Travis-CI和Shell脚本

时间:2015-11-01 18:39:18

标签: shell unit-testing travis-ci shunit2

我使用shunit2对shell script执行一些单元测试。

为了能够访问脚本的功能我来源

. script_file.sh  --source-only

在脚本中,我将所有内容封装在一个函数中但是用于

if [ "${1}" != "--source-only" ]; then
    main "${@}"
fi

这适用于Linux和OS X.我现在已经使用以下.travis.yml

设置了Travis CI
language: bash

before_script:
    - curl -L "http://downloads.sourceforge.net/shunit2/shunit2-2.0.3.tgz" | tar zx
    - chmod +x $(pwd)/shunit2-2.0.3/src/shell/shunit2

script:
    - export SHUNIT2=$(pwd)/shunit2-2.0.3/src/shell/shunit2
    - make test

On Travis CI I see

Using worker: worker-linux-docker-f8d37801.prod.travis-ci.org:travis-linux-1
[...]
git.checkout
0.38s$ git clone --depth=50 --branch=master https://github.com/matteocorti/check_ssl_cert.git matteocorti/check_ssl_cert
Cloning into 'matteocorti/check_ssl_cert'...
remote: Counting objects: 285, done.
remote: Compressing objects: 100% (97/97), done.
remote: Total 285 (delta 187), reused 268 (delta 170), pack-reused 0
Receiving objects: 100% (285/285), 191.59 KiB | 0 bytes/s, done.
Resolving deltas: 100% (187/187), done.
Checking connectivity... done.
$ cd matteocorti/check_ssl_cert
$ git checkout -qf 85cb898990e583d8eac14ec693dbd79d9f3e9e6b
This job is running on container-based infrastructure, which does not allow use of 'sudo', setuid and setguid executables.
If you require sudo, add 'sudo: required' to your .travis.yml
See http://docs.travis-ci.com/user/workers/container-based-infrastructure/ for details.
before_script.1
0.26s$ curl -L "http://downloads.sourceforge.net/shunit2/shunit2-2.0.3.tgz" | tar zx
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0   418    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
  0   385    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100 34113  100 34113    0     0   133k      0 --:--:-- --:--:-- --:--:--  133k
before_script.2
0.00s$ chmod +x $(pwd)/shunit2-2.0.3/src/shell/shunit2
0.00s$ export SHUNIT2=$(pwd)/shunit2-2.0.3/src/shell/shunit2
The command "export SHUNIT2=$(pwd)/shunit2-2.0.3/src/shell/shunit2" exited with 0.
0.02s$ make test
( cd test && ./unit_tests.sh )
+[ -z /home/travis/build/matteocorti/check_ssl_cert/shunit2-2.0.3/src/shell/shunit2 ]
+[ ! -x /home/travis/build/matteocorti/check_ssl_cert/shunit2-2.0.3/src/shell/shunit2 ]
+SCRIPT=../check_ssl_cert
+[ ! -r ../check_ssl_cert ]
+NAGIOS_OK=0
+NAGIOS_CRITICAL=1
+NAGIOS_WARNING=2
+NAGIOS_UNKNOWN=3
+. ../check_ssl_cert --source-only
+VERSION=1.18.0
+SHORTNAME=SSL_CERT
+VALID_ATTRIBUTES=,startdate,enddate,subject,issuer,serial,modulus,serial,hash,email,ocsp_uri,fingerprint,
+[  != --source-only ]
+main
[...]

似乎脚本被称为w / o参数,尽管它上面的几行清楚地表明情况并非如此

+. ../check_ssl_cert --source-only

我错过了什么吗?

1 个答案:

答案 0 :(得分:3)

Travis最有可能使用一些shell 其他而不是bash作为next()解释器,/bin/sh / .运算符的参数不是{{3}那个shell显然不支持它们。