开发者

GNU make: inverting sub-process success?

开发者 https://www.devze.com 2022-12-08 00:08 出处:网络
I\'ve a make file for a scripted system, with a lot开发者_如何学编程 of tests which should pass. Each test is a separate call to the scripting application:

I've a make file for a scripted system, with a lot开发者_如何学编程 of tests which should pass. Each test is a separate call to the scripting application:

#----------------------------------------------------------------------------
# run test scripts in the module::test
#----------------------------------------------------------------------------
scripted_tests: bin/kin modules/test/actor_equality.kin modules/test/actor_fibre.kin ...
    bin/kin modules/test/actor_equality.kin
    bin/kin modules/test/actor_fibre.kin
    ...

Which is fine. I also have some similar tests which should return failure. I know that - will ignore the return status, but there must be something simple to invert the return status so I can run

#----------------------------------------------------------------------------
# run test scripts in the module::test::errors
#----------------------------------------------------------------------------
inverse_tests: bin/kin modules/test/error/bad_function.kin ...
    not bin/kin modules/test/error/bad_function.kin
    ...


Use the ! command.

echo This returns success
! echo This returns failure


Suppose you want to make sure that the exit status of "bin/kin test5.kin" is 5. Then just write this:

run-test5:
  bin/kin test5.bin; test $$? = 5

For more elaborated tests see 'help test' and 'man test'.

Note: I tend to avoid exclamation marks because it is typically impossible to copy/paste them into an interactive shell (since it searches the history).

0

精彩评论

暂无评论...
验证码 换一张
取 消