Skip to content

Commit

Permalink
Add tests for nested packages case
Browse files Browse the repository at this point in the history
  • Loading branch information
vkammerer committed Nov 10, 2022
1 parent 2e91cc9 commit 24b5b5d
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 20 deletions.
23 changes: 23 additions & 0 deletions test/integration/helpers.dart
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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>()),
);
},
);
}
Original file line number Diff line number Diff line change
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

0 comments on commit 24b5b5d

Please sign in to comment.