Open shyndman opened 3 years ago
I ran into the same problem, here is a minimum reproducible example:
import 'dart:io';
import 'package:glob/glob.dart';
import 'package:glob/list_local_fs.dart';
import 'package:path/path.dart';
import 'package:test/test.dart';
void main() {
test('IOOverrides should be respected', () {
final tempDir = Directory.systemTemp.createTempSync();
addTearDown(() => tempDir.deleteSync(recursive: true));
final files = [
'foo.txt',
'foo/bar/baz.txt',
].map((p) => File(join(tempDir.path, p)));
final filePaths = files.map((e) => e.path);
for (final file in files) {
file.createSync(recursive: true);
}
IOOverrides.runZoned(
() {
final fileList =
Directory.current.listSync(recursive: true).map((e) => e.path);
expect(fileList, containsAll(filePaths));
final glob = Glob('**');
final globFileList = glob.listSync().map((e) => e.path);
expect(globFileList, fileList);
},
getCurrentDirectory: () => tempDir,
);
});
}
If you replace glob.listSync()
with glob.listSync(root: Directory.current.path)
it works as expected.
Hi there,
Because
Glob
depends on the current working directory as determined by thepath
library, andpath
bypassesIOOverrides
to determine this value (https://github.com/dart-lang/sdk/issues/39796), libraries usingglob
become more difficult to test when using mocked filesystems.