Skip to content

Commit

Permalink
Fix windows generator test regression
Browse files Browse the repository at this point in the history
  • Loading branch information
nielsenko committed Sep 6, 2022
1 parent b2d7589 commit de8cfd9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
2 changes: 1 addition & 1 deletion generator/test/error_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
),
),
),
Expand Down
7 changes: 5 additions & 2 deletions generator/test/info_test.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -25,8 +28,8 @@ void main() {
);

expect(
sb.toString(),
await readFileAsErrorFormattedString(directory, outputFile),
sb.toString().trim(),
(await File(path.join(directory, outputFile)).readFileAsErrorFormattedString()).trim(),
);
});
});
Expand Down
19 changes: 10 additions & 9 deletions generator/test/test_util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -189,16 +189,17 @@ Future<String> readFileAsDartFormattedString(String path) async {
return _stringReplacements(content);
}

Future<String> 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<String> 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) {
Expand Down

0 comments on commit de8cfd9

Please sign in to comment.