mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Ignore EOF newline characters and added tests to dir_contents_diff tool (flutter/engine#50805)
No issue filed, but was [discussed on discord](https://discord.com/channels/608014603317936148/608021010377080866/1209568840644567091).
This commit is contained in:
parent
55da4fb37d
commit
05fedd7c11
@ -922,6 +922,7 @@ def build_dart_host_test_list(build_dir):
|
||||
os.path.join(build_dir, 'dart-sdk', 'lib', 'libraries.json'),
|
||||
],
|
||||
),
|
||||
(os.path.join('flutter', 'tools', 'dir_contents_diff'), []),
|
||||
(os.path.join('flutter', 'tools', 'engine_tool'), []),
|
||||
(os.path.join('flutter', 'tools', 'githooks'), []),
|
||||
(os.path.join('flutter', 'tools', 'header_guard_check'), []),
|
||||
|
||||
@ -70,8 +70,20 @@ int dirContentsDiff(String goldenPath, String dirPath) {
|
||||
final String dirListing = _generateDirListing(dirPath);
|
||||
tempFile.writeAsStringSync(dirListing);
|
||||
final ProcessResult diffResult = Process.runSync(
|
||||
'git', <String>['diff', '-p', goldenPath, tempFile.path],
|
||||
runInShell: true, stdoutEncoding: utf8);
|
||||
'git',
|
||||
<String>[
|
||||
'diff',
|
||||
// If you manually edit the golden file, many text editors will add
|
||||
// trailing whitespace. This flag ignores that because honestly it's
|
||||
// not a significant part of this test.
|
||||
'--ignore-space-at-eol',
|
||||
'-p',
|
||||
goldenPath,
|
||||
tempFile.path,
|
||||
],
|
||||
runInShell: true,
|
||||
stdoutEncoding: utf8,
|
||||
);
|
||||
if (diffResult.exitCode != 0) {
|
||||
print(
|
||||
'Unexpected diff in $goldenPath, use `git apply` with the following patch.\n');
|
||||
|
||||
@ -1,3 +1,19 @@
|
||||
name: dir_contents_diff
|
||||
environment:
|
||||
sdk: '>=3.2.0-0 <4.0.0'
|
||||
dev_dependencies:
|
||||
litetest: any
|
||||
path: any
|
||||
dependency_overrides:
|
||||
async_helper:
|
||||
path: ../../../third_party/dart/pkg/async_helper
|
||||
expect:
|
||||
path: ../../../third_party/dart/pkg/expect
|
||||
litetest:
|
||||
path: ../../testing/litetest
|
||||
meta:
|
||||
path: ../../../third_party/dart/pkg/meta
|
||||
path:
|
||||
path: ../../../third_party/dart/third_party/pkg/path
|
||||
smith:
|
||||
path: ../../../third_party/dart/pkg/smith
|
||||
|
||||
@ -0,0 +1,77 @@
|
||||
import 'dart:io' as io;
|
||||
|
||||
import 'package:litetest/litetest.dart';
|
||||
import 'package:path/path.dart' as p;
|
||||
|
||||
void main() {
|
||||
// Find a path to `dir_contents_diff.dart` from the working directory.
|
||||
final String pkgPath = io.File.fromUri(io.Platform.script).parent.parent.path;
|
||||
final String binPath = p.join(
|
||||
pkgPath,
|
||||
'bin',
|
||||
'dir_contents_diff.dart',
|
||||
);
|
||||
|
||||
// As a sanity check, ensure that the file exists.
|
||||
if (!io.File(binPath).existsSync()) {
|
||||
io.stderr.writeln('Unable to find $binPath');
|
||||
io.exitCode = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Runs `../bin/dir_contents_diff.dart` with the given arguments.
|
||||
(int, String) runSync(String goldenPath, String dirPath) {
|
||||
final io.ProcessResult result = io.Process.runSync(
|
||||
'dart',
|
||||
<String>[binPath, goldenPath, dirPath],
|
||||
);
|
||||
return (result.exitCode, result.stdout ?? result.stderr);
|
||||
}
|
||||
|
||||
test('lists files and diffs successfully', () {
|
||||
final String goldenPath = p.join(pkgPath, 'test', 'file_ok.txt');
|
||||
final String dirPath = p.join(pkgPath, 'test', 'fixtures');
|
||||
final (int exitCode, String output) = runSync(goldenPath, dirPath);
|
||||
if (exitCode != 0) {
|
||||
io.stderr.writeln('Expected exit code 0, got $exitCode');
|
||||
io.stderr.writeln(output);
|
||||
}
|
||||
expect(exitCode, 0);
|
||||
});
|
||||
|
||||
test('lists files and diffs successfully, even with an EOF newline', () {
|
||||
final String goldenPath = p.join(pkgPath, 'test', 'file_ok_eof_newline.txt');
|
||||
final String dirPath = p.join(pkgPath, 'test', 'fixtures');
|
||||
final (int exitCode, String output) = runSync(goldenPath, dirPath);
|
||||
if (exitCode != 0) {
|
||||
io.stderr.writeln('Expected exit code 0, got $exitCode');
|
||||
io.stderr.writeln(output);
|
||||
}
|
||||
expect(exitCode, 0);
|
||||
});
|
||||
|
||||
test('diff fails when an expected file is missing', () {
|
||||
final String goldenPath = p.join(pkgPath, 'test', 'file_bad_missing.txt');
|
||||
final String dirPath = p.join(pkgPath, 'test', 'fixtures');
|
||||
final (int exitCode, String output) = runSync(goldenPath, dirPath);
|
||||
if (exitCode == 0) {
|
||||
io.stderr.writeln('Expected non-zero exit code, got $exitCode');
|
||||
io.stderr.writeln(output);
|
||||
}
|
||||
expect(exitCode, 1);
|
||||
expect(output, contains('+a.txt'));
|
||||
});
|
||||
|
||||
test('diff fails when an unexpected file is present', () {
|
||||
final String goldenPath = p.join(pkgPath, 'test', 'file_bad_unexpected.txt');
|
||||
final String dirPath = p.join(pkgPath, 'test', 'fixtures');
|
||||
final (int exitCode, String output) = runSync(goldenPath, dirPath);
|
||||
if (exitCode == 0) {
|
||||
io.stderr.writeln('Expected non-zero exit code, got $exitCode');
|
||||
io.stderr.writeln(output);
|
||||
}
|
||||
expect(exitCode, 1);
|
||||
expect(output, contains('-c.txt'));
|
||||
});
|
||||
}
|
||||
@ -0,0 +1 @@
|
||||
b.txt
|
||||
@ -0,0 +1,3 @@
|
||||
a.txt
|
||||
b.txt
|
||||
c.txt
|
||||
@ -0,0 +1,2 @@
|
||||
a.txt
|
||||
b.txt
|
||||
@ -0,0 +1,2 @@
|
||||
a.txt
|
||||
b.txt
|
||||
1
engine/src/flutter/tools/dir_contents_diff/test/fixtures/a.txt
vendored
Normal file
1
engine/src/flutter/tools/dir_contents_diff/test/fixtures/a.txt
vendored
Normal file
@ -0,0 +1 @@
|
||||
Will be referenced by a test.
|
||||
1
engine/src/flutter/tools/dir_contents_diff/test/fixtures/b.txt
vendored
Normal file
1
engine/src/flutter/tools/dir_contents_diff/test/fixtures/b.txt
vendored
Normal file
@ -0,0 +1 @@
|
||||
Will be referenced by a test.
|
||||
Loading…
x
Reference in New Issue
Block a user