Debian Codegraph @

debian/patches/fix-tests-permission-denied.diff

raw
1 Index: plotters-bitmap/src/bitmap/test.rs
2 ===================================================================
3 --- plotters-bitmap.orig/src/bitmap/test.rs
4 +++ plotters-bitmap/src/bitmap/test.rs
5 @@ -396,17 +396,24 @@ mod test {
6 use plotters::style::text_anchor::{HPos, Pos, VPos};
7 use std::fs;
8 use std::path::Path;
9 + use std::path::PathBuf;
10
11 - static DST_DIR: &str = "target/test/bitmap";
12 + fn get_dst_dir() -> PathBuf {
13 + if let Some(cargo_target_dir) = option_env!("CARGO_TARGET_DIR") {
14 + return Path::new(cargo_target_dir).join("bitmap");
15 + } else {
16 + return Path::new("target/test/bitmap").to_path_buf();
17 + }
18 + }
19
20 fn checked_save_file(name: &str, content: &[u8], w: u32, h: u32) {
21 /*
22 Please use the PNG file to manually verify the results.
23 */
24 assert!(content.iter().any(|x| *x != 0));
25 - fs::create_dir_all(DST_DIR).unwrap();
26 + fs::create_dir_all(get_dst_dir()).unwrap();
27 let file_name = format!("{}.png", name);
28 - let file_path = Path::new(DST_DIR).join(file_name);
29 + let file_path = get_dst_dir().join(file_name);
30 println!("{:?} created", file_path);
31 let img = ImageBuffer::<Rgb<u8>, &[u8]>::from_raw(w, h, content).unwrap();
32 img.save(&file_path).unwrap();