Boost.build question: Adding a new unit-test rule
Hi. I'm working on a project where some of the unit test are very inconvenient to implement with CppUnit and Mock classes or stubs alone, but would be very simple to implement by having them print messages to standard output, pipe this to a log file and diff this against a reference file. I added the following to our Jamrules file (most of it is stolen from the standard unit-test rule and run action): rule unit-test-diff { local files = [ exe $(<) : $(2) : $(3) : $(4) : EXE ] ; type-DEPENDS test : $(files) ; local file ; for file in $(files) { run-and-diff $(file) ; } } actions run-and-diff { $(SHELL_SET)PATH=$(RUN_PATH) $(SHELL_EXPORT)PATH $(<) > $(<:D=:S=.log) diff $(<:S=.log) $(<:S=.ref) # diff $(<:D=:S=.log) $(<:D=:S=.ref) } This runs the unit test program, pipes the output to <targetname>.log and diffs agains <targetname>.ref. There is only one problem: I cannot get Boost.build to locate these files in the correct folder. The Jamfile for the unit test is located in the same folder as the unit test source code. This is the only natural place for the ref-file as well. The action above has three different alternatives for the actual diff operation. The first uses the full path of the executable, but replaces the last part of the file name with .log and .ref. This places them in the binary folder of the unit test program, which isn't not very convenient. The second strips away the path, but since the currect folder always is the project root (not the folder where the Jamfile is), this places the log and ref files on the project root, which is almost as bad as the first alternative. I also experimented briefly with :G but this has no effect as the file path did not seem to contain grist. One possible solution might be to add a path feature to the target and set this to the reference file name, but I'm not quite sure how to implement this for rules that are not part of a tools.jam-file I really need the unit test rule to place these files in the folder where the rest of the test source code is. Does anyone know how to do this? - Helge Penne
--- In Boost-Users@y..., "Helge Penne"
Hi. I'm working on a project where some of the unit test are very inconvenient to implement with CppUnit and Mock classes or stubs alone, but would be very simple to implement by having them print messages to standard output, pipe this to a log file and diff this against a reference file.
[...]
- Helge Penne
New Boost Test Library provides the convinient way to validate output vs. supplied pattern file. BTL is not yet in a main branch, but for the latest version you can checl unit_test_development brach in CVS. See output_test_stream_test.cpp for example. Gennadiy.
--- In Boost-Users@y..., "rogeeff"
--- In Boost-Users@y..., "Helge Penne"
wrote: Hi. I'm working on a project where some of the unit test are very inconvenient to implement with CppUnit and Mock classes or stubs alone, but would be very simple to implement by having them print messages to standard output, pipe this to a log file and diff this against a reference file.
[...]
- Helge Penne
New Boost Test Library provides the convinient way to validate output vs. supplied pattern file. BTL is not yet in a main branch, but for the latest version you can checl unit_test_development brach in CVS.
See output_test_stream_test.cpp for example.
Gennadiy.
Yes, the test stream is a nice class, but when you specify the pattern file, the file will be located in the current folder. When I use jam, the current folder will be the project root. This is not where the pattern file belongs, it belongs in the same folder as the test code. Putting the relativ path to the pattern file in the code for the test program itself is not very csatisfying, so you seem to have more or less the same type of problem that I had. My problem is therefore still unsolved. In its most basic sense, the problem is this: How can I make a jam rule know which folder the target's subproject is located in? Ideally, I would like know how to assign this folder to a variable inside the rule actions, so that the actions can reference files inside this folder. - Helge
participants (3)
-
Helge Penne
-
hpenne
-
rogeeff