A modern, C++-native, test framework for unit-tests, TDD and BDD - using C++14, C++17 and later (C++11 support is in v2.x branch, and C++03 on the Catch1.x branch)
In catch_discover_tests function, the DL_PATHS opition is used to specify the directories of the dependent shared libraries. The specified paths are used in the function to setup the environment for (1) retrieving the list of test cases from the text executable and for (2) executing the tests.
With current implementation, given DL_PATHS is specified, the prepared execution environments are inconsistent between (1) and (2), and the order of the paths specified by the DL_PATHS for searching libraries is not respected as well.
This PR tweak the catch_discover_tests_impl function, so that the execution environments are made consistent and the order of the search paths specified by DL_PATHS are respected.
Detail
Current behavior
The code for modifing the execution environment for (1) is shown as below, where the original value of environment variable is discarded and its value is overwrited by the specified DL_PATHS.
The code for modifing the execution environment for (2) is shown as follows, the paths in the DL_PATHS are transformed to the perform the path_list_prepend command for each specified path in order, which resulting in the order of searching DL_PATHS being reversed, and follows the searching order of the original values from the environment.
For example, when running on Windows, the environment variable for searching dependent shared libraries is PATH (i.e. dl_paths_variable_name is setted to PATH).
Given
the orignal environment PATH=/path/to/dir/C;/path/to/dir/D, and
the specified option DL_PATHS=/path/to/dir/A;/path/to/dir/B
We could see that under the current implementation,
the modified environment for (1) is: PATH=/path/to/dir/A;/path/to/dir/B
the modified environment for (2) is: PATH=/path/to/dir/B;/path/to/dir/A;/path/to/dir/C;/path/to/dir/D
Which are inconsistent, and the specified order is not respected.
Proposed behavior
The code for (1) is modified such that the DL_PATHS is prepend before the original paths, instead of overwriting the original values.
The code for (2) has been modified so that the commands in environment_modifications follow a "first path, last prepend" order. This ensures that the finding procedure would first search the paths in DL_PATHS with the specified order, followed by the paths from the original environment.
Description
In
catch_discover_tests
function, theDL_PATHS
opition is used to specify the directories of the dependent shared libraries. The specified paths are used in the function to setup the environment for (1) retrieving the list of test cases from the text executable and for (2) executing the tests.With current implementation, given
DL_PATHS
is specified, the prepared execution environments are inconsistent between (1) and (2), and the order of the paths specified by theDL_PATHS
for searching libraries is not respected as well.This PR tweak the
catch_discover_tests_impl
function, so that the execution environments are made consistent and the order of the search paths specified byDL_PATHS
are respected.Detail
Current behavior
The code for modifing the execution environment for (1) is shown as below, where the original value of environment variable is discarded and its value is overwrited by the specified
DL_PATHS
.The code for modifing the execution environment for (2) is shown as follows, the paths in the
DL_PATHS
are transformed to the perform thepath_list_prepend
command for each specified path in order, which resulting in the order of searchingDL_PATHS
being reversed, and follows the searching order of the original values from the environment.For example, when running on Windows, the environment variable for searching dependent shared libraries is
PATH
(i.e.dl_paths_variable_name
is setted toPATH
).Given
PATH=/path/to/dir/C;/path/to/dir/D
, andDL_PATHS=/path/to/dir/A;/path/to/dir/B
We could see that under the current implementation,
PATH=/path/to/dir/A;/path/to/dir/B
PATH=/path/to/dir/B;/path/to/dir/A;/path/to/dir/C;/path/to/dir/D
Which are inconsistent, and the specified order is not respected.
Proposed behavior
The code for (1) is modified such that the
DL_PATHS
is prepend before the original paths, instead of overwriting the original values.The code for (2) has been modified so that the commands in
environment_modifications
follow a "first path, last prepend" order. This ensures that the finding procedure would first search the paths inDL_PATHS
with the specified order, followed by the paths from the original environment.For example, given that
PATH=/path/to/dir/C;/path/to/dir/D
, andDL_PATHS=/path/to/dir/A;/path/to/dir/B
With the proposed implementation, the modified environment for (1) and (2) becomes:
PATH=/path/to/dir/A;/path/to/dir/B;/path/to/dir/C;/path/to/dir/D
The paths order are respected and the execution environments are made consistent.