File: fix-working-dir-for-tests.patch

package info (click to toggle)
rust-fslock 0.2.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 224 kB
  • sloc: makefile: 9
file content (65 lines) | stat: -rw-r--r-- 2,311 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
Index: fslock/src/test.rs
===================================================================
--- fslock.orig/src/test.rs
+++ fslock/src/test.rs
@@ -2,11 +2,23 @@ use crate::{Error, LockFile};
 use core::str;
 
 #[cfg(feature = "std")]
+fn make_testpath(filename: &str) -> String {
+     match option_env!("CARGO_TARGET_DIR") {
+         Some(target_dir) => {
+            let result = std::path::Path::new(target_dir).join(filename);
+            std::fs::create_dir_all(result.parent().unwrap()).unwrap();
+            result.into_os_string().into_string().unwrap()
+         }
+         None => filename.to_string()
+     }
+}
+
+#[cfg(feature = "std")]
 #[test]
 fn read_pid() -> Result<(), Error> {
     use std::fs::read_to_string;
 
-    let path = "testfiles/read_pid.lock";
+    let path = &make_testpath("testfiles/read_pid.lock");
     let mut file = LockFile::open(path)?;
     file.lock_with_pid()?;
 
@@ -25,7 +37,7 @@ fn read_pid() -> Result<(), Error> {
 fn try_read_pid() -> Result<(), Error> {
     use std::fs::read_to_string;
 
-    let path = "testfiles/try_read_pid.lock";
+    let path = &make_testpath("testfiles/try_read_pid.lock");
     let mut file = LockFile::open(path)?;
     assert!(file.try_lock_with_pid()?);
 
@@ -109,7 +121,7 @@ fn check_try_lock_with_pid_example(
 #[cfg(feature = "std")]
 #[test]
 fn other_process() -> Result<(), Error> {
-    let path = "testfiles/other_process.lock";
+    let path = &make_testpath("testfiles/other_process.lock");
     let mut file = LockFile::open(path)?;
     file.lock()?;
     check_try_lock_example(path, b"FAILURE\n")?;
@@ -123,7 +135,7 @@ fn other_process() -> Result<(), Error>
 fn other_process_pid() -> Result<(), Error> {
     use std::fs::read_to_string;
 
-    let path = "testfiles/other_process_pid.lock";
+    let path = &make_testpath("testfiles/other_process_pid.lock");
     let mut file = LockFile::open(path)?;
     assert!(file.try_lock_with_pid()?);
 
@@ -167,7 +179,7 @@ fn other_process_pid() -> Result<(), Err
 fn other_process_but_curr_reads() -> Result<(), Error> {
     use std::fs::read_to_string;
 
-    let path = "testfiles/other_process_but_curr_reads.lock";
+    let path = &make_testpath("testfiles/other_process_but_curr_reads.lock");
     let mut file = LockFile::open(path)?;
     file.lock()?;