Move std::path unit tests to integration tests
This commit is contained in:
@@ -5,3 +5,4 @@
|
|||||||
extern crate test;
|
extern crate test;
|
||||||
|
|
||||||
mod hash;
|
mod hash;
|
||||||
|
mod path;
|
||||||
|
|||||||
114
library/std/benches/path.rs
Normal file
114
library/std/benches/path.rs
Normal file
@@ -0,0 +1,114 @@
|
|||||||
|
use core::hint::black_box;
|
||||||
|
use std::collections::{BTreeSet, HashSet};
|
||||||
|
use std::hash::{DefaultHasher, Hash, Hasher};
|
||||||
|
use std::path::*;
|
||||||
|
|
||||||
|
#[bench]
|
||||||
|
#[cfg_attr(miri, ignore)] // Miri isn't fast...
|
||||||
|
fn bench_path_cmp_fast_path_buf_sort(b: &mut test::Bencher) {
|
||||||
|
let prefix = "my/home";
|
||||||
|
let mut paths: Vec<_> =
|
||||||
|
(0..1000).map(|num| PathBuf::from(prefix).join(format!("file {num}.rs"))).collect();
|
||||||
|
|
||||||
|
paths.sort();
|
||||||
|
|
||||||
|
b.iter(|| {
|
||||||
|
black_box(paths.as_mut_slice()).sort_unstable();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
#[bench]
|
||||||
|
#[cfg_attr(miri, ignore)] // Miri isn't fast...
|
||||||
|
fn bench_path_cmp_fast_path_long(b: &mut test::Bencher) {
|
||||||
|
let prefix = "/my/home/is/my/castle/and/my/castle/has/a/rusty/workbench/";
|
||||||
|
let paths: Vec<_> =
|
||||||
|
(0..1000).map(|num| PathBuf::from(prefix).join(format!("file {num}.rs"))).collect();
|
||||||
|
|
||||||
|
let mut set = BTreeSet::new();
|
||||||
|
|
||||||
|
paths.iter().for_each(|p| {
|
||||||
|
set.insert(p.as_path());
|
||||||
|
});
|
||||||
|
|
||||||
|
b.iter(|| {
|
||||||
|
set.remove(paths[500].as_path());
|
||||||
|
set.insert(paths[500].as_path());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
#[bench]
|
||||||
|
#[cfg_attr(miri, ignore)] // Miri isn't fast...
|
||||||
|
fn bench_path_cmp_fast_path_short(b: &mut test::Bencher) {
|
||||||
|
let prefix = "my/home";
|
||||||
|
let paths: Vec<_> =
|
||||||
|
(0..1000).map(|num| PathBuf::from(prefix).join(format!("file {num}.rs"))).collect();
|
||||||
|
|
||||||
|
let mut set = BTreeSet::new();
|
||||||
|
|
||||||
|
paths.iter().for_each(|p| {
|
||||||
|
set.insert(p.as_path());
|
||||||
|
});
|
||||||
|
|
||||||
|
b.iter(|| {
|
||||||
|
set.remove(paths[500].as_path());
|
||||||
|
set.insert(paths[500].as_path());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
#[bench]
|
||||||
|
#[cfg_attr(miri, ignore)] // Miri isn't fast...
|
||||||
|
fn bench_path_hashset(b: &mut test::Bencher) {
|
||||||
|
let prefix = "/my/home/is/my/castle/and/my/castle/has/a/rusty/workbench/";
|
||||||
|
let paths: Vec<_> =
|
||||||
|
(0..1000).map(|num| PathBuf::from(prefix).join(format!("file {num}.rs"))).collect();
|
||||||
|
|
||||||
|
let mut set = HashSet::new();
|
||||||
|
|
||||||
|
paths.iter().for_each(|p| {
|
||||||
|
set.insert(p.as_path());
|
||||||
|
});
|
||||||
|
|
||||||
|
b.iter(|| {
|
||||||
|
set.remove(paths[500].as_path());
|
||||||
|
set.insert(black_box(paths[500].as_path()))
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
#[bench]
|
||||||
|
#[cfg_attr(miri, ignore)] // Miri isn't fast...
|
||||||
|
fn bench_path_hashset_miss(b: &mut test::Bencher) {
|
||||||
|
let prefix = "/my/home/is/my/castle/and/my/castle/has/a/rusty/workbench/";
|
||||||
|
let paths: Vec<_> =
|
||||||
|
(0..1000).map(|num| PathBuf::from(prefix).join(format!("file {num}.rs"))).collect();
|
||||||
|
|
||||||
|
let mut set = HashSet::new();
|
||||||
|
|
||||||
|
paths.iter().for_each(|p| {
|
||||||
|
set.insert(p.as_path());
|
||||||
|
});
|
||||||
|
|
||||||
|
let probe = PathBuf::from(prefix).join("other");
|
||||||
|
|
||||||
|
b.iter(|| set.remove(black_box(probe.as_path())));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[bench]
|
||||||
|
fn bench_hash_path_short(b: &mut test::Bencher) {
|
||||||
|
let mut hasher = DefaultHasher::new();
|
||||||
|
let path = Path::new("explorer.exe");
|
||||||
|
|
||||||
|
b.iter(|| black_box(path).hash(&mut hasher));
|
||||||
|
|
||||||
|
black_box(hasher.finish());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[bench]
|
||||||
|
fn bench_hash_path_long(b: &mut test::Bencher) {
|
||||||
|
let mut hasher = DefaultHasher::new();
|
||||||
|
let path =
|
||||||
|
Path::new("/aaaaa/aaaaaa/./../aaaaaaaa/bbbbbbbbbbbbb/ccccccccccc/ddddddddd/eeeeeee.fff");
|
||||||
|
|
||||||
|
b.iter(|| black_box(path).hash(&mut hasher));
|
||||||
|
|
||||||
|
black_box(hasher.finish());
|
||||||
|
}
|
||||||
@@ -67,9 +67,6 @@
|
|||||||
#![stable(feature = "rust1", since = "1.0.0")]
|
#![stable(feature = "rust1", since = "1.0.0")]
|
||||||
#![deny(unsafe_op_in_unsafe_fn)]
|
#![deny(unsafe_op_in_unsafe_fn)]
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests;
|
|
||||||
|
|
||||||
use core::clone::CloneToUninit;
|
use core::clone::CloneToUninit;
|
||||||
|
|
||||||
use crate::borrow::{Borrow, Cow};
|
use crate::borrow::{Borrow, Cow};
|
||||||
|
|||||||
@@ -1,10 +1,19 @@
|
|||||||
use core::hint::black_box;
|
#![feature(
|
||||||
|
clone_to_uninit,
|
||||||
|
path_add_extension,
|
||||||
|
path_file_prefix,
|
||||||
|
maybe_uninit_slice,
|
||||||
|
os_string_pathbuf_leak
|
||||||
|
)]
|
||||||
|
|
||||||
use super::*;
|
use std::clone::CloneToUninit;
|
||||||
use crate::collections::{BTreeSet, HashSet};
|
use std::ffi::OsStr;
|
||||||
use crate::hash::DefaultHasher;
|
use std::hash::{DefaultHasher, Hash, Hasher};
|
||||||
use crate::mem::MaybeUninit;
|
use std::mem::MaybeUninit;
|
||||||
use crate::ptr;
|
use std::path::*;
|
||||||
|
use std::ptr;
|
||||||
|
use std::rc::Rc;
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
#[allow(unknown_lints, unused_macro_rules)]
|
#[allow(unknown_lints, unused_macro_rules)]
|
||||||
macro_rules! t (
|
macro_rules! t (
|
||||||
@@ -110,7 +119,7 @@ macro_rules! t (
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn into() {
|
fn into() {
|
||||||
use crate::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
|
||||||
let static_path = Path::new("/home/foo");
|
let static_path = Path::new("/home/foo");
|
||||||
let static_cow_path: Cow<'static, Path> = static_path.into();
|
let static_cow_path: Cow<'static, Path> = static_path.into();
|
||||||
@@ -1525,7 +1534,7 @@ pub fn test_with_added_extension() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_eq_receivers() {
|
fn test_eq_receivers() {
|
||||||
use crate::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
|
||||||
let borrowed: &Path = Path::new("foo/bar");
|
let borrowed: &Path = Path::new("foo/bar");
|
||||||
let mut owned: PathBuf = PathBuf::new();
|
let mut owned: PathBuf = PathBuf::new();
|
||||||
@@ -1550,7 +1559,7 @@ fn test_eq_receivers() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
pub fn test_compare() {
|
pub fn test_compare() {
|
||||||
use crate::hash::{DefaultHasher, Hash, Hasher};
|
use std::hash::{DefaultHasher, Hash, Hasher};
|
||||||
|
|
||||||
fn hash<T: Hash>(t: T) -> u64 {
|
fn hash<T: Hash>(t: T) -> u64 {
|
||||||
let mut s = DefaultHasher::new();
|
let mut s = DefaultHasher::new();
|
||||||
@@ -1867,12 +1876,12 @@ fn test_ord() {
|
|||||||
#[test]
|
#[test]
|
||||||
#[cfg(any(unix, target_os = "wasi"))]
|
#[cfg(any(unix, target_os = "wasi"))]
|
||||||
fn test_unix_absolute() {
|
fn test_unix_absolute() {
|
||||||
use crate::path::absolute;
|
use std::path::absolute;
|
||||||
|
|
||||||
assert!(absolute("").is_err());
|
assert!(absolute("").is_err());
|
||||||
|
|
||||||
let relative = "a/b";
|
let relative = "a/b";
|
||||||
let mut expected = crate::env::current_dir().unwrap();
|
let mut expected = std::env::current_dir().unwrap();
|
||||||
expected.push(relative);
|
expected.push(relative);
|
||||||
assert_eq!(absolute(relative).unwrap().as_os_str(), expected.as_os_str());
|
assert_eq!(absolute(relative).unwrap().as_os_str(), expected.as_os_str());
|
||||||
|
|
||||||
@@ -1888,7 +1897,7 @@ fn test_unix_absolute() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Test leading `.` and `..` components
|
// Test leading `.` and `..` components
|
||||||
let curdir = crate::env::current_dir().unwrap();
|
let curdir = std::env::current_dir().unwrap();
|
||||||
assert_eq!(absolute("./a").unwrap().as_os_str(), curdir.join("a").as_os_str());
|
assert_eq!(absolute("./a").unwrap().as_os_str(), curdir.join("a").as_os_str());
|
||||||
assert_eq!(absolute("../a").unwrap().as_os_str(), curdir.join("../a").as_os_str()); // return /pwd/../a
|
assert_eq!(absolute("../a").unwrap().as_os_str(), curdir.join("../a").as_os_str()); // return /pwd/../a
|
||||||
}
|
}
|
||||||
@@ -1896,12 +1905,12 @@ fn test_unix_absolute() {
|
|||||||
#[test]
|
#[test]
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
fn test_windows_absolute() {
|
fn test_windows_absolute() {
|
||||||
use crate::path::absolute;
|
use std::path::absolute;
|
||||||
// An empty path is an error.
|
// An empty path is an error.
|
||||||
assert!(absolute("").is_err());
|
assert!(absolute("").is_err());
|
||||||
|
|
||||||
let relative = r"a\b";
|
let relative = r"a\b";
|
||||||
let mut expected = crate::env::current_dir().unwrap();
|
let mut expected = std::env::current_dir().unwrap();
|
||||||
expected.push(relative);
|
expected.push(relative);
|
||||||
assert_eq!(absolute(relative).unwrap().as_os_str(), expected.as_os_str());
|
assert_eq!(absolute(relative).unwrap().as_os_str(), expected.as_os_str());
|
||||||
|
|
||||||
@@ -1953,116 +1962,6 @@ fn test_extension_path_sep_alternate() {
|
|||||||
assert_eq!(path, Path::new("path/to/file.d\\test"));
|
assert_eq!(path, Path::new("path/to/file.d\\test"));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[bench]
|
|
||||||
#[cfg_attr(miri, ignore)] // Miri isn't fast...
|
|
||||||
fn bench_path_cmp_fast_path_buf_sort(b: &mut test::Bencher) {
|
|
||||||
let prefix = "my/home";
|
|
||||||
let mut paths: Vec<_> =
|
|
||||||
(0..1000).map(|num| PathBuf::from(prefix).join(format!("file {num}.rs"))).collect();
|
|
||||||
|
|
||||||
paths.sort();
|
|
||||||
|
|
||||||
b.iter(|| {
|
|
||||||
black_box(paths.as_mut_slice()).sort_unstable();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
#[bench]
|
|
||||||
#[cfg_attr(miri, ignore)] // Miri isn't fast...
|
|
||||||
fn bench_path_cmp_fast_path_long(b: &mut test::Bencher) {
|
|
||||||
let prefix = "/my/home/is/my/castle/and/my/castle/has/a/rusty/workbench/";
|
|
||||||
let paths: Vec<_> =
|
|
||||||
(0..1000).map(|num| PathBuf::from(prefix).join(format!("file {num}.rs"))).collect();
|
|
||||||
|
|
||||||
let mut set = BTreeSet::new();
|
|
||||||
|
|
||||||
paths.iter().for_each(|p| {
|
|
||||||
set.insert(p.as_path());
|
|
||||||
});
|
|
||||||
|
|
||||||
b.iter(|| {
|
|
||||||
set.remove(paths[500].as_path());
|
|
||||||
set.insert(paths[500].as_path());
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
#[bench]
|
|
||||||
#[cfg_attr(miri, ignore)] // Miri isn't fast...
|
|
||||||
fn bench_path_cmp_fast_path_short(b: &mut test::Bencher) {
|
|
||||||
let prefix = "my/home";
|
|
||||||
let paths: Vec<_> =
|
|
||||||
(0..1000).map(|num| PathBuf::from(prefix).join(format!("file {num}.rs"))).collect();
|
|
||||||
|
|
||||||
let mut set = BTreeSet::new();
|
|
||||||
|
|
||||||
paths.iter().for_each(|p| {
|
|
||||||
set.insert(p.as_path());
|
|
||||||
});
|
|
||||||
|
|
||||||
b.iter(|| {
|
|
||||||
set.remove(paths[500].as_path());
|
|
||||||
set.insert(paths[500].as_path());
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
#[bench]
|
|
||||||
#[cfg_attr(miri, ignore)] // Miri isn't fast...
|
|
||||||
fn bench_path_hashset(b: &mut test::Bencher) {
|
|
||||||
let prefix = "/my/home/is/my/castle/and/my/castle/has/a/rusty/workbench/";
|
|
||||||
let paths: Vec<_> =
|
|
||||||
(0..1000).map(|num| PathBuf::from(prefix).join(format!("file {num}.rs"))).collect();
|
|
||||||
|
|
||||||
let mut set = HashSet::new();
|
|
||||||
|
|
||||||
paths.iter().for_each(|p| {
|
|
||||||
set.insert(p.as_path());
|
|
||||||
});
|
|
||||||
|
|
||||||
b.iter(|| {
|
|
||||||
set.remove(paths[500].as_path());
|
|
||||||
set.insert(black_box(paths[500].as_path()))
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
#[bench]
|
|
||||||
#[cfg_attr(miri, ignore)] // Miri isn't fast...
|
|
||||||
fn bench_path_hashset_miss(b: &mut test::Bencher) {
|
|
||||||
let prefix = "/my/home/is/my/castle/and/my/castle/has/a/rusty/workbench/";
|
|
||||||
let paths: Vec<_> =
|
|
||||||
(0..1000).map(|num| PathBuf::from(prefix).join(format!("file {num}.rs"))).collect();
|
|
||||||
|
|
||||||
let mut set = HashSet::new();
|
|
||||||
|
|
||||||
paths.iter().for_each(|p| {
|
|
||||||
set.insert(p.as_path());
|
|
||||||
});
|
|
||||||
|
|
||||||
let probe = PathBuf::from(prefix).join("other");
|
|
||||||
|
|
||||||
b.iter(|| set.remove(black_box(probe.as_path())));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[bench]
|
|
||||||
fn bench_hash_path_short(b: &mut test::Bencher) {
|
|
||||||
let mut hasher = DefaultHasher::new();
|
|
||||||
let path = Path::new("explorer.exe");
|
|
||||||
|
|
||||||
b.iter(|| black_box(path).hash(&mut hasher));
|
|
||||||
|
|
||||||
black_box(hasher.finish());
|
|
||||||
}
|
|
||||||
|
|
||||||
#[bench]
|
|
||||||
fn bench_hash_path_long(b: &mut test::Bencher) {
|
|
||||||
let mut hasher = DefaultHasher::new();
|
|
||||||
let path =
|
|
||||||
Path::new("/aaaaa/aaaaaa/./../aaaaaaaa/bbbbbbbbbbbbb/ccccccccccc/ddddddddd/eeeeeee.fff");
|
|
||||||
|
|
||||||
b.iter(|| black_box(path).hash(&mut hasher));
|
|
||||||
|
|
||||||
black_box(hasher.finish());
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn clone_to_uninit() {
|
fn clone_to_uninit() {
|
||||||
let a = Path::new("hello.txt");
|
let a = Path::new("hello.txt");
|
||||||
Reference in New Issue
Block a user