简体   繁体   English

Travis-CI和Shell脚本

[英]Travis-CI and Shell scripts

I use shunit2 to perform some unit tests on a shell script . 我使用shunit2对shell脚本执行一些单元测试。

To be able to access the script's functions I source it 为了能够访问脚本的功能,我提供了源代码

. script_file.sh  --source-only

And in the script I have everything encapsulated in a function but for 在脚本中,我将所有内容封装在一个函数中,但是

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

This works on Linux and OS X. I have now set up Travis CI with the following .travis.yml 这适用于Linux和OSX。我现在已经使用以下.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 在Travis CI上,我看到了

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
[...]

It seems that the script is called w/o parameters although a couple of lines above it clearly shows that it is not the case 似乎该脚本被称为w / o参数,尽管脚本上方的几行清楚地表明并非如此

+. ../check_ssl_cert --source-only

Am I missing something? 我想念什么吗?

Travis is most likely using some shell other than bash for its /bin/sh interpreter and arguments to the . Travis最有可能使用bash以外的其他 shell作为其/bin/sh解释器和。参数. / source operator are not POSIX specified and that shell clearly doesn't support them. / source运算符未指定POSIX,并且该Shell显然不支持它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM