From e7614adedbd30727b2aab0f3af0d7d3ec7ea56bb Mon Sep 17 00:00:00 2001 From: Johnni Winther Date: Tue, 27 Aug 2019 09:56:53 +0000 Subject: [PATCH] [cfe] Add Windows work-around for git diff in expectation testing Change-Id: I126fb328181fc225177486e01a98e83060539b9e Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/114502 Commit-Queue: Johnni Winther Reviewed-by: Jens Johansen --- .../test/spell_checking_list_common.txt | 2 ++ pkg/front_end/test/utils/kernel_chain.dart | 31 ++++++++++++++++--- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/pkg/front_end/test/spell_checking_list_common.txt b/pkg/front_end/test/spell_checking_list_common.txt index 8d496a86520..a4239e69a1a 100644 --- a/pkg/front_end/test/spell_checking_list_common.txt +++ b/pkg/front_end/test/spell_checking_list_common.txt @@ -1928,6 +1928,7 @@ physical pick picked pipeline +piping pivot place placed @@ -2396,6 +2397,7 @@ should shouldn't show shown +shows shrink side sign diff --git a/pkg/front_end/test/utils/kernel_chain.dart b/pkg/front_end/test/utils/kernel_chain.dart index 646d00c7029..fca8792f685 100644 --- a/pkg/front_end/test/utils/kernel_chain.dart +++ b/pkg/front_end/test/utils/kernel_chain.dart @@ -7,6 +7,7 @@ library fasta.testing.kernel_chain; import 'dart:async' show Future; import 'dart:io' show Directory, File, IOSink; +import 'dart:io'; import 'dart:typed_data' show Uint8List; @@ -402,10 +403,32 @@ class BytesCollector implements Sink> { } Future runDiff(Uri expected, String actual) async { - StdioProcess process = await StdioProcess.run( - "git", ["diff", "--no-index", "-u", expected.toFilePath(), "-"], - input: actual, runInShell: true); - return process.output; + if (Platform.isWindows) { + // TODO(johnniwinther): Work-around for Windows. For some reason piping + // the actual result through stdin doesn't work; it shows a diff as if the + // actual result is the empty string. + Directory tempDirectory = Directory.systemTemp.createTempSync(); + Uri uri = tempDirectory.uri.resolve('actual'); + File file = new File.fromUri(uri)..writeAsStringSync(actual); + StdioProcess process = await StdioProcess.run( + "git", + [ + "diff", + "--no-index", + "-u", + expected.toFilePath(), + uri.toFilePath() + ], + runInShell: true); + file.deleteSync(); + tempDirectory.deleteSync(); + return process.output; + } else { + StdioProcess process = await StdioProcess.run( + "git", ["diff", "--no-index", "-u", expected.toFilePath(), "-"], + input: actual, runInShell: true); + return process.output; + } } Future openWrite(Uri uri, f(IOSink sink)) async {