diff --git a/packages/flutter_test/lib/src/_goldens_io.dart b/packages/flutter_test/lib/src/_goldens_io.dart index 6cb88df459..eb029cd351 100644 --- a/packages/flutter_test/lib/src/_goldens_io.dart +++ b/packages/flutter_test/lib/src/_goldens_io.dart @@ -155,7 +155,7 @@ class LocalComparisonOutput { /// Returns the appropriate file for a given diff from a [ComparisonResult]. File getFailureFile(String failure, Uri golden, Uri basedir) { - final String fileName = golden.pathSegments[0]; + final String fileName = golden.pathSegments.last; final String testName = fileName.split(path.extension(fileName))[0] + '_' + failure diff --git a/packages/flutter_test/test/goldens_test.dart b/packages/flutter_test/test/goldens_test.dart index f85a2c90d2..512b8365c8 100644 --- a/packages/flutter_test/test/goldens_test.dart +++ b/packages/flutter_test/test/goldens_test.dart @@ -149,7 +149,7 @@ void main() { group('fails', () { - test('and generates correct output in the correct location', () async { + test('and generates correct output in the correct base location', () async { comparator = LocalFileComparator(Uri.parse('local_test.dart'), pathStyle: fs.path.style); await fs.file(fix('/golden.png')).writeAsBytes(_kColorFailurePngBytes); try { @@ -176,6 +176,35 @@ void main() { } }); + test('and generates correct output when files are in a subdirectory', () async { + comparator = LocalFileComparator(Uri.parse('local_test.dart'), pathStyle: fs.path.style); + fs.file(fix('subdir/golden.png')) + ..createSync(recursive:true) + ..writeAsBytes(_kColorFailurePngBytes); + try { + await doComparison('subdir/golden.png'); + fail('TestFailure expected but not thrown.'); + } on TestFailure catch (error) { + expect(error.message, contains('% diff detected')); + final io.File master = fs.file( + fix('/failures/golden_masterImage.png') + ); + final io.File test = fs.file( + fix('/failures/golden_testImage.png') + ); + final io.File isolated = fs.file( + fix('/failures/golden_isolatedDiff.png') + ); + final io.File masked = fs.file( + fix('/failures/golden_maskedDiff.png') + ); + expect(master.existsSync(), isTrue); + expect(test.existsSync(), isTrue); + expect(isolated.existsSync(), isTrue); + expect(masked.existsSync(), isTrue); + } + }); + test('when golden file does not exist', () async { try { await doComparison();