@@ -43,7 +43,7 @@ void main() {
4343
4444 test (
4545 'uses the previous working directory if deleted' ,
46- currentDirHelper (() {
46+ withLocalCurrentDirectory (() {
4747 final temp = io.Directory .systemTemp.createTempSync ('path_test' );
4848 final tempPath = temp.resolveSymbolicLinksSync ();
4949 io.Directory .current = temp;
@@ -61,7 +61,8 @@ void main() {
6161 );
6262 });
6363
64- test ('registers changes to the working directory' , currentDirHelper (() {
64+ test ('registers changes to the working directory' ,
65+ withLocalCurrentDirectory (() {
6566 final dir = io.Directory .current.path;
6667 expect (path.absolute ('foo/bar' ), equals (path.join (dir, 'foo/bar' )));
6768 expect (
@@ -85,10 +86,8 @@ void main() {
8586 // [path.current] that has clobbered the root in the past.
8687 test (
8788 'absolute works on root working directory' ,
88- currentDirHelper (() {
89- io.sleep (const Duration (seconds: 2 ));
89+ withLocalCurrentDirectory (() {
9090 io.Directory .current = path.rootPrefix (path.current);
91- io.sleep (const Duration (seconds: 2 ));
9291
9392 expect (
9493 path.relative (path.absolute ('foo/bar' ), from: path.current),
@@ -110,7 +109,11 @@ void main() {
110109 );
111110}
112111
113- dynamic Function () currentDirHelper (dynamic Function () body) {
112+ /// Runs [body] in a zone with a local current working directory.
113+ ///
114+ /// Avoids clobbering the current working directory of the entire process
115+ /// when writing to it and reading it back through `dart:io` functions.
116+ R Function () withLocalCurrentDirectory <R >(R Function () body) {
114117 var savedCurrentDirectory = io.Directory .current;
115118 return () => io.IOOverrides .runZoned (body,
116119 getCurrentDirectory: () => savedCurrentDirectory,
0 commit comments