Respect path order of DL_PATHS in catch_discover_tests #2878
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.