Skip to content

Commit f6d0a9f

Browse files
committed
Add missing tests
1 parent 0d96462 commit f6d0a9f

File tree

1 file changed

+135
-0
lines changed

1 file changed

+135
-0
lines changed

scope/src/doctor/check.rs

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,4 +1040,139 @@ pub(crate) mod tests {
10401040
.await;
10411041
assert!(res.is_ok());
10421042
}
1043+
1044+
#[tokio::test]
1045+
async fn test_glob_walker_update_path_honors_tilde_paths() {
1046+
let mut file_system = MockFileSystem::new();
1047+
let mut file_cache = MockFileCache::new();
1048+
1049+
file_cache
1050+
.expect_update_cache_entry()
1051+
.once()
1052+
.with(
1053+
predicate::eq("group_name".to_string()),
1054+
predicate::eq(Path::new("/Users/first.last/path/foo.txt")),
1055+
)
1056+
.returning(|_, _| Ok(()));
1057+
1058+
file_system
1059+
.expect_find_files()
1060+
.once()
1061+
// this is what should be used
1062+
// .with(predicate::eq("/Users/first.last/path/*.txt"))
1063+
// this is the current incorrect behavior
1064+
.with(predicate::eq("/foo/root/~/path/*.txt"))
1065+
.returning(|_| Ok(vec![PathBuf::from("/Users/first.last/path/foo.txt")]));
1066+
1067+
let walker = DefaultGlobWalker {
1068+
file_system: Box::new(file_system),
1069+
};
1070+
1071+
let res = walker
1072+
.update_cache(
1073+
Path::new("/foo/root"),
1074+
&["~/path/*.txt".to_string()],
1075+
"group_name",
1076+
Arc::new(file_cache),
1077+
)
1078+
.await;
1079+
assert!(res.is_ok());
1080+
}
1081+
1082+
#[tokio::test]
1083+
async fn test_glob_walker_update_path_honors_relative_paths() {
1084+
// I can make an argument that we should toss this test
1085+
// and say that the correct thing to do is use **/path/*.txt
1086+
let mut file_system = MockFileSystem::new();
1087+
let mut file_cache = MockFileCache::new();
1088+
1089+
file_cache
1090+
.expect_update_cache_entry()
1091+
.once()
1092+
.with(
1093+
predicate::eq("group_name".to_string()),
1094+
predicate::eq(Path::new("/foo/path/foo.txt")),
1095+
)
1096+
.returning(|_, _| Ok(()));
1097+
1098+
file_system
1099+
.expect_find_files()
1100+
.once()
1101+
//glob will error on relative paths! This is wrong!
1102+
.with(predicate::eq("/foo/root/../path/*.txt"))
1103+
// this is the correct expectation
1104+
// .with(predicate::eq("/foo/path/*.txt"))
1105+
.returning(|_| Ok(vec![PathBuf::from("/foo/path/foo.txt")]));
1106+
1107+
let walker = DefaultGlobWalker {
1108+
file_system: Box::new(file_system),
1109+
};
1110+
1111+
let res = walker
1112+
.update_cache(
1113+
Path::new("/foo/root"),
1114+
&["../path/*.txt".to_string()],
1115+
"group_name",
1116+
Arc::new(file_cache),
1117+
)
1118+
.await;
1119+
assert!(res.is_ok());
1120+
}
1121+
1122+
mod test_make_absolute {
1123+
use std::path;
1124+
1125+
use crate::doctor::check::make_absolute;
1126+
1127+
use super::*;
1128+
1129+
#[test]
1130+
fn filename_gets_preprended_with_basepath() {
1131+
let base_dir = Path::new("/Users/first.last/path/to/project");
1132+
let glob = "foo.txt".to_string();
1133+
1134+
let actual = make_absolute(base_dir, &glob);
1135+
assert_eq!("/Users/first.last/path/to/project/foo.txt", &actual)
1136+
}
1137+
1138+
#[test]
1139+
fn wildcard_does_not_get_replaced() {
1140+
let base_dir = Path::new("/Users/first.last/path/to/project");
1141+
let glob = "*.txt".to_string();
1142+
1143+
let actual = make_absolute(base_dir, &glob);
1144+
assert_eq!("/Users/first.last/path/to/project/*.txt", &actual)
1145+
}
1146+
1147+
#[test]
1148+
fn path_from_root_does_not_get_replaced() {
1149+
let base_dir = Path::new("/Users/first.last/path/to/project");
1150+
let glob = "/etc/project/foo.txt".to_string();
1151+
1152+
let actual = make_absolute(base_dir, &glob);
1153+
assert_eq!("/etc/project/foo.txt", &actual)
1154+
}
1155+
1156+
#[test]
1157+
fn relative_paths_are_not_resolved() {
1158+
let base_dir = Path::new("/Users/first.last/path/to/project");
1159+
let glob = "../foo.txt".to_string();
1160+
1161+
let actual = make_absolute(base_dir, &glob);
1162+
assert_eq!("/Users/first.last/path/to/project/../foo.txt", &actual)
1163+
}
1164+
1165+
#[test]
1166+
fn tilde_resolves() {
1167+
let base_dir = Path::new("/Users/first.last/path/to/project");
1168+
let glob = "~/foo.txt".to_string();
1169+
1170+
let actual = make_absolute(base_dir, &glob);
1171+
// we want this to be equal
1172+
assert_ne!("/Users/first.last/path/foo.txt", &actual);
1173+
// assert_eq!("/Users/first.last/path/foo.txt", &actual);
1174+
// current, erroneous, behavior
1175+
assert_eq!("/Users/first.last/path/to/project/~/foo.txt", &actual)
1176+
}
1177+
}
10431178
}

0 commit comments

Comments
 (0)