[librsvg: 1/2] Remove the need to set OUT_DIR in order to run 'cargo test'
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 1/2] Remove the need to set OUT_DIR in order to run 'cargo test'
- Date: Mon, 26 Oct 2020 16:02:44 +0000 (UTC)
commit 5b653a5a72cb667087e7afe82bb2f5a4fc7ea262
Author: Sven Neumann <sven svenfoo org>
Date: Sun Oct 25 15:43:46 2020 +0100
Remove the need to set OUT_DIR in order to run 'cargo test'
If OUT_DIR is not set, a folder in the temporary directory as
determined by std::env::temp_dir() will be used.
rsvg_internals/src/test_utils.rs | 19 ++++++++++++-------
1 file changed, 12 insertions(+), 7 deletions(-)
---
diff --git a/rsvg_internals/src/test_utils.rs b/rsvg_internals/src/test_utils.rs
index 065ace1b..5b071eda 100644
--- a/rsvg_internals/src/test_utils.rs
+++ b/rsvg_internals/src/test_utils.rs
@@ -45,17 +45,22 @@ impl Deviation for Diff {
}
}
-/// Creates a directory from the `OUT_DIR` environment variable and returns its path.
+/// Creates a directory for test output and returns its path.
+///
+/// The location for the output directory is taken from the `OUT_DIR` environment
+/// variable if that is set. Otherwise std::env::temp_dir() will be used, which is
+/// a platform dependent location for temporary files.
///
/// # Panics
///
-/// Will panic if the `OUT_DIR` environment variable is not set. Normally this is set
-/// by the continuous integration scripts or the build scripts that run the test suite.
+/// Will panic if the output directory can not be created.
pub fn output_dir() -> PathBuf {
- let path = PathBuf::from(
- env::var_os("OUT_DIR")
- .expect(r#"OUT_DIR is not set, please set it to a directory where the test suite can write its
output"#),
- );
+ let tempdir = || {
+ let mut path = env::temp_dir();
+ path.push("rsvg-test-output");
+ path
+ };
+ let path = env::var_os("OUT_DIR").map_or_else(tempdir, PathBuf::from);
fs::create_dir_all(&path).expect("could not create output directory for tests");
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]