8d77908227
A previous change inadvertently broke the support for Windows. This fixes this and adds an end-to-end test to avoid this. Change-Id: I6f8563665038a7ecb0b30b5dfb7051b606d90620 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/420660 Commit-Queue: Johnni Winther <johnniwinther@google.com> Reviewed-by: Bob Nystrom <rnystrom@google.com>
99 lines
2.9 KiB
Dart
99 lines
2.9 KiB
Dart
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
import 'dart:io';
|
|
import 'package:path/path.dart' as p;
|
|
import 'package:test_runner/src/utils.dart';
|
|
|
|
const commonArguments = [
|
|
'run',
|
|
'pkg/test_runner/tool/update_static_error_tests.dart',
|
|
'--update=cfe',
|
|
];
|
|
|
|
const testNameParts = [
|
|
'language',
|
|
'compile_time_constant',
|
|
'compile_time_constant_test'
|
|
];
|
|
|
|
final fileNameParts = [
|
|
'tests',
|
|
...testNameParts.take(testNameParts.length - 1),
|
|
'${testNameParts.last}.dart',
|
|
];
|
|
|
|
const expectedLine = 'Running CFE on 1 file...';
|
|
final expectedUpdateText = '${testNameParts.last}.dart (3 errors)';
|
|
|
|
void main() async {
|
|
var testFile = File(p.joinAll(fileNameParts));
|
|
var testContent = testFile.readAsStringSync();
|
|
try {
|
|
var errorFound = false;
|
|
|
|
var testName = testNameParts.join('/');
|
|
errorFound |= await run(testName);
|
|
|
|
var relativeNativePath = p.joinAll(fileNameParts);
|
|
errorFound |= await run(relativeNativePath);
|
|
|
|
var relativeUriPath = fileNameParts.join('/');
|
|
errorFound |= await run(relativeUriPath);
|
|
|
|
var absoluteNativePath = File(relativeNativePath).absolute.path;
|
|
var result = await run(absoluteNativePath);
|
|
if (Platform.isWindows) {
|
|
// TODO(johnniwinther,rnystrom): Support absolute paths on Windows.
|
|
if (!result) {
|
|
print('Error: Expected failure on Windows. '
|
|
'Update test to expect success on all platforms.');
|
|
errorFound = true;
|
|
} else {
|
|
print('Error on Windows is expected.');
|
|
}
|
|
} else {
|
|
errorFound |= result;
|
|
}
|
|
|
|
if (errorFound) {
|
|
print('----------------------------------------------------------------');
|
|
throw 'Error found!';
|
|
}
|
|
} finally {
|
|
// Restore original test content.
|
|
testFile.writeAsStringSync(testContent);
|
|
}
|
|
}
|
|
|
|
Future<bool> run(String input) async {
|
|
var executable = Platform.resolvedExecutable;
|
|
var arguments = [...commonArguments, input];
|
|
print('--------------------------------------------------------------------');
|
|
print('Running: $executable ${arguments.join(' ')}');
|
|
var process = await Process.start(executable, runInShell: true, arguments);
|
|
var lines = <String>[];
|
|
process.stdout.forEach((e) => lines.add(decodeUtf8(e)));
|
|
process.stderr.forEach((e) => lines.add(decodeUtf8(e)));
|
|
var exitCode = await process.exitCode;
|
|
var output = lines.join();
|
|
print(output);
|
|
print('Exit code: $exitCode');
|
|
|
|
var hasError = false;
|
|
if (!output.contains(expectedLine)) {
|
|
print('Error: Expected output: $expectedLine');
|
|
hasError = true;
|
|
}
|
|
if (!output.contains(expectedUpdateText)) {
|
|
print('Error: Expected update: $expectedUpdateText');
|
|
hasError = true;
|
|
}
|
|
if (exitCode != 0) {
|
|
print('Error: Expected exit code: 0');
|
|
hasError = true;
|
|
}
|
|
return hasError;
|
|
}
|