[cfe] tests to handle Windows EOL

Bug #50938

Change-Id: I01aeaa83f3a1a1dd143379986821da35450732a9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/278510
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
diff --git a/pkg/front_end/test/fasta/expression_suite.dart b/pkg/front_end/test/fasta/expression_suite.dart
index 10547d5..1ae29ed 100644
--- a/pkg/front_end/test/fasta/expression_suite.dart
+++ b/pkg/front_end/test/fasta/expression_suite.dart
@@ -5,42 +5,30 @@
 library fasta.test.expression_test;
 
 import "dart:io" show File, IOSink;
-
 import 'dart:typed_data' show Uint8List;
 
 import 'package:_fe_analyzer_shared/src/util/colors.dart' as colors;
-
 import "package:front_end/src/api_prototype/compiler_options.dart"
     show CompilerOptions, DiagnosticMessage;
 import 'package:front_end/src/api_prototype/experimental_flags.dart';
-
 import 'package:front_end/src/api_prototype/expression_compilation_tools.dart'
     show createDefinitionsWithTypes, createTypeParametersWithBounds;
-
 import 'package:front_end/src/api_prototype/incremental_kernel_generator.dart'
     show IncrementalCompilerResult;
-
 import "package:front_end/src/api_prototype/memory_file_system.dart"
     show MemoryFileSystem;
-
 import "package:front_end/src/api_prototype/terminal_color_support.dart"
     show printDiagnosticMessage;
-
 import 'package:front_end/src/base/processed_options.dart'
     show ProcessedOptions;
-
 import 'package:front_end/src/compute_platform_binaries_location.dart'
     show computePlatformBinariesLocation;
-
 import 'package:front_end/src/fasta/compiler_context.dart' show CompilerContext;
-
 import 'package:front_end/src/fasta/incremental_compiler.dart'
     show IncrementalCompiler;
-
 import 'package:front_end/src/fasta/kernel/utils.dart'
     show serializeComponent, serializeProcedure;
 import 'package:front_end/src/testing/compiler_common.dart';
-
 import "package:kernel/ast.dart"
     show
         Class,
@@ -53,23 +41,17 @@
         Member,
         Procedure,
         TypeParameter;
-
 import 'package:kernel/target/targets.dart' show TargetFlags;
-
 import 'package:kernel/text/ast_to_text.dart' show Printer;
-
 import "package:testing/src/log.dart" show splitLines;
-
 import "package:testing/testing.dart"
     show Chain, ChainContext, Result, Step, TestDescription, runMe;
-
 import 'package:vm/target/vm.dart' show VmTarget;
-
 import "package:yaml/yaml.dart" show YamlMap, YamlList, loadYamlNode;
 
 import '../testing_utils.dart' show checkEnvironment;
-
 import '../utils/kernel_chain.dart' show runDiff, openWrite;
+import 'testing/suite.dart';
 
 class Context extends ChainContext {
   final CompilerContext compilerContext;
@@ -114,6 +96,7 @@
 class CompilationResult {
   Procedure? compiledProcedure;
   List<DiagnosticMessage> errors;
+
   CompilationResult(this.compiledProcedure, this.errors);
 
   String printResult(Uri entryPoint, Context context) {
@@ -237,7 +220,7 @@
     File expectedFile = new File("${testUri.toFilePath()}$suffix");
     if (await expectedFile.exists()) {
       String expected = await expectedFile.readAsString();
-      if (expected.trim() != actual.trim()) {
+      if (expected.replaceAll("\r\n", "\n").trim() != actual.trim()) {
         if (!updateExpectations) {
           String diff = await runDiff(expectedFile.uri, actual);
           return fail(
@@ -653,7 +636,7 @@
 Future<Context> createContext(
     Chain suite, Map<String, String> environment) async {
   const Set<String> knownEnvironmentKeys = {
-    "updateExpectations",
+    UPDATE_EXPECTATIONS,
     "fuzz",
   };
   checkEnvironment(environment, knownEnvironmentKeys);
@@ -713,7 +696,7 @@
   final ProcessedOptions optionsNoNNBD =
       new ProcessedOptions(options: optionBuilderNoNNBD, inputs: [entryPoint]);
 
-  final bool updateExpectations = environment["updateExpectations"] == "true";
+  final bool updateExpectations = environment[UPDATE_EXPECTATIONS] == "true";
 
   final bool fuzz = environment["fuzz"] == "true";
 
diff --git a/pkg/front_end/test/fasta/textual_outline_suite.dart b/pkg/front_end/test/fasta/textual_outline_suite.dart
index c0249d6..6e004aa 100644
--- a/pkg/front_end/test/fasta/textual_outline_suite.dart
+++ b/pkg/front_end/test/fasta/textual_outline_suite.dart
@@ -8,9 +8,7 @@
 
 import 'package:_fe_analyzer_shared/src/scanner/abstract_scanner.dart'
     show ScannerConfiguration;
-
 import 'package:dart_style/dart_style.dart' show DartFormatter;
-
 import 'package:front_end/src/fasta/util/textual_outline.dart';
 import 'package:testing/testing.dart'
     show
@@ -47,7 +45,7 @@
 
 Future<Context> createContext(Chain suite, Map<String, String> environment) {
   return new Future.value(
-      new Context(environment["updateExpectations"] == "true"));
+      new Context(environment[UPDATE_EXPECTATIONS] == "true"));
 }
 
 void main([List<String> arguments = const []]) =>
diff --git a/pkg/front_end/test/incremental_suite.dart b/pkg/front_end/test/incremental_suite.dart
index 2479d56..bdf1eea 100644
--- a/pkg/front_end/test/incremental_suite.dart
+++ b/pkg/front_end/test/incremental_suite.dart
@@ -97,6 +97,7 @@
 
 import 'binary_md_dill_reader.dart' show DillComparer;
 
+import 'fasta/testing/suite.dart';
 import "incremental_utils.dart" as util;
 
 import 'test_utils.dart';
@@ -492,7 +493,7 @@
 
 Future<Context> createContext(Chain suite, Map<String, String> environment) {
   const Set<String> knownEnvironmentKeys = {
-    "updateExpectations",
+    UPDATE_EXPECTATIONS,
     "addDebugBreaks",
     "skipTests",
   };
@@ -503,7 +504,7 @@
   colors.enableColors = false;
   Set<String> skipTests = environment["skipTests"]?.split(",").toSet() ?? {};
   return new Future.value(new Context(
-    environment["updateExpectations"] == "true",
+    environment[UPDATE_EXPECTATIONS] == "true",
     environment["addDebugBreaks"] == "true",
     skipTests,
   ));
@@ -1920,7 +1921,7 @@
   if (file.existsSync()) {
     expected = file.readAsStringSync();
   }
-  if (expected != actualSerialized) {
+  if (expected?.replaceAll("\r\n", "\n") != actualSerialized) {
     if (context.updateExpectations) {
       file.writeAsStringSync(actualSerialized);
     } else {
diff --git a/pkg/front_end/test/outline_extractor_suite.dart b/pkg/front_end/test/outline_extractor_suite.dart
index a41a076..9f392bb 100644
--- a/pkg/front_end/test/outline_extractor_suite.dart
+++ b/pkg/front_end/test/outline_extractor_suite.dart
@@ -3,12 +3,15 @@
 // BSD-style license that can be found in the LICENSE file.
 
 import 'dart:convert' show jsonDecode;
-
 import 'dart:io' show File;
 
-import 'package:front_end/src/api_prototype/incremental_kernel_generator.dart';
-import 'package:front_end/src/fasta/util/outline_extractor.dart';
 import 'package:_fe_analyzer_shared/src/messages/severity.dart' show Severity;
+import 'package:front_end/src/api_prototype/compiler_options.dart';
+import 'package:front_end/src/api_prototype/incremental_kernel_generator.dart';
+import 'package:front_end/src/api_prototype/memory_file_system.dart';
+import 'package:front_end/src/fasta/util/outline_extractor.dart';
+import 'package:kernel/ast.dart';
+import 'package:kernel/src/equivalence.dart';
 import 'package:testing/testing.dart'
     show
         Chain,
@@ -18,17 +21,11 @@
         Step,
         TestDescription,
         runMe;
-import 'package:kernel/src/equivalence.dart';
-import 'package:front_end/src/api_prototype/compiler_options.dart';
-import 'package:front_end/src/api_prototype/memory_file_system.dart';
-import 'package:kernel/ast.dart';
 
 import 'fasta/testing/suite.dart' show UPDATE_EXPECTATIONS;
-import 'utils/kernel_chain.dart' show MatchContext;
-
-import 'testing_utils.dart' show checkEnvironment;
-
 import 'incremental_suite.dart' as helper;
+import 'testing_utils.dart' show checkEnvironment;
+import 'utils/kernel_chain.dart' show MatchContext;
 
 const String EXPECTATIONS = '''
 [
@@ -49,11 +46,11 @@
 Future<Context> createContext(
     Chain suite, Map<String, String> environment) async {
   const Set<String> knownEnvironmentKeys = {
-    "updateExpectations",
+    UPDATE_EXPECTATIONS,
   };
   checkEnvironment(environment, knownEnvironmentKeys);
 
-  bool updateExpectations = environment["updateExpectations"] == "true";
+  bool updateExpectations = environment[UPDATE_EXPECTATIONS] == "true";
 
   return new Context(suite.name, updateExpectations);
 }
diff --git a/pkg/front_end/test/parser_suite.dart b/pkg/front_end/test/parser_suite.dart
index c039409..d3c5f4f 100644
--- a/pkg/front_end/test/parser_suite.dart
+++ b/pkg/front_end/test/parser_suite.dart
@@ -3,43 +3,30 @@
 // BSD-style license that can be found in the LICENSE file.
 
 import 'dart:convert' show jsonDecode;
-
 import 'dart:io' show File;
-
 import 'dart:typed_data' show Uint8List;
 
-import 'package:front_end/src/fasta/command_line_reporting.dart'
-    as command_line_reporting;
-
-import 'package:front_end/src/fasta/messages.dart' show Message;
-import 'package:front_end/src/fasta/source/diet_parser.dart'
-    show useImplicitCreationExpressionInCfe;
-
-import 'package:front_end/src/fasta/util/parser_ast.dart' show getAST;
-
-import 'package:_fe_analyzer_shared/src/experiments/flags.dart' as shared
-    show ExperimentalFlag;
-
 import 'package:_fe_analyzer_shared/src/experiments/errors.dart'
     show getExperimentNotEnabledMessage;
-
+import 'package:_fe_analyzer_shared/src/experiments/flags.dart' as shared
+    show ExperimentalFlag;
 import 'package:_fe_analyzer_shared/src/parser/parser.dart'
     show Parser, lengthOfSpan;
-
 import 'package:_fe_analyzer_shared/src/scanner/scanner.dart'
     show ErrorToken, ScannerConfiguration, Token, Utf8BytesScanner;
-
 import 'package:_fe_analyzer_shared/src/scanner/token.dart'
     show SyntheticStringToken;
-
+import 'package:front_end/src/fasta/command_line_reporting.dart'
+    as command_line_reporting;
+import 'package:front_end/src/fasta/messages.dart' show Message;
+import 'package:front_end/src/fasta/source/diet_parser.dart'
+    show useImplicitCreationExpressionInCfe;
 import 'package:front_end/src/fasta/source/stack_listener_impl.dart'
     show offsetForToken;
-
+import 'package:front_end/src/fasta/util/parser_ast.dart' show getAST;
 import 'package:front_end/src/fasta/util/parser_ast_helper.dart'
     show ParserAstNode;
-
 import 'package:kernel/ast.dart';
-
 import 'package:testing/testing.dart'
     show
         Chain,
@@ -51,13 +38,10 @@
         runMe;
 
 import 'fasta/testing/suite.dart' show UPDATE_EXPECTATIONS;
-import 'utils/kernel_chain.dart' show MatchContext;
-
 import 'parser_test_listener.dart' show ParserTestListener;
-
 import 'parser_test_parser.dart' show TestParser;
-
 import 'testing_utils.dart' show checkEnvironment;
+import 'utils/kernel_chain.dart' show MatchContext;
 
 const String EXPECTATIONS = '''
 [
@@ -78,13 +62,13 @@
 Future<Context> createContext(
     Chain suite, Map<String, String> environment) async {
   const Set<String> knownEnvironmentKeys = {
-    "updateExpectations",
+    UPDATE_EXPECTATIONS,
     "trace",
     "annotateLines"
   };
   checkEnvironment(environment, knownEnvironmentKeys);
 
-  bool updateExpectations = environment["updateExpectations"] == "true";
+  bool updateExpectations = environment[UPDATE_EXPECTATIONS] == "true";
   bool trace = environment["trace"] == "true";
   bool annotateLines = environment["annotateLines"] == "true";
 
@@ -177,8 +161,10 @@
 
 class ParserAstStep extends Step<TestDescription, TestDescription, Context> {
   const ParserAstStep();
+
   @override
   String get name => "ParserAst";
+
   @override
   Future<Result<TestDescription>> run(
       TestDescription description, Context context) {
@@ -196,6 +182,7 @@
 
 class ListenerStep extends Step<TestDescription, TestDescription, Context> {
   final bool doExpects;
+
   const ListenerStep(this.doExpects);
 
   @override
diff --git a/pkg/front_end/test/utils/kernel_chain.dart b/pkg/front_end/test/utils/kernel_chain.dart
index c84a94c..c5bca3f 100644
--- a/pkg/front_end/test/utils/kernel_chain.dart
+++ b/pkg/front_end/test/utils/kernel_chain.dart
@@ -96,7 +96,7 @@
     File expectedFile = new File("${uri.toFilePath()}$suffix");
     if (await expectedFile.exists()) {
       String expected = await expectedFile.readAsString();
-      if (expected != actual) {
+      if (expected.replaceAll("\r\n", "\n") != actual) {
         if (updateExpectations) {
           return updateExpectationFile<O>(expectedFile.uri, actual, output);
         }