Debian Codegraph @

tests/windows.rs

raw symbols SCIP
1 #![cfg(windows)]
2
3 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::{create_dirrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/create_dir()., metadatarust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/metadata()., read_linkrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/read_link()., read_to_stringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/read_to_string()., symlink_metadatarust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/symlink_metadata()., writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/write().};
4 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::osrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/::windows::fs::{symlink_dir, symlink_file};
5 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/::Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#;
6
7 use tempfilerust-analyzer cargo tempfile 3.27.0 crate/::TempDirrust-analyzer cargo tempfile 3.27.0 dir/TempDir#;
8
9 use cp_rrust-analyzer cargo cp_r 0.5.2 crate/::CopyOptionsrust-analyzer cargo cp_r 0.5.2 CopyOptions#;
10
11 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
12 fn copy_file_symlink() {
13 let tmp = TempDir::with_prefix("src").unwrap();
14 let src = tmp.path();
15 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!(src.join("target"), b"hello").unwrap();
16 symlink_file("target", src.join("link")).unwrap();
17
18 let dest_tmp = TempDir::with_prefix("dest").unwrap();
19 let dest = dest_tmp.path();
20 CopyOptions::new().copy_tree(src, dest).unwrap();
21
22 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(read_to_string(dest.join("link")).unwrap(), "hello");
23 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(read_link(dest.join("link")).unwrap(), Path::new("target"));
24 }
25
26 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
27 fn copy_dir_symlink() {
28 let tmp = TempDir::with_prefix("src").unwrap();
29 let src = tmp.path();
30 create_dir(src.join("target")).unwrap();
31 symlink_dir("target", src.join("link")).unwrap();
32 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!(
33 "source symlink target is {:?}",
34 read_link(src.join("link")).unwrap()
35 );
36
37 let dest_tmp = TempDir::with_prefix("dest").unwrap();
38 let dest = dest_tmp.path();
39 CopyOptions::new().copy_tree(&src, &dest).unwrap();
40 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!(
41 "dest symlink target is {:?}",
42 read_link(dest.join("link")).unwrap()
43 );
44
45 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(symlink_metadata(dest.join("link")).unwrap().is_symlink());
46 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(metadata(dest.join("link")).unwrap().is_dir());
47 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(read_link(dest.join("link")).unwrap(), Path::new("target"));
48 }