使用Travis CI在UNIX shell脚本上进行测试

问题描述 投票:30回答:3

背景:

我一直在使用Travis CI来完成我的PHP项目,我真的很喜欢他们如何为你提供一个图片的链接,该图片显示了项目当前版本的状态。

我目前正在使用UNIX shell脚本制作大量工具,并希望使用Travis CI来测试我的UNIX脚本。

我搜索了互联网,试图找到如何实现这一目标。我去了主网站,搜索了Stackoverflow并进行了一些谷歌搜索。

看来这是不可能的。

我目前使用shunit2来测试我的shell脚本和函数。

我的问题是:

  1. 是否可以使用Travis CI来测试shell脚本?
  2. 如果没有,我可以使用插入GitHub的替代品吗?
  3. 在shell脚本上执行集成测试的最佳方法是什么?
shell unix travis-ci shunit2
3个回答
38
投票

绝对。

我在这里做了一个简单的测试:https://travis-ci.org/soulseekah/test-shunit2-travis

我的.travis.yml文件是:

language: bash

before_script:
    - curl -L "http://downloads.sourceforge.net/shunit2/shunit2-2.0.3.tgz" | tar zx

script:
    - bash equality_test.sh

存储库:https://github.com/soulseekah/test-shunit2-travis


10
投票

我将所有内容都转换为Makefile,然后调用make test ...

language: bash
script: make test

我正在使用assert.sh,所以没有必要使用before_script。你可以在https://github.com/wmluke/dokku-domains-plugin查看。


1
投票

如果您需要最新版本的shUnit2,您可能需要从主分支获取它。

我得到它像这样工作:

---
language: bash
before_script: "sudo curl -o /usr/local/bin/shunit2 https://raw.githubusercontent.com/kward/shunit2/master/shunit2"
script: "bash shunit2/test_example.sh"

另见我的例子shunit2 repo here

© www.soinside.com 2019 - 2024. All rights reserved.