diff --git a/generator/test/error_test.dart b/generator/test/error_test.dart index fdd477f1b5..5f4898fb27 100644 --- a/generator/test/error_test.dart +++ b/generator/test/error_test.dart @@ -15,7 +15,7 @@ void main() { (e) => e.format().trim(), 'format()', myersDiff( - (await File(path.join(directory, outputFile)).readAsString()).trim(), + (await File(path.join(directory, outputFile)).readFileAsErrorFormattedString()).trim(), ), ), ), diff --git a/generator/test/info_test.dart b/generator/test/info_test.dart index 45b8ee8640..c0573a82b7 100644 --- a/generator/test/info_test.dart +++ b/generator/test/info_test.dart @@ -1,4 +1,7 @@ +import 'dart:io'; + import 'package:build_test/build_test.dart'; +import 'package:path/path.dart' as path; import 'package:realm_generator/realm_generator.dart'; import 'package:test/test.dart'; import 'test_util.dart'; @@ -25,8 +28,8 @@ void main() { ); expect( - sb.toString(), - await readFileAsErrorFormattedString(directory, outputFile), + sb.toString().trim(), + (await File(path.join(directory, outputFile)).readFileAsErrorFormattedString()).trim(), ); }); }); diff --git a/generator/test/test_util.dart b/generator/test/test_util.dart index eeb066f0da..d609b743bd 100644 --- a/generator/test/test_util.dart +++ b/generator/test/test_util.dart @@ -189,16 +189,17 @@ Future readFileAsDartFormattedString(String path) async { return _stringReplacements(content); } -Future readFileAsErrorFormattedString(String directoryName, String outputFilePath) async { - var file = File(_path.join(Directory.current.path, '$directoryName/$outputFilePath')); - String content = await file.readAsString(encoding: utf8); - if (Platform.isWindows) { - var macToWinSymbols = {'╷': ',', '━': '=', '╵': '\'', '│': '|', '─': '-', '┌': ',', '└': '\''}; - macToWinSymbols.forEach((key, value) { - content = content.replaceAll(key, value); - }); +extension FileEx on File { + Future readFileAsErrorFormattedString() async { + var content = await readAsString(encoding: utf8); + if (Platform.isWindows) { + var macToWinSymbols = {'╷': ',', '━': '=', '╵': '\'', '│': '|', '─': '-', '┌': ',', '└': '\''}; + macToWinSymbols.forEach((key, value) { + content = content.replaceAll(key, value); + }); + } + return LineSplitter.split(content).join('\n'); } - return LineSplitter.split(content).join('\n'); } String _stringReplacements(String content) {