[英]How to use makefile to create test results
I have a C program - example.c
and once it compiles I want to use it to generate test results. 我有一个C程序
example.c
,一旦编译,我想用它来生成测试结果。 Each file under ./tests/%.in
is a test case. ./tests/%.in
下的每个文件都是一个测试用例。
And I want from each of them to create ./tests/%.out
我想从他们每个
./tests/%.out
创建./tests/%.out
I tried something like that: 我尝试过这样的事情:
all: test_results
example: example.c
gcc example.c -o example
test_results: example ./tests/%.out
./tests/%.out: ./tests/%.in
./example $^ > $@
But I get errors, and it doesn't really seem to do the job. 但是我遇到了错误,而且似乎并没有真正做到。
%
is the wildcard character only in a pattern rule, if you want to get every files under a directory, use *
along with the wildcard
function instead: %
仅在模式规则中是通配符,如果要获取目录下的每个文件,请使用*
和wildcard
一起使用:
all: test_results
example: example.c
gcc example.c -o example
TEST_INPUT = $(wildcard tests/*.in)
test_results: example $(TEST_INPUT:.in=.out)
./tests/%.out: ./tests/%.in
./example $^ > $@
Also, you can get rid of the ./
prefix of your paths and may want to make the all
and test_results
rules phony . 此外,您还可以摆脱的
./
你的路的前缀,可能希望使all
与test_results
规则假 。 The example
dependency of your test_results
rule is misplaced too (it won't update the .out
files if example
is outdated), it should be a dependency of the .out
files themselves: 您的
test_results
规则的example
依赖项也放错了位置(如果example
已过时,它不会更新.out
文件),它应该是.out
文件本身的依赖项:
.PHONY: all
all: test_results
example: example.c
gcc example.c -o example
TEST_INPUT = $(wildcard tests/*.in)
.PHONY: test_results
test_results: $(TEST_INPUT:.in=.out)
tests/%.out: tests/%.in example
./example $< > $@
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.