打破 Travis-CI 基于 dotnet 测试失败的构建

Break Travis-CI build on dotnet test failure

做一些概念验证我在 NetCoreXunit 有一个简单的 netcore 回购和一些 xUnit 测试,我必须在 Appveyor 和 Travis 上构建。我进行了一次失败的测试,Appveyor 的构建失败了,但我正在努力让 Travis 做同样的事情。它愉快地执行测试并报告其中一项测试失败但通过了构建。

我用 Google 搜索到死,一直在尝试在 yaml 配置的脚本步骤中通过管道传输和解析输出,但我的脚本知识并不丰富。

如果有人可以帮助我让 Travis 使构建失败,我将不胜感激。 GitHub 回购中有一个 link 到我的 Appveyor 和 Travis 构建,如果您提交回购,它应该会自动构建。

--更新-- 因此,就解析两个测试程序集的输出并正确识别是否存在测试失败而言,我得到了它;但我需要创建一个变量,以便在退出之前对两个程序集进行测试。我不得不跳过愚蠢的圈套才能走到这一步;一个是我似乎无法在没有 Travis 抱怨的情况下定义变量。它也是硬编码的,我想扩展它以查找所有测试程序集,而不仅仅是硬编码的。

after_success:
  # Run tests
  - dotnet test ./src/NetCoreXunit -xml ./out/NetCoreXunit.xml;
    if grep -q 'result="Fail"' ./out/NetCoreXunit.xml ;  then
      echo 'Failed tests detected.';
    else
      echo 'All tests passed.';
    fi;
  - dotnet test ./src/NetCoreXunitB -xml ./out/NetCoreXunitB.xml;
    if grep -q 'result="Fail"' ./out/NetCoreXunitB.xml ;  then
      echo 'Failed tests detected.';
    else
      echo 'All tests passed.';
    fi;

任何建议表示赞赏:我如何获得所有测试程序集的列表以及如何声明和设置一个 bool,然后我可以用它退出代码?

花了很长时间才让 .travis.yml 工作;应该直接沿着 Python 路线前进;从 yml.

import os
import sys
import re
from subprocess import call

root_directory = os.getcwd()
print (root_directory)

regexp = re.compile(r'src[\/\]NetCoreXunit.?$')
result = False
for child in os.walk(root_directory):
    print (child[0])
    if regexp.search(child[0]) is not None:
        print ("Matched")
        test_path = os.path.join(root_directory, child[0])
        if os.path.isdir(test_path):
            print ("IsDir")
            print (test_path)
            os.chdir(test_path)
            call (["dotnet", "test", "-xml", "output.xml"])
            if 'result="Fail"' in open("output.xml").read():
                print (test_path + ": Failed tests detected")
                result = True
            else:
                print (test_path + ": All tests passed")

os.chdir(root_directory)

if result:
    print ("Failed tests detected")
    sys.exit(1)