Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Glob ignores Directory.current set on IOOverrides #52

Open
shyndman opened this issue Mar 30, 2021 · 1 comment
Open

Glob ignores Directory.current set on IOOverrides #52

shyndman opened this issue Mar 30, 2021 · 1 comment
Labels
status-blocked Blocked from making progress by another (referenced) issue

Comments

@shyndman
Copy link

shyndman commented Mar 30, 2021

Hi there,

Because Glob depends on the current working directory as determined by the path library, and path bypasses IOOverrides to determine this value (dart-lang/sdk#39796), libraries using glob become more difficult to test when using mocked filesystems.

@natebosch natebosch added the status-blocked Blocked from making progress by another (referenced) issue label Apr 1, 2021
@Giuspepe
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status-blocked Blocked from making progress by another (referenced) issue
Projects
None yet
Development

No branches or pull requests

3 participants