tests: Prefer the env var for finding test layouts
The builtin file path is embedded in the binary and subject to substitution, which makes it invalid when trying to build a .deb reproducibly. Out of the two solutions, it's easier to make the change here rather than customize .debu building not to run tests reproducibly.
This commit is contained in:
20
src/data.rs
20
src/data.rs
@ -746,13 +746,21 @@ mod tests {
|
|||||||
|
|
||||||
use ::logging::ProblemPanic;
|
use ::logging::ProblemPanic;
|
||||||
|
|
||||||
const THIS_FILE: &str = file!();
|
|
||||||
|
|
||||||
fn path_from_root(file: &'static str) -> PathBuf {
|
fn path_from_root(file: &'static str) -> PathBuf {
|
||||||
PathBuf::from(THIS_FILE)
|
let source_dir = env::var("SOURCE_DIR")
|
||||||
.parent().unwrap()
|
.map(PathBuf::from)
|
||||||
.parent().unwrap()
|
.unwrap_or_else(|e| {
|
||||||
.join(file)
|
if let env::VarError::NotPresent = e {
|
||||||
|
let this_file = file!();
|
||||||
|
PathBuf::from(this_file)
|
||||||
|
.parent().unwrap()
|
||||||
|
.parent().unwrap()
|
||||||
|
.into()
|
||||||
|
} else {
|
||||||
|
panic!("{:?}", e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
source_dir.join(file)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
Reference in New Issue
Block a user