@@ -8,7 +8,8 @@ use tempfile::tempdir;
88
99#[ test]
1010fn test_apply_patch_scenarios ( ) -> anyhow:: Result < ( ) > {
11- for scenario in fs:: read_dir ( "tests/fixtures/scenarios" ) ? {
11+ let scenarios_dir = Path :: new ( env ! ( "CARGO_MANIFEST_DIR" ) ) . join ( "tests/fixtures/scenarios" ) ;
12+ for scenario in fs:: read_dir ( scenarios_dir) ? {
1213 let scenario = scenario?;
1314 let path = scenario. path ( ) ;
1415 if path. is_dir ( ) {
@@ -81,11 +82,15 @@ fn snapshot_dir_recursive(
8182 continue ;
8283 } ;
8384 let rel = stripped. to_path_buf ( ) ;
84- let file_type = entry. file_type ( ) ?;
85- if file_type. is_dir ( ) {
85+
86+ // Under Buck2, files in `__srcs` are often materialized as symlinks.
87+ // Use `metadata()` (follows symlinks) so our fixture snapshots work
88+ // under both Cargo and Buck2.
89+ let metadata = fs:: metadata ( & path) ?;
90+ if metadata. is_dir ( ) {
8691 entries. insert ( rel. clone ( ) , Entry :: Dir ) ;
8792 snapshot_dir_recursive ( base, & path, entries) ?;
88- } else if file_type . is_file ( ) {
93+ } else if metadata . is_file ( ) {
8994 let contents = fs:: read ( & path) ?;
9095 entries. insert ( rel, Entry :: File ( contents) ) ;
9196 }
@@ -97,12 +102,14 @@ fn copy_dir_recursive(src: &Path, dst: &Path) -> anyhow::Result<()> {
97102 for entry in fs:: read_dir ( src) ? {
98103 let entry = entry?;
99104 let path = entry. path ( ) ;
100- let file_type = entry. file_type ( ) ?;
101105 let dest_path = dst. join ( entry. file_name ( ) ) ;
102- if file_type. is_dir ( ) {
106+
107+ // See note in `snapshot_dir_recursive` about Buck2 symlink trees.
108+ let metadata = fs:: metadata ( & path) ?;
109+ if metadata. is_dir ( ) {
103110 fs:: create_dir_all ( & dest_path) ?;
104111 copy_dir_recursive ( & path, & dest_path) ?;
105- } else if file_type . is_file ( ) {
112+ } else if metadata . is_file ( ) {
106113 if let Some ( parent) = dest_path. parent ( ) {
107114 fs:: create_dir_all ( parent) ?;
108115 }
0 commit comments