@@ -872,3 +872,37 @@ fn reopen_fd() {
872
872
let tmpdir2 = check ! ( cap_std:: fs:: Dir :: reopen_dir( & tmpdir. as_filelike( ) ) ) ;
873
873
assert ! ( tmpdir2. exists( "subdir" ) ) ;
874
874
}
875
+
876
+ #[ test]
877
+ fn metadata_created ( ) {
878
+ let tmpdir = tmpdir ( ) ;
879
+ check ! ( tmpdir. create_dir( "dir" ) ) ;
880
+ let dir = check ! ( tmpdir. open_dir( "dir" ) ) ;
881
+ let file = check ! ( dir. create( "file" ) ) ;
882
+
883
+ let cap_std_dir = check ! ( dir. dir_metadata( ) ) ;
884
+ let cap_std_file = check ! ( file. metadata( ) ) ;
885
+ let cap_std_dir_entry = {
886
+ let mut entries = check ! ( dir. entries( ) ) ;
887
+ let entry = check ! ( entries. next( ) . unwrap( ) ) ;
888
+ assert_eq ! ( entry. file_name( ) , "file" ) ;
889
+ assert ! ( entries. next( ) . is_none( ) , "unexpected dir entry" ) ;
890
+ check ! ( entry. metadata( ) )
891
+ } ;
892
+
893
+ let std_dir = check ! ( dir. into_std_file( ) . metadata( ) ) ;
894
+ let std_file = check ! ( file. into_std( ) . metadata( ) ) ;
895
+
896
+ // If the standard library supports file creation times, then cap-std
897
+ // should too.
898
+ if let Ok ( expected) = std_dir. created ( ) {
899
+ println ! ( "std::fs supports file created times" ) ;
900
+ assert_eq ! ( expected, check!( cap_std_dir. created( ) ) . into_std( ) ) ;
901
+ } else {
902
+ println ! ( "std::fs doesn't support file created times" ) ;
903
+ }
904
+ if let Ok ( expected) = std_file. created ( ) {
905
+ assert_eq ! ( expected, check!( cap_std_file. created( ) ) . into_std( ) ) ;
906
+ assert_eq ! ( expected, check!( cap_std_dir_entry. created( ) ) . into_std( ) ) ;
907
+ }
908
+ }
0 commit comments