mirror of
https://github.com/openai/codex.git
synced 2026-11-09 00:39:32 +00:00
fix: declare test path relative to $CARGO_MANIFEST_DIR (#8498)
This is another fix to prepare for Buck2. See #8496 for related changes. --- [//]: # (BEGIN SAPLING FOOTER) Stack created with [Sapling](https://sapling-scm.com). Best reviewed with [ReviewStack](https://reviewstack.dev/openai/codex/pull/8498). * __->__ #8498 * #8496
This commit is contained in:
1 parent
e61bae12e3
commit
38de0a1de4
1 file changed
+14
-7
@@ -8,7 +8,8 @@ use tempfile::tempdir;
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_apply_patch_scenarios() -> anyhow::Result<()> {
|
fn test_apply_patch_scenarios() -> anyhow::Result<()> {
|
||||||
for scenario in fs::read_dir("tests/fixtures/scenarios")? {
|
let scenarios_dir = Path::new(env!("CARGO_MANIFEST_DIR")).join("tests/fixtures/scenarios");
|
||||||
|
for scenario in fs::read_dir(scenarios_dir)? {
|
||||||
let scenario = scenario?;
|
let scenario = scenario?;
|
||||||
let path = scenario.path();
|
let path = scenario.path();
|
||||||
if path.is_dir() {
|
if path.is_dir() {
|
||||||
@@ -81,11 +82,15 @@ fn snapshot_dir_recursive(
|
|||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
let rel = stripped.to_path_buf();
|
let rel = stripped.to_path_buf();
|
||||||
let file_type = entry.file_type()?;
|
|
||||||
if file_type.is_dir() {
|
// Under Buck2, files in `__srcs` are often materialized as symlinks.
|
||||||
|
// Use `metadata()` (follows symlinks) so our fixture snapshots work
|
||||||
|
// under both Cargo and Buck2.
|
||||||
|
let metadata = fs::metadata(&path)?;
|
||||||
|
if metadata.is_dir() {
|
||||||
entries.insert(rel.clone(), Entry::Dir);
|
entries.insert(rel.clone(), Entry::Dir);
|
||||||
snapshot_dir_recursive(base, &path, entries)?;
|
snapshot_dir_recursive(base, &path, entries)?;
|
||||||
} else if file_type.is_file() {
|
} else if metadata.is_file() {
|
||||||
let contents = fs::read(&path)?;
|
let contents = fs::read(&path)?;
|
||||||
entries.insert(rel, Entry::File(contents));
|
entries.insert(rel, Entry::File(contents));
|
||||||
}
|
}
|
||||||
@@ -97,12 +102,14 @@ fn copy_dir_recursive(src: &Path, dst: &Path) -> anyhow::Result<()> {
|
|||||||
for entry in fs::read_dir(src)? {
|
for entry in fs::read_dir(src)? {
|
||||||
let entry = entry?;
|
let entry = entry?;
|
||||||
let path = entry.path();
|
let path = entry.path();
|
||||||
let file_type = entry.file_type()?;
|
|
||||||
let dest_path = dst.join(entry.file_name());
|
let dest_path = dst.join(entry.file_name());
|
||||||
if file_type.is_dir() {
|
|
||||||
|
// See note in `snapshot_dir_recursive` about Buck2 symlink trees.
|
||||||
|
let metadata = fs::metadata(&path)?;
|
||||||
|
if metadata.is_dir() {
|
||||||
fs::create_dir_all(&dest_path)?;
|
fs::create_dir_all(&dest_path)?;
|
||||||
copy_dir_recursive(&path, &dest_path)?;
|
copy_dir_recursive(&path, &dest_path)?;
|
||||||
} else if file_type.is_file() {
|
} else if metadata.is_file() {
|
||||||
if let Some(parent) = dest_path.parent() {
|
if let Some(parent) = dest_path.parent() {
|
||||||
fs::create_dir_all(parent)?;
|
fs::create_dir_all(parent)?;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user