Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix diff command when running in nested directory #26

Merged
merged 3 commits into from Nov 30, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
@@ -1,5 +1,6 @@
## 3.0.1-dev
## 3.0.1

- Run `git diff` only on the current working directory.
- Require Dart >= 2.17.0

## 3.0.0
Expand Down
2 changes: 1 addition & 1 deletion lib/src/impl.dart
Expand Up @@ -59,7 +59,7 @@ void expectResultOutputSucceeds(String result) {
}

Future<String> _changedGeneratedFiles(String workingDir) =>
_runProc('git', ['diff'], workingDir);
_runProc('git', ['diff', '.'], workingDir);

Future<String> _runProc(
String proc,
Expand Down
2 changes: 1 addition & 1 deletion lib/src/version.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pubspec.yaml
Expand Up @@ -2,7 +2,7 @@ name: build_verify
description: >-
Test utility to ensure generated Dart code within a package is up-to-date
when using package:build.
version: 3.0.1-dev
version: 3.0.1
repository: https://github.com/kevmoo/build_verify

environment:
Expand Down
23 changes: 23 additions & 0 deletions test/integration/helpers.dart
@@ -0,0 +1,23 @@
import 'package:test_descriptor/test_descriptor.dart' as d;

d.FileDescriptor getPubspecYamlFile(String packageName) => d.file(
'pubspec.yaml',
'''
name: $packageName
version: 1.2.3
environment:
sdk: '>=2.12.0 <3.0.0'

dev_dependencies:
build_runner: ^2.0.0
build_version: ^2.0.0
''',
);

d.FileDescriptor getGeneratedVersionFile(String version) => d.file(
'version.dart',
'''
// Generated code. Do not modify.
const packageVersion = '$version';
''',
);
99 changes: 99 additions & 0 deletions test/integration/nested_integration_test.dart
@@ -0,0 +1,99 @@
@Timeout.factor(4)

import 'package:build_verify/build_verify.dart' show defaultCommand;
import 'package:build_verify/src/impl.dart';
import 'package:build_verify/src/utils.dart';
import 'package:git/git.dart';
import 'package:test/test.dart';
import 'package:test_descriptor/test_descriptor.dart' as d;
import 'package:test_process/test_process.dart';

import 'helpers.dart';

void main() {
setUp(() async {
await d.dir('package_a', [
getPubspecYamlFile('package_a'),
d.dir('lib', [
d.dir('src', [
getGeneratedVersionFile('1.2.3'),
])
])
]).create();

await d.dir('package_b', [
getPubspecYamlFile('package_b'),
d.dir('lib', [
d.dir('src', [
getGeneratedVersionFile('1.2.3'),
])
])
]).create();

final gitDir = await GitDir.init(d.sandbox, allowContent: true);
await gitDir.runCommand(['add', '.']);
await gitDir.runCommand(['commit', '-am', 'test']);

final packageAProcess = await TestProcess.start(
dartPath,
['pub', 'get'],
workingDirectory: '${d.sandbox}/package_a',
);

await packageAProcess.shouldExit(0);

final packageBProcess = await TestProcess.start(
dartPath,
['pub', 'get'],
workingDirectory: '${d.sandbox}/package_b',
);

await packageBProcess.shouldExit(0);
});

test(
'when they have no modification, package a and b tests should pass',
() async {
await expectBuildCleanImpl(
'${d.sandbox}/package_a',
defaultCommand,
packageRelativeDirectory: 'package_a',
);
await expectBuildCleanImpl(
'${d.sandbox}/package_b',
defaultCommand,
packageRelativeDirectory: 'package_b',
);
},
);

test(
'''when package b has modifications,
package a test should pass and package b test should fail''',
() async {
await d.dir('package_b', [
getPubspecYamlFile('package_b'),
d.dir('lib', [
d.dir('src', [
getGeneratedVersionFile('1.2.4'),
])
])
]).create();

await expectBuildCleanImpl(
'${d.sandbox}/package_a',
defaultCommand,
packageRelativeDirectory: 'package_a',
);

expect(
() => expectBuildCleanImpl(
'${d.sandbox}/package_b',
defaultCommand,
packageRelativeDirectory: 'package_b',
),
throwsA(const TypeMatcher<TestFailure>()),
);
},
);
}
Expand Up @@ -8,31 +8,15 @@ import 'package:test/test.dart';
import 'package:test_descriptor/test_descriptor.dart' as d;
import 'package:test_process/test_process.dart';

import 'helpers.dart';

void main() {
setUp(() async {
await d.file(
'pubspec.yaml',
'''
name: example
version: 1.2.3
environment:
sdk: '>=2.12.0 <3.0.0'

dev_dependencies:
build_runner: ^2.0.0
build_version: ^2.0.0
''',
).create();
await getPubspecYamlFile('example').create();

await d.dir('lib', [
d.dir('src', [
d.file(
'version.dart',
r'''
// Generated code. Do not modify.
const packageVersion = '1.2.3';
''',
)
getGeneratedVersionFile('1.2.3'),
])
]).create();

Expand Down