5

In automake you can add tests using the TESTS variable but these need to be self-contained tests. I need a way to call a standard test driver providing arguments. Is there any way to do this, or to call a standard makefile target during testing?

For example, one of my targets needs to run:

driver.sh suite-a

And another time I need to run:

driver.sh suite-b

It is a hassle to have to add another bash script wrapper each time just to assign to TESTS. So either I need to add to TESTS with command line options, or I need a way to add a make target as the test itself.

How can I do this?

edA-qa mort-ora-y
  • 30,295
  • 39
  • 137
  • 267

3 Answers3

3

From Gnu Documentation, you can use:

TESTS = suite-a suite-b
LOG_COMPILER = driver.sh

if you want to have multiple scripts for tests, you can use the trick:

TESTS = suite-a.drv1 suite-b.drv1 suite-c.drv2 suite-d.drv2
TEST_EXTENSIONS = .drv1 .drv2
drv1_LOG_COMPILER = driver1.sh
drv2_LOG_COMPILER = driver2.sh

this will run:

driver1.sh suite-a.drv1
driver1.sh suite-b.drv1
driver2.sh suite-c.drv2
driver2.sh suite-d.drv2

or you may prefer use meta-warper based on name suite:

TESTS = suite-a suite-b suite-c suite-d
LOG_COMPILER = driver-warper.sh

a very simple and basic example:

driver-warper.sh:
case $1 in
     'suite-a') ./driver1.sh suite-a
     ;;
     'suite-b') ./driver1.sh suite-b
     ;;
     'suite-c') ./driver2.sh suite-c
     ;;
     'suite-d') ./driver2.sh suite-d
     ;;
esac
exit $?
Cédric ROYER
  • 389
  • 2
  • 4
  • Unlike `TEST_ENVIRONMENT`, this `LOG_COMPILER` works if the `.sh` script being called is just a simple one (i.e. not really a driver) that only expects one argument, which will be called with each element of `TESTS`. This was a nice way for me to quickly run various test files through a script, without needing repetitive tiny wrappers for each. +1! – underscore_d Oct 25 '16 at 14:10
2

If all your tests must run through driver.sh, you can use TESTS_ENVIRONMENT for that.

TESTS_ENVIRONMENT = driver.sh
TESTS = suite-a suite-b
adl
  • 15,627
  • 6
  • 51
  • 65
  • Thanks, but unfortunately the tests are mixed. I suppose I could create a separate makefile, but then I could also just create a new wrapper as well. – edA-qa mort-ora-y Mar 10 '12 at 12:51
  • Maybe you just need a meta-driver that dispatches to the right driver, (or call the tests directly) based on the name of the test. This is what I'm doing here: http://git.lrde.epita.fr/?p=spot.git;a=blob;f=wrap/python/tests/Makefile.am with the driver being this http://git.lrde.epita.fr/?p=spot.git;a=blob;f=wrap/python/tests/run.in – adl Mar 10 '12 at 13:06
0

To avoid writing many bash script wrappers, you can write one common wrapper script and create several symlinks to it. The script can check its name and take care of adding command-line arguments, etc.

Makefile.am:

TESTS = test-foo.sh test-bar.sh

Then e.g. a test-common.sh script:

test_name=`basename -s .sh $0`
case $test_name in
    'test-foo') ./my-tester.py foo
        ;;
    'test-foo') ./my-tester.py bar
        ;;
esac

For adding new tests, you would update test-common.sh and add a new symlink:

ln -s test-common.sh test-foo.sh
ln -s test-common.sh test-bar.sh
jeffa
  • 26
  • 3