Makefile 启动服务器、运行测试、停止服务器
我有一个Makefile目标,如下所示Makefile 启动服务器、运行测试、停止服务器,makefile,exitstatus,Makefile,Exitstatus,我有一个Makefile目标,如下所示 integration-test: git-hooks java -Djava.library.path=$$(pwd)/test/integration/lib/DynamoDBLocal_lib \ -Djava.util.logging.config.file=/dev/null \ -Dorg.eclipse.jetty.LEVEL=WARN \ -Dlog4j.com.amazonaws.s
integration-test: git-hooks
java -Djava.library.path=$$(pwd)/test/integration/lib/DynamoDBLocal_lib \
-Djava.util.logging.config.file=/dev/null \
-Dorg.eclipse.jetty.LEVEL=WARN \
-Dlog4j.com.amazonaws.services.dynamodbv2.local.server.LocalDynamoDBServerHandler=OFF \
-jar $$(pwd)/test/integration/lib/DynamoDBLocal.jar \
-inMemory \
-port 8000 &
sleep 3
./node_modules/.bin/mocha --compilers coffee:coffee-script/register \
--reporter spec \
test/integration/main.coffee
ps -ef | grep [D]ynamoDBLocal_lib | awk '{print $$2}' | xargs kill
以下是我正在做的:
- Java命令启动Amazon的DynamoDB的本地实例
- 我给它3秒钟的启动时间
- 我运行集成测试
- 我杀了数据库
-
,让make
忽略它,如果这样做,问题是我不知道测试是否失败,因为$?
将始终返回0
在这种情况下,通常的做法是什么?如果这解决了我的问题,我可以将目标分割成更多的目标
谢谢。您必须在一个shell中运行整个程序,这意味着您需要使用命令分隔符(例如,
;
)和反斜杠来连接行。然后,您可以存储结果并与其一起退出:
integration-test: git-hooks
{ java -Djava.library.path=$$(pwd)/test/integration/lib/DynamoDBLocal_lib \
-Djava.util.logging.config.file=/dev/null \
-Dorg.eclipse.jetty.LEVEL=WARN \
-Dlog4j.com.amazonaws.services.dynamodbv2.local.server.LocalDynamoDBServerHandler=OFF \
-jar $$(pwd)/test/integration/lib/DynamoDBLocal.jar \
-inMemory \
-port 8000 & }; \
sleep 3; \
./node_modules/.bin/mocha --compilers coffee:coffee-script/register \
--reporter spec \
test/integration/main.coffee; \
r=$$?; \
ps -ef | grep [D]ynamoDBLocal_lib | awk '{print $$2}' | xargs kill; \
exit $$r
但是,如果使用单个shell,您实际上可以做得更好,只终止您想要的确切进程,而不是使用ps
:
integration-test: git-hooks
{ java -Djava.library.path=$$(pwd)/test/integration/lib/DynamoDBLocal_lib \
-Djava.util.logging.config.file=/dev/null \
-Dorg.eclipse.jetty.LEVEL=WARN \
-Dlog4j.com.amazonaws.services.dynamodbv2.local.server.LocalDynamoDBServerHandler=OFF \
-jar $$(pwd)/test/integration/lib/DynamoDBLocal.jar \
-inMemory \
-port 8000 & }; \
pid=$$!; \
sleep 3; \
./node_modules/.bin/mocha --compilers coffee:coffee-script/register \
--reporter spec \
test/integration/main.coffee; \
r=$$?; \
kill $$pid; \
exit $$r
“测试产生错误”和“测试失败”是同一回事吗?测试会写下你想要测试的信息吗?或者您想要返回值,如果是,那么您希望如何显示该信息?是的,在本例中是相同的。我想要退出状态,是的。Make已经显示了我命令的输出,我只想使用test命令的exit状态并返回它,我认为通过这样做Make将返回一个非0的exit状态,对吗?我编辑了我的答案,让它更清楚。非常感谢!你有没有一个链接可以让我阅读你的解决方案背后的理论?你可以在这里阅读配方语法:其余的更改与make无关,而只是学习如何在shell中编程。阅读您的shell手册页,了解任何优秀的shell编程教程。