Expose generateTestBootstrap() as public API in test harness (#17290)
This will allow external tools that wrap our test harness to share the code that generates the test bootstrap. This change exposed an issue whereby the LocalGoldenFileComparator was being too strict in its URI handling, so this changes relaxes that constraint as well (and adds associated tests).
This commit is contained in:
@@ -125,8 +125,7 @@ class LocalFileComparator implements GoldenFileComparator {
|
||||
///
|
||||
/// The [testFile] URI must represent a file.
|
||||
LocalFileComparator(Uri testFile, {path.Style pathStyle})
|
||||
: assert(testFile.scheme == 'file'),
|
||||
basedir = _getBasedir(testFile, pathStyle),
|
||||
: basedir = _getBasedir(testFile, pathStyle),
|
||||
_path = _getPath(pathStyle);
|
||||
|
||||
static path.Context _getPath(path.Style style) {
|
||||
@@ -135,7 +134,9 @@ class LocalFileComparator implements GoldenFileComparator {
|
||||
|
||||
static Uri _getBasedir(Uri testFile, path.Style pathStyle) {
|
||||
final path.Context context = _getPath(pathStyle);
|
||||
return context.toUri(context.dirname(context.fromUri(testFile)) + context.separator);
|
||||
final String testFilePath = context.fromUri(testFile);
|
||||
final String testDirectoryPath = context.dirname(testFilePath);
|
||||
return context.toUri(testDirectoryPath + context.separator);
|
||||
}
|
||||
|
||||
/// The directory in which the test was loaded.
|
||||
|
||||
@@ -78,6 +78,11 @@ void main() {
|
||||
expect(comparator.basedir, fs.directory(fix('/foo/bar/')).uri);
|
||||
});
|
||||
|
||||
test('can be instantiated with uri that represents file in same folder', () {
|
||||
comparator = new LocalFileComparator(Uri.parse('foo_test.dart'), pathStyle: fs.path.style);
|
||||
expect(comparator.basedir, Uri.parse('./'));
|
||||
});
|
||||
|
||||
group('compare', () {
|
||||
Future<bool> doComparison([String golden = 'golden.png']) {
|
||||
final Uri uri = fs.file(fix(golden)).uri;
|
||||
@@ -101,6 +106,28 @@ void main() {
|
||||
final bool success = await doComparison('sub/foo.png');
|
||||
expect(success, isTrue);
|
||||
});
|
||||
|
||||
group('when comparator instantiated with uri that represents file in same folder', () {
|
||||
test('and golden file is in same folder as test', () async {
|
||||
fs.file(fix('/foo/bar/golden.png'))
|
||||
..createSync(recursive: true)
|
||||
..writeAsBytesSync(_kExpectedBytes);
|
||||
fs.currentDirectory = fix('/foo/bar');
|
||||
comparator = new LocalFileComparator(Uri.parse('local_test.dart'), pathStyle: fs.path.style);
|
||||
final bool success = await doComparison('golden.png');
|
||||
expect(success, isTrue);
|
||||
});
|
||||
|
||||
test('and golden file is in subfolder of test', () async {
|
||||
fs.file(fix('/foo/bar/baz/golden.png'))
|
||||
..createSync(recursive: true)
|
||||
..writeAsBytesSync(_kExpectedBytes);
|
||||
fs.currentDirectory = fix('/foo/bar');
|
||||
comparator = new LocalFileComparator(Uri.parse('local_test.dart'), pathStyle: fs.path.style);
|
||||
final bool success = await doComparison('baz/golden.png');
|
||||
expect(success, isTrue);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
group('fails', () {
|
||||
|
||||
Reference in New Issue
Block a user