Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions testing/run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'), []),
Expand Down
16 changes: 14 additions & 2 deletions tools/dir_contents_diff/lib/dir_contents_diff.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
16 changes: 16 additions & 0 deletions tools/dir_contents_diff/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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
77 changes: 77 additions & 0 deletions tools/dir_contents_diff/test/dir_contents_diff_test.dart
Original file line number Diff line number Diff line change
@@ -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'));
});
}
1 change: 1 addition & 0 deletions tools/dir_contents_diff/test/file_bad_missing.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
b.txt
3 changes: 3 additions & 0 deletions tools/dir_contents_diff/test/file_bad_unexpected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
a.txt
b.txt
c.txt
2 changes: 2 additions & 0 deletions tools/dir_contents_diff/test/file_ok.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
a.txt
b.txt
2 changes: 2 additions & 0 deletions tools/dir_contents_diff/test/file_ok_eof_newline.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
a.txt
b.txt
1 change: 1 addition & 0 deletions tools/dir_contents_diff/test/fixtures/a.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Will be referenced by a test.
1 change: 1 addition & 0 deletions tools/dir_contents_diff/test/fixtures/b.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Will be referenced by a test.