Skip to content

Test source files

Richard R. Drake edited this page Jun 8, 2022 · 1 revision

Since the test execution occurs in a different directory than the test script itself, the files needed to execute the test must be copied into the execution directory, or accessed directly from the test source directory.

A test script file can specify files to copy from the execution directory to the source path using a #VVT: copy directive. For example, if the file input.xml is used by the test atest.vvt, then that test file could do this:

#VVT: copy : input.xml
import subprocess
subprocess.check_call( ['myapp','input.xml'] )

When vvtest runs, it copies input.xml into the test execution directory, changes to that directory, then executes the atest.vvt test script.

ews01212% ls
atest.vvt  input.xml

ews01212% vvtest
...
Finish date: Fri Dec 31 18:17:01 2021 (elapsed time 1s)
Test directory: TestResults.ceelan

ews01212% ls -l TestResults.ceelan/atest
total 12
lrwxrwxrwx 1 rrdrake rrdrake   34 Dec 31 18:17 atest.vvt -> /scratch/rrdrake/example/atest.vvt
-rw-r----- 1 rrdrake rrdrake  342 Dec 31 18:17 execute.log
-rw-r----- 1 rrdrake rrdrake   42 Dec 31 18:14 input.xml
-rw-r----- 1 rrdrake rrdrake 1091 Dec 31 18:17 vvtest_util.py
-rw-r----- 1 rrdrake rrdrake 1394 Dec 31 18:17 vvtest_util.sh

Soft linking source files

For more efficiency, a test can soft link files from the execution directory back to the source directory using the #VVT: link directive. For example, this test file

#VVT: link : input.txt other.dat
import subprocess
subprocess.check_call( ['myapp','input.xml','other.dat'] )

will soft link both of those files rather than copy them.

ews01212% ls -l TestResults.ceelan/atest
total 12
lrwxrwxrwx 1 rrdrake rrdrake   34 Dec 31 18:28 atest.vvt -> /scratch/rrdrake/example/atest.vvt
-rw-r----- 1 rrdrake rrdrake  383 Dec 31 18:28 execute.log
lrwxrwxrwx 1 rrdrake rrdrake   34 Dec 31 18:28 input.xml -> /scratch/rrdrake/example/input.xml
lrwxrwxrwx 1 rrdrake rrdrake   34 Dec 31 18:28 other.dat -> /scratch/rrdrake/example/other.dat
-rw-r----- 1 rrdrake rrdrake 1091 Dec 31 18:28 vvtest_util.py
-rw-r----- 1 rrdrake rrdrake 1394 Dec 31 18:28 vvtest_util.sh

Using the test source path

Of course, another way to access the test source files is to read them directly from the source location. For convenience, that location is stored in the vvtest_util.py file in a variable called "SRCDIR". For example,

import subprocess
import vvtest_util as vvt
subprocess.check_call( [ 'myapp', vvt.SRCDIR+'/input.xml' ] )

Note however, that using the SRCDIR has drawbacks. When writing and fixing tests, having the input files, the output files and the test script itself in one directory is more convenient. Also, test dependencies are made explicit when tracking them in the test file itself. Lastly, there is a feature of vvtest called "test extraction" that needs to know the files associated with each test.

Clone this wiki locally