10

In my Makefile.am, I have the following test:

TESTS += tests/test1
check_PROGRAMS += tests/test1
tests_test1_SOURCES = tests/test1.c
tests_test1_CPPFLAGS = ...
tests_test1_LDADD = ...

test1 is compiled and run when make check is invoked. How should Makefile.am be modified to pass a command line argument to test1?

Mike Kwan
  • 24,123
  • 12
  • 63
  • 96

2 Answers2

14

You cannot pass arguments to tests.

Instead of

TESTS += tests/test1

do

TESTS += tests/test1.test
EXTRA_DIST += tests/test1.test

where tests/test1.test is an executable shell script that will run your program with any argument you wish:

#!/bin/sh
tests/test1 args... < $srcdir/tests/distributed-input-file
adl
  • 15,627
  • 6
  • 51
  • 65
  • +1 for the answering my rather different question of whether there was a way to use `$srcdir` in test scripts - turns out it's just that simple :) – underscore_d Jul 26 '17 at 13:49
0

You can also pass parameters via the environment. This is handy when you want to pass different parameters in different runs of make check.

Say you have tests/test1.test with the following:

#!/bin/bash
tests/test1 $TEST_FLAGS < $srcdir/tests/distributed-input-file

Now, you can run the following:

$ TEST_FLAGS=--verbose make check

And the --verbose flag would be passed to your test program whenever you want it to display extra info for debugging purposes.

Paulo
  • 757
  • 8
  • 18