Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
167 views
in Technique[技术] by (71.8m points)

Meson: How to run tests that depend on an external process?

I'm writing a meson.build file where I run several tests. These tests need a server running on a port in order to run successfully.

I started with this:

exe = executable('tests-client', 'tests-client.c')
test('test-client', suite: 'foo')

To run the tests I do:

$ meson test --suite foo

To launch the server, I run a script before the test call:

exe = executable('tests-client', 'tests-client.c')
run_command('start-server.sh')
test('test-client', suite: 'foo')

However, this doesn't work because run_script runs when meson builds, not when the tests are run. I also tried to run the server as if it was a test, but although it may work, it's semantically incorrect.

question from:https://stackoverflow.com/questions/65838760/meson-how-to-run-tests-that-depend-on-an-external-process

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

One possibility is to write a little script that starts the server and calls the test that is given as an argument. Then you can use Meson's add_test_setup() with the kwarg default: true.

add_test_setup('server',                                         
  exe_wrapper: find_program('start-server-before-test.sh'),
  is_default: true,                                                
)                                                                  

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...