gpt4 book ai didi

shell - Travis-CI 和 Shell 脚本

转载 作者:行者123 更新时间:2023-12-04 02:16:26 24 4
gpt4 key购买 nike

我使用 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

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

虽然脚本上面的几行清楚地表明情况并非如此,但似乎调用了不带参数的脚本

+. ../check_ssl_cert --source-only

我错过了什么吗?

最佳答案

Travis 很可能在其 /bin/sh 中使用 其他 的 shell 而不是 bash . 的解释器和参数/source运算符不是 POSIX specified而且那个 shell 显然不支持它们。

关于shell - Travis-CI 和 Shell 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33465760/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com