测试出错成功退出

Make Exits Successfully with Errors In A Test

这个问题不是关于如何解决中止的核心转储或错误。我希望我的测试失败,然后失败。

我认为我的实际问题出在这个食谱上。

tests: $(TSTE)
    for test in $^ ; do \
        chmod +x ./$${test} ; \
        ./$${test}; \
    done

我怀疑是因为它没有退出 for 循环。我实际上更喜欢先进行所有测试 运行,然后对退出代码求和并退出。我不确定该怎么做。

make 的输出。

for test in target/utils.exe target/requester.exe target/responder.exe target/header.exe target/server.exe ; do \
        chmod +x ./${test} ; \
        ./${test}; \
done
success 
header.exe: tests/header.c:33: test_methods: Assertion `get == GET' failed.
Aborted (core dumped)
make[1]: Leaving directory '/home/christopher/source/caffeine'

Press ENTER or type command to continue

$ echo $?                               
0

我需要 make 以错误代码退出,这样我的 cicd 管道也会失败。

编辑

这个问题没有被这个回答。 How to make makefile exit with error when using a loop?

因为这个声明立即退出,我仍然希望所有测试都完成,并且聚合退出代码冒泡。

您只需在 shell 脚本中执行此操作,就像您编写 shell 脚本一样。类似于:

tests: $(TSTE)
        err=0; \
        for test in $^ ; do \
            chmod +x ./$${test} ; \
            ./$${test} || err=$$?; \
        done; \
        exit $$err