[librsvg: 10/33] Remove fixture_path() now that there is no Cargo workspace




commit b8a8c3afc47b0f1f7b4f49307ecd6b5d8307da6d
Author: Federico Mena Quintero <federico gnome org>
Date:   Thu Oct 29 17:48:02 2020 -0600

    Remove fixture_path() now that there is no Cargo workspace
    
    ... and the test_resources macro generates the correct paths without a
    workspace.

 tests/src/errors.rs        |  6 ++----
 tests/src/loading_crash.rs |  6 +-----
 tests/src/reference.rs     |  6 +++---
 tests/src/render_crash.rs  |  6 +-----
 tests/src/utils.rs         | 26 +++-----------------------
 5 files changed, 10 insertions(+), 40 deletions(-)
---
diff --git a/tests/src/errors.rs b/tests/src/errors.rs
index e3a3cbbc..71327cf1 100644
--- a/tests/src/errors.rs
+++ b/tests/src/errors.rs
@@ -13,22 +13,20 @@
 use cairo;
 use librsvg::{CairoRenderer, Loader, LoadingError, RenderingError};
 
-use crate::utils::fixture_path;
-
 #[ignore]
 #[test]
 fn too_many_elements() {
     let name = "tests/fixtures/errors/515-too-many-elements.svgz";
 
     assert!(matches!(
-        Loader::new().read_path(fixture_path(name)),
+        Loader::new().read_path(name),
         Err(LoadingError::XmlParseError(_))
     ));
 }
 
 fn rendering_instancing_limit(name: &str) {
     let handle = Loader::new()
-        .read_path(fixture_path(name))
+        .read_path(name)
         .unwrap_or_else(|e| panic!("could not load: {}", e));
 
     let surface = cairo::ImageSurface::create(cairo::Format::ARgb32, 500, 500).unwrap();
diff --git a/tests/src/loading_crash.rs b/tests/src/loading_crash.rs
index 2c9dce1e..e053e322 100644
--- a/tests/src/loading_crash.rs
+++ b/tests/src/loading_crash.rs
@@ -8,12 +8,8 @@ use test_generator::test_resources;
 
 use librsvg::Loader;
 
-use crate::utils::fixture_path;
-
 #[test_resources("tests/fixtures/crash/*.svg")]
-fn loading_crash(name: &str) {
-    let path = fixture_path(name);
-
+fn loading_crash(path: &str) {
     // We just test for crashes during loading, and don't care about success/error.
     let _ = Loader::new().read_path(path);
 }
diff --git a/tests/src/reference.rs b/tests/src/reference.rs
index 72e99a1d..6dc47e59 100644
--- a/tests/src/reference.rs
+++ b/tests/src/reference.rs
@@ -17,7 +17,7 @@ use librsvg::{
 };
 use std::path::PathBuf;
 
-use crate::utils::{fixture_path, setup_font_map, setup_language};
+use crate::utils::{setup_font_map, setup_language};
 
 // The original reference images from the SVG1.1 test suite are at 72 DPI.
 const TEST_SUITE_DPI: f64 = 72.0;
@@ -35,11 +35,11 @@ const TEST_SUITE_DPI: f64 = 72.0;
 // offset.
 const FRAME_SIZE: i32 = 47;
 
-fn reference_test(name: &str) {
+fn reference_test(path: &str) {
     setup_language();
     setup_font_map();
 
-    let path = fixture_path(name);
+    let path = PathBuf::from(path);
     let path_base_name = path.file_stem().unwrap().to_string_lossy().to_owned();
     if path_base_name.starts_with("ignore") {
         return;
diff --git a/tests/src/render_crash.rs b/tests/src/render_crash.rs
index a02fb064..d0c8b42f 100644
--- a/tests/src/render_crash.rs
+++ b/tests/src/render_crash.rs
@@ -9,12 +9,8 @@ use test_generator::test_resources;
 use cairo;
 use librsvg::{CairoRenderer, Loader};
 
-use crate::utils::fixture_path;
-
 #[test_resources("tests/fixtures/render-crash/*.svg")]
-fn loading_crash(name: &str) {
-    let path = fixture_path(name);
-
+fn loading_crash(path: &str) {
     let handle = Loader::new()
         .read_path(path)
         .unwrap_or_else(|e| panic!("could not load: {}", e));
diff --git a/tests/src/utils.rs b/tests/src/utils.rs
index 1914c6c3..3892fc34 100644
--- a/tests/src/utils.rs
+++ b/tests/src/utils.rs
@@ -4,26 +4,8 @@ use glib::translate::*;
 use libc;
 use std::env;
 use std::ffi::CString;
-use std::path::PathBuf;
 use std::sync::Once;
 
-/// Given a filename from `test_generator::test_resources`, computes the correct fixture filename.
-///
-/// The `test_resources` procedural macro works by running a filename glob starting on
-/// the toplevel of the Cargo workspace.  However, when a test function gets run,
-/// its $cwd is the test crate's toplevel.  This function fixes the pathname generated
-/// by `test_resources` so that it has the correct path.
-pub fn fixture_path(filename_from_test_resources: &str) -> PathBuf {
-    let crate_toplevel = PathBuf::from(
-        env::var_os("CARGO_MANIFEST_DIR")
-            .expect(r#"CARGO_MANIFEST_DIR" is not set, please set it or run under "cargo test""#),
-    );
-
-    let workspace_toplevel = crate_toplevel.parent().unwrap();
-
-    workspace_toplevel.join(filename_from_test_resources)
-}
-
 #[cfg(have_pangoft2)]
 mod pango_ft2 {
     use super::*;
@@ -52,14 +34,12 @@ mod pango_ft2 {
         let config = fontconfig::FcConfigCreate();
 
         for path in &font_paths {
-            let path = fixture_path(path);
-            let path_str = path.to_str().unwrap();
-            let path_cstring = CString::new(path_str).unwrap();
+            let path_cstring = CString::new(*path).unwrap();
 
             if fontconfig::FcConfigAppFontAddFile(config, path_cstring.as_ptr() as *const _) == 0 {
                 panic!(
-                    "Could not load font file {:?} for tests; aborting",
-                    path_str
+                    "Could not load font file {} for tests; aborting",
+                    path,
                 );
             }
         }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]