-
Notifications
You must be signed in to change notification settings - Fork 2
Link and copy source files
Since tests are executed out-of-source (in a separate directory than the test source file), files that are needed to run the test have to be soft linked or copied from the source directory into the execution directory. This can be done using the "link" and/or "copy" header specification.
For example, consider the test file working.vvt
:
#VVT: link : input.txt helper.py
import subprocess
subprocess.call( ['./helper.py','input.txt'] )
This test needs two files in order to run, input.txt
and helper.py
. The "link" specification in the header of the test causes those two files to be linked into the execution directory. Run this test by executing vvtest then look at the resulting execution directory:
s968057% ls -l TestResults.Darwin/working
total 40
-rw-r----- 1 rrdrake SANDIA\Domain Users 412 Jun 24 17:56 execute.log
lrwxr-x--- 1 rrdrake SANDIA\Domain Users 35 Jun 24 17:56 helper.py -> /Users/rrdrake/vvtdoc/ex2/helper.py
lrwxr-x--- 1 rrdrake SANDIA\Domain Users 35 Jun 24 17:56 input.txt -> /Users/rrdrake/vvtdoc/ex2/input.txt
-rw-r----- 1 rrdrake SANDIA\Domain Users 726 Jun 24 17:56 vvtest_util.py
lrwxr-x--- 1 rrdrake SANDIA\Domain Users 37 Jun 24 17:56 working.vvt -> /Users/rrdrake/vvtdoc/ex2/working.vvt
Notice the two test files plus the test source script is soft linked. The test output shows the action of copying/linking the files:
s968057% cat TestResults.Darwin/working/execute.log
Starting test: working
Directory : /Users/rrdrake/vvtdoc/ex2/TestResults.Darwin/working
Command : /usr/bin/env python working.vvt
Timeout : 3600
Cleaning execute directory...
Linking and copying working files...
ln -s /Users/rrdrake/vvtdoc/ex2/working.vvt working.vvt
ln -s /Users/rrdrake/vvtdoc/ex2/input.txt input.txt
ln -s /Users/rrdrake/vvtdoc/ex2/helper.py helper.py
the input file contents
The link and copy specifications can be repeated and mixed. For example if working.vvt
was
#VVT: link : helper.py
#VVT: copy : input.txt
import subprocess
subprocess.call( ['./helper.py','input.txt'] )
Then after running, the execution directory would look like this:
s968057% ls -l TestResults.Darwin/working
total 40
-rw-r----- 1 rrdrake SANDIA\Domain Users 412 Jun 24 18:22 execute.log
lrwxr-x--- 1 rrdrake SANDIA\Domain Users 35 Jun 24 18:22 helper.py -> /Users/rrdrake/vvtdoc/ex2/helper.py
-rw-r----- 1 rrdrake SANDIA\Domain Users 24 Jun 24 17:52 input.txt
-rw-r----- 1 rrdrake SANDIA\Domain Users 726 Jun 24 18:22 vvtest_util.py
lrwxr-x--- 1 rrdrake SANDIA\Domain Users 37 Jun 24 18:22 working.vvt -> /Users/rrdrake/vvtdoc/ex2/working.vvt
Notice input.txt
is not a soft link.
The syntax illustrated in the previous section is
#VVT: link (optional attributes) : file1 file2 ...
Note that this syntax and the following apply equally to "copy" instead of "link". The optional attributes are discussed in a separate chapter, but the relevant ones here are "testname", "platforms", "parameters", and "options".
If the file name in the test execution directory should differ from the one in the source, then use this syntax:
#VVT: link (rename) : srcname1, exename1 srcname2, exename2
This would put a link named "exename1" in the execution directory which pointed to "srcname1". Similarly "exename2" would point to "srcname2". If a copy was specified instead, then the "exename1" and "exename2" would be copies of the src files.
Also note that additional attributes can be placed inside the parentheses separated by commas, such as
#VVT: link (rename, parameters="np>1") : srcname, exename
The strings given for the source files can contain wild cards. Shell-like expansion is performed, also known as file glob'ing. This can be done both for linking working files as well as copying.
For example, suppose a test used more than one python file for its operation. Then the set of files could be linked using wildcards. Consider the test file working.vvt
:
#VVT: link : working_*.py
import working_stuff1
working_stuff1.foo()
Note the "link" directive uses wildcards. The working_stuff1.py
file:
import working_stuff2
def foo():
working_stuff2.bar()
And working_stuff2.py
:
import sys
def bar():
print ( 'hello from bar' )
When run, you would see both "working_stuff" files linked into the execution directory:
s968057% ls
working.vvt working_stuff1.py working_stuff2.py
s968057% vvtest
...
s968057% ls -l TestResults.iDarwin/working/
total 40
-rw-r----- 1 rrdrake rrdrake 441 Aug 6 10:49 execute.log
-rw-r----- 1 rrdrake rrdrake 1024 Aug 6 10:49 vvtest_util.py
lrwxr-x--- 1 rrdrake rrdrake 38 Aug 6 10:49 working.vvt -> /Users/rrdrake/vvtdoc/ex2b/working.vvt
lrwxr-x--- 1 rrdrake rrdrake 44 Aug 6 10:49 working_stuff1.py -> /Users/rrdrake/vvtdoc/ex2b/working_stuff1.py
lrwxr-x--- 1 rrdrake rrdrake 44 Aug 6 10:49 working_stuff2.py -> /Users/rrdrake/vvtdoc/ex2b/working_stuff2.py
s968057% grep hello TestResults.iDarwin/working/execute.log
hello from bar