Refactor ArgParser.usage
tests for BuildPlan
to reduce duplication. (flutter/engine#56254)
Part of https://github.com/flutter/flutter/issues/157870. I figured I'd tackle a theme of tests at a time - easier for me to do in little spurts between other tasks.
This commit is contained in:
parent
38f7a81e37
commit
f89c4fd346
@ -891,19 +891,32 @@ void main() {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('show builds in help message as long as not a [ci/...] build', () {
|
// These tests should strictly check the usage (--help) output.
|
||||||
final testEnv = TestEnvironment.withTestEngine();
|
group('shows instructions based on verbosity', () {
|
||||||
|
/// Creates a configured [ArgParser] based on then environemnt and builds.
|
||||||
|
///
|
||||||
|
/// By default a non-verbose, non-RBE, Linux x64 configured [BuildPlan]
|
||||||
|
/// is created and used to configure the available options and instructions
|
||||||
|
/// for the returned [ArgParser].
|
||||||
|
///
|
||||||
|
/// - To use a different [TestEnvironment], provide [environment].
|
||||||
|
/// - To use a different set of builds, provide [builds].
|
||||||
|
ArgParser createArgParser({
|
||||||
|
TestEnvironment? environment,
|
||||||
|
void Function(TestBuilderConfig)? builds,
|
||||||
|
}) {
|
||||||
|
final testEnv = environment ?? TestEnvironment.withTestEngine();
|
||||||
addTearDown(testEnv.cleanup);
|
addTearDown(testEnv.cleanup);
|
||||||
|
|
||||||
final testConfig = TestBuilderConfig();
|
final testConfig = TestBuilderConfig();
|
||||||
testConfig.addBuild(
|
if (builds != null) {
|
||||||
name: 'ci/host_debug',
|
builds(testConfig);
|
||||||
dimension: TestDroneDimension.linux,
|
} else {
|
||||||
);
|
|
||||||
testConfig.addBuild(
|
testConfig.addBuild(
|
||||||
name: 'linux/host_debug',
|
name: 'linux/host_debug',
|
||||||
dimension: TestDroneDimension.linux,
|
dimension: TestDroneDimension.linux,
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
final parser = ArgParser();
|
final parser = ArgParser();
|
||||||
final _ = BuildPlan.configureArgParser(
|
final _ = BuildPlan.configureArgParser(
|
||||||
@ -917,17 +930,33 @@ void main() {
|
|||||||
help: true,
|
help: true,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
return parser;
|
||||||
|
}
|
||||||
|
|
||||||
|
test('show builds in help message as long as not a [ci/...] build', () {
|
||||||
|
final parser = createArgParser(
|
||||||
|
builds: (testConfig) {
|
||||||
|
testConfig.addBuild(
|
||||||
|
name: 'ci/host_debug',
|
||||||
|
dimension: TestDroneDimension.linux,
|
||||||
|
);
|
||||||
|
testConfig.addBuild(
|
||||||
|
name: 'linux/host_debug',
|
||||||
|
dimension: TestDroneDimension.linux,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
expect(parser.usage, contains('host_debug'));
|
expect(parser.usage, contains('host_debug'));
|
||||||
expect(parser.usage, isNot(contains('ci/host_debug')));
|
expect(parser.usage, isNot(contains('ci/host_debug')));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('shows [ci/...] builds if verbose is true', () {
|
test('shows [ci/...] builds if verbose is true', () {
|
||||||
final testEnv = TestEnvironment.withTestEngine(
|
final parser = createArgParser(
|
||||||
|
environment: TestEnvironment.withTestEngine(
|
||||||
verbose: true,
|
verbose: true,
|
||||||
);
|
),
|
||||||
addTearDown(testEnv.cleanup);
|
builds: (testConfig) {
|
||||||
|
|
||||||
final testConfig = TestBuilderConfig();
|
|
||||||
testConfig.addBuild(
|
testConfig.addBuild(
|
||||||
name: 'ci/host_debug',
|
name: 'ci/host_debug',
|
||||||
dimension: TestDroneDimension.linux,
|
dimension: TestDroneDimension.linux,
|
||||||
@ -936,17 +965,7 @@ void main() {
|
|||||||
name: 'linux/host_debug',
|
name: 'linux/host_debug',
|
||||||
dimension: TestDroneDimension.linux,
|
dimension: TestDroneDimension.linux,
|
||||||
);
|
);
|
||||||
|
|
||||||
final parser = ArgParser();
|
|
||||||
final _ = BuildPlan.configureArgParser(
|
|
||||||
parser,
|
|
||||||
testEnv.environment,
|
|
||||||
configs: {
|
|
||||||
'linux_test_config': testConfig.buildConfig(
|
|
||||||
path: 'ci/builders/linux_test_config.json',
|
|
||||||
),
|
|
||||||
},
|
},
|
||||||
help: true,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(parser.usage, contains('host_debug'));
|
expect(parser.usage, contains('host_debug'));
|
||||||
@ -954,26 +973,7 @@ void main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('hides LTO instructions normally', () {
|
test('hides LTO instructions normally', () {
|
||||||
final testEnv = TestEnvironment.withTestEngine();
|
final parser = createArgParser();
|
||||||
addTearDown(testEnv.cleanup);
|
|
||||||
|
|
||||||
final testConfig = TestBuilderConfig();
|
|
||||||
testConfig.addBuild(
|
|
||||||
name: 'linux/host_debug',
|
|
||||||
dimension: TestDroneDimension.linux,
|
|
||||||
);
|
|
||||||
|
|
||||||
final parser = ArgParser();
|
|
||||||
final _ = BuildPlan.configureArgParser(
|
|
||||||
parser,
|
|
||||||
testEnv.environment,
|
|
||||||
configs: {
|
|
||||||
'linux_test_config': testConfig.buildConfig(
|
|
||||||
path: 'ci/builders/linux_test_config.json',
|
|
||||||
),
|
|
||||||
},
|
|
||||||
help: true,
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
parser.usage,
|
parser.usage,
|
||||||
@ -982,31 +982,10 @@ void main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('shows LTO instructions if verbose', () {
|
test('shows LTO instructions if verbose', () {
|
||||||
final testEnv = TestEnvironment.withTestEngine(
|
final parser = createArgParser(
|
||||||
|
environment: TestEnvironment.withTestEngine(
|
||||||
verbose: true,
|
verbose: true,
|
||||||
);
|
|
||||||
addTearDown(testEnv.cleanup);
|
|
||||||
|
|
||||||
final testConfig = TestBuilderConfig();
|
|
||||||
testConfig.addBuild(
|
|
||||||
name: 'ci/host_debug',
|
|
||||||
dimension: TestDroneDimension.linux,
|
|
||||||
);
|
|
||||||
testConfig.addBuild(
|
|
||||||
name: 'linux/host_debug',
|
|
||||||
dimension: TestDroneDimension.linux,
|
|
||||||
);
|
|
||||||
|
|
||||||
final parser = ArgParser();
|
|
||||||
final _ = BuildPlan.configureArgParser(
|
|
||||||
parser,
|
|
||||||
testEnv.environment,
|
|
||||||
configs: {
|
|
||||||
'linux_test_config': testConfig.buildConfig(
|
|
||||||
path: 'ci/builders/linux_test_config.json',
|
|
||||||
),
|
),
|
||||||
},
|
|
||||||
help: true,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
@ -1016,98 +995,44 @@ void main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('shows RBE instructions if not configured', () {
|
test('shows RBE instructions if not configured', () {
|
||||||
final testEnv = TestEnvironment.withTestEngine(
|
final parser = createArgParser(
|
||||||
|
environment: TestEnvironment.withTestEngine(
|
||||||
// This is the default, but make it explicit for the test.
|
// This is the default, but make it explicit for the test.
|
||||||
// ignore: avoid_redundant_argument_values
|
// ignore: avoid_redundant_argument_values
|
||||||
withRbe: false,
|
withRbe: false,
|
||||||
);
|
|
||||||
addTearDown(testEnv.cleanup);
|
|
||||||
|
|
||||||
final testConfig = TestBuilderConfig();
|
|
||||||
testConfig.addBuild(
|
|
||||||
name: 'linux/host_debug',
|
|
||||||
dimension: TestDroneDimension.linux,
|
|
||||||
);
|
|
||||||
|
|
||||||
final parser = ArgParser();
|
|
||||||
final _ = BuildPlan.configureArgParser(
|
|
||||||
parser,
|
|
||||||
testEnv.environment,
|
|
||||||
configs: {
|
|
||||||
'linux_test_config': testConfig.buildConfig(
|
|
||||||
path: 'ci/builders/linux_test_config.json',
|
|
||||||
),
|
),
|
||||||
},
|
|
||||||
help: true,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
parser.usage,
|
parser.usage,
|
||||||
contains('Enable pre-configured remote build execution'),
|
stringContainsInOrder([
|
||||||
);
|
'Enable pre-configured remote build execution',
|
||||||
expect(
|
'https://flutter.dev/to/engine-rbe',
|
||||||
parser.usage,
|
]),
|
||||||
contains('https://flutter.dev/to/engine-rbe'),
|
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('shows RBE instructions if verbose', () {
|
test('shows RBE instructions if verbose', () {
|
||||||
final testEnv = TestEnvironment.withTestEngine(
|
final parser = createArgParser(
|
||||||
withRbe: true,
|
environment: TestEnvironment.withTestEngine(
|
||||||
verbose: true,
|
verbose: true,
|
||||||
);
|
|
||||||
addTearDown(testEnv.cleanup);
|
|
||||||
|
|
||||||
final testConfig = TestBuilderConfig();
|
|
||||||
testConfig.addBuild(
|
|
||||||
name: 'linux/host_debug',
|
|
||||||
dimension: TestDroneDimension.linux,
|
|
||||||
);
|
|
||||||
|
|
||||||
final parser = ArgParser();
|
|
||||||
final _ = BuildPlan.configureArgParser(
|
|
||||||
parser,
|
|
||||||
testEnv.environment,
|
|
||||||
configs: {
|
|
||||||
'linux_test_config': testConfig.buildConfig(
|
|
||||||
path: 'ci/builders/linux_test_config.json',
|
|
||||||
),
|
),
|
||||||
},
|
|
||||||
help: true,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
parser.usage,
|
parser.usage,
|
||||||
contains('Enable pre-configured remote build execution'),
|
stringContainsInOrder([
|
||||||
);
|
'Enable pre-configured remote build execution',
|
||||||
expect(
|
'https://flutter.dev/to/engine-rbe',
|
||||||
parser.usage,
|
]),
|
||||||
contains('https://flutter.dev/to/engine-rbe'),
|
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('hides RBE intsructions if enabled', () {
|
test('hides RBE instructions if enabled', () {
|
||||||
final testEnv = TestEnvironment.withTestEngine(
|
final parser = createArgParser(
|
||||||
|
environment: TestEnvironment.withTestEngine(
|
||||||
withRbe: true,
|
withRbe: true,
|
||||||
);
|
|
||||||
addTearDown(testEnv.cleanup);
|
|
||||||
|
|
||||||
final testConfig = TestBuilderConfig();
|
|
||||||
testConfig.addBuild(
|
|
||||||
name: 'linux/host_debug',
|
|
||||||
dimension: TestDroneDimension.linux,
|
|
||||||
);
|
|
||||||
|
|
||||||
final parser = ArgParser();
|
|
||||||
final _ = BuildPlan.configureArgParser(
|
|
||||||
parser,
|
|
||||||
testEnv.environment,
|
|
||||||
configs: {
|
|
||||||
'linux_test_config': testConfig.buildConfig(
|
|
||||||
path: 'ci/builders/linux_test_config.json',
|
|
||||||
),
|
),
|
||||||
},
|
|
||||||
help: true,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
@ -1121,29 +1046,12 @@ void main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('hides --build-strategy if RBE not enabled', () {
|
test('hides --build-strategy if RBE not enabled', () {
|
||||||
final testEnv = TestEnvironment.withTestEngine(
|
final parser = createArgParser(
|
||||||
|
environment: TestEnvironment.withTestEngine(
|
||||||
// This is the default, but make it explicit for the test.
|
// This is the default, but make it explicit for the test.
|
||||||
// ignore: avoid_redundant_argument_values
|
// ignore: avoid_redundant_argument_values
|
||||||
withRbe: false,
|
withRbe: false,
|
||||||
);
|
|
||||||
addTearDown(testEnv.cleanup);
|
|
||||||
|
|
||||||
final testConfig = TestBuilderConfig();
|
|
||||||
testConfig.addBuild(
|
|
||||||
name: 'linux/host_debug',
|
|
||||||
dimension: TestDroneDimension.linux,
|
|
||||||
);
|
|
||||||
|
|
||||||
final parser = ArgParser();
|
|
||||||
final _ = BuildPlan.configureArgParser(
|
|
||||||
parser,
|
|
||||||
testEnv.environment,
|
|
||||||
configs: {
|
|
||||||
'linux_test_config': testConfig.buildConfig(
|
|
||||||
path: 'ci/builders/linux_test_config.json',
|
|
||||||
),
|
),
|
||||||
},
|
|
||||||
help: true,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
@ -1153,27 +1061,10 @@ void main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('shows --build-strategy if RBE enabled', () {
|
test('shows --build-strategy if RBE enabled', () {
|
||||||
final testEnv = TestEnvironment.withTestEngine(
|
final parser = createArgParser(
|
||||||
|
environment: TestEnvironment.withTestEngine(
|
||||||
withRbe: true,
|
withRbe: true,
|
||||||
);
|
|
||||||
addTearDown(testEnv.cleanup);
|
|
||||||
|
|
||||||
final testConfig = TestBuilderConfig();
|
|
||||||
testConfig.addBuild(
|
|
||||||
name: 'linux/host_debug',
|
|
||||||
dimension: TestDroneDimension.linux,
|
|
||||||
);
|
|
||||||
|
|
||||||
final parser = ArgParser();
|
|
||||||
final _ = BuildPlan.configureArgParser(
|
|
||||||
parser,
|
|
||||||
testEnv.environment,
|
|
||||||
configs: {
|
|
||||||
'linux_test_config': testConfig.buildConfig(
|
|
||||||
path: 'ci/builders/linux_test_config.json',
|
|
||||||
),
|
),
|
||||||
},
|
|
||||||
help: true,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
@ -1183,27 +1074,10 @@ void main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('shows --build-strategy if verbose', () {
|
test('shows --build-strategy if verbose', () {
|
||||||
final testEnv = TestEnvironment.withTestEngine(
|
final parser = createArgParser(
|
||||||
|
environment: TestEnvironment.withTestEngine(
|
||||||
verbose: true,
|
verbose: true,
|
||||||
);
|
|
||||||
addTearDown(testEnv.cleanup);
|
|
||||||
|
|
||||||
final testConfig = TestBuilderConfig();
|
|
||||||
testConfig.addBuild(
|
|
||||||
name: 'linux/host_debug',
|
|
||||||
dimension: TestDroneDimension.linux,
|
|
||||||
);
|
|
||||||
|
|
||||||
final parser = ArgParser();
|
|
||||||
final _ = BuildPlan.configureArgParser(
|
|
||||||
parser,
|
|
||||||
testEnv.environment,
|
|
||||||
configs: {
|
|
||||||
'linux_test_config': testConfig.buildConfig(
|
|
||||||
path: 'ci/builders/linux_test_config.json',
|
|
||||||
),
|
),
|
||||||
},
|
|
||||||
help: true,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
@ -1212,28 +1086,20 @@ void main() {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('hides --gn-args if not verbose', () {
|
||||||
|
final parser = createArgParser();
|
||||||
|
|
||||||
|
expect(
|
||||||
|
parser.usage,
|
||||||
|
isNot(contains('Additional arguments to provide to "gn"')),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
test('shows --gn-args if verbose', () {
|
test('shows --gn-args if verbose', () {
|
||||||
final testEnv = TestEnvironment.withTestEngine(
|
final parser = createArgParser(
|
||||||
|
environment: TestEnvironment.withTestEngine(
|
||||||
verbose: true,
|
verbose: true,
|
||||||
);
|
|
||||||
addTearDown(testEnv.cleanup);
|
|
||||||
|
|
||||||
final testConfig = TestBuilderConfig();
|
|
||||||
testConfig.addBuild(
|
|
||||||
name: 'linux/host_debug',
|
|
||||||
dimension: TestDroneDimension.linux,
|
|
||||||
);
|
|
||||||
|
|
||||||
final parser = ArgParser();
|
|
||||||
final _ = BuildPlan.configureArgParser(
|
|
||||||
parser,
|
|
||||||
testEnv.environment,
|
|
||||||
configs: {
|
|
||||||
'linux_test_config': testConfig.buildConfig(
|
|
||||||
path: 'ci/builders/linux_test_config.json',
|
|
||||||
),
|
),
|
||||||
},
|
|
||||||
help: true,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
@ -1241,32 +1107,5 @@ void main() {
|
|||||||
contains('Additional arguments to provide to "gn"'),
|
contains('Additional arguments to provide to "gn"'),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('hides --gn-args if not verbose', () {
|
|
||||||
final testEnv = TestEnvironment.withTestEngine();
|
|
||||||
addTearDown(testEnv.cleanup);
|
|
||||||
|
|
||||||
final testConfig = TestBuilderConfig();
|
|
||||||
testConfig.addBuild(
|
|
||||||
name: 'linux/host_debug',
|
|
||||||
dimension: TestDroneDimension.linux,
|
|
||||||
);
|
|
||||||
|
|
||||||
final parser = ArgParser();
|
|
||||||
final _ = BuildPlan.configureArgParser(
|
|
||||||
parser,
|
|
||||||
testEnv.environment,
|
|
||||||
configs: {
|
|
||||||
'linux_test_config': testConfig.buildConfig(
|
|
||||||
path: 'ci/builders/linux_test_config.json',
|
|
||||||
),
|
|
||||||
},
|
|
||||||
help: true,
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(
|
|
||||||
parser.usage,
|
|
||||||
isNot(contains('Additional arguments to provide to "gn"')),
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user