Unverified Commit cdc40b52 authored by Andrew Kolos's avatar Andrew Kolos Committed by GitHub

clean up `--dart-define-from-file` option tests (#135980)

Fixes https://github.com/flutter/flutter/issues/134279.

Changes:
* Moves all tests of `--dart-define-from-file` behavior from `build_bundle_test.dart` and `assemble_test.dart` to `flutter_command_test.dart`.
* Deletes a duplicate test of malformed JSON detection behavior.
* Renames the `useDartDefineFromFileOption` method of `FlutterCommand` to `_usesDartDefineFromFileOption`. This 1) makes the name more consistent with the other `uses*Option` methods and 2) hides the method since it is not used outside of the file.
* Renames several tests to better articulate what is under test and what the expected result is.
* Adds a test for the case where a `.env` file with a malformed line is provided to `--dart-define-from-file`.
parent 22f593e5
......@@ -656,10 +656,10 @@ abstract class FlutterCommand extends Command<void> {
valueHelp: 'foo=bar',
splitCommas: false,
);
useDartDefineFromFileOption();
_usesDartDefineFromFileOption();
}
void useDartDefineFromFileOption() {
void _usesDartDefineFromFileOption() {
argParser.addMultiOption(
FlutterOptions.kDartDefineFromFileOption,
help:
......@@ -1441,9 +1441,10 @@ abstract class FlutterCommand extends Command<void> {
dartDefineConfigJsonMap[key] = value;
});
} on FormatException catch (err) {
throwToolExit('Json config define file "--${FlutterOptions
.kDartDefineFromFileOption}=$path" format err, '
'please fix first! format err:\n$err');
throwToolExit('Unable to parse the file at path "$path" due to a formatting error. '
'Ensure that the file contains valid JSON.\n'
'Error details: $err'
);
}
}
}
......
......@@ -290,49 +290,4 @@ void main() {
],
});
});
testUsingContext('test --dart-define-from-file option with err file format', () {
globals.fs.directory('config').createSync();
final CommandRunner<void> commandRunner = createTestCommandRunner(AssembleCommand(
buildSystem: TestBuildSystem.all(BuildResult(success: true)),
));
expect(commandRunner.run(<String>['assemble',
'-o Output',
'debug_macos_bundle_flutter_assets',
'--dart-define=k=v',
'--dart-define-from-file=config']),
throwsToolExit(message: 'Did not find the file passed to "--dart-define-from-file". Path: config'));
}, overrides: <Type, Generator>{
Cache: () => Cache.test(processManager: FakeProcessManager.any()),
FileSystem: () => MemoryFileSystem.test(),
ProcessManager: () => FakeProcessManager.any(),
});
testUsingContext('test --dart-define-from-file option with err json format', () async {
await globals.fs.file('config.json').writeAsString(
'''
{
"kInt": 1,
"kDouble": 1.1,
"name": "err json format,
"title": "this is title from config json file"
}
'''
);
final CommandRunner<void> commandRunner = createTestCommandRunner(AssembleCommand(
buildSystem: TestBuildSystem.all(BuildResult(success: true)),
));
expect(commandRunner.run(<String>['assemble',
'-o Output',
'debug_macos_bundle_flutter_assets',
'--dart-define=k=v',
'--dart-define-from-file=config.json']),
throwsToolExit(message: 'Json config define file "--dart-define-from-file=config.json" format err, please fix first! format err:'));
}, overrides: <Type, Generator>{
Cache: () => Cache.test(processManager: FakeProcessManager.any()),
FileSystem: () => MemoryFileSystem.test(),
ProcessManager: () => FakeProcessManager.any(),
});
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment