Skip to content

Commit

Permalink
Fixed regex to show missing assets file error (#131160)
Browse files Browse the repository at this point in the history
Added Regex to match error message from verbos build as suggested by @stuartmorgan [here](flutter/flutter#98137 (comment)).
Modified Windows Build Test

Fixes #97065
  • Loading branch information
thisisjaymehta authored Jul 31, 2023
1 parent 3cf206b commit efc9e16
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
11 changes: 10 additions & 1 deletion packages/flutter_tools/lib/src/windows/build_windows.dart
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,16 @@ Future<void> _runBuild(

// MSBuild sends all output to stdout, including build errors. This surfaces
// known error patterns.
final RegExp errorMatcher = RegExp(r':\s*(?:warning|(?:fatal )?error).*?:');
final RegExp errorMatcher = RegExp(
<String>[
// Known error messages
r'(:\s*(?:warning|(?:fatal )?error).*?:)',
r'Error detected in pubspec\.yaml:',

// Known secondary error lines for pubspec.yaml
r'No file or variants found for asset:',
].join('|'),
);

int result;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -962,6 +962,41 @@ if %errorlevel% neq 0 goto :VCEnd</Command>
ProcessManager: () => FakeProcessManager.any(),
FeatureFlags: () => TestFeatureFlags(isWindowsEnabled: true),
});

// Tests the case where stdout contains the error about pubspec.yaml
// And tests the case where stdout contains the error about missing assets
testUsingContext('Windows build extracts errors related to pubspec.yaml from stdout', () async {
final FakeVisualStudio fakeVisualStudio = FakeVisualStudio();
final BuildWindowsCommand command = BuildWindowsCommand(logger: BufferLogger.test())
..visualStudioOverride = fakeVisualStudio;
setUpMockProjectFilesForBuild();

const String stdout = r'''
Error detected in pubspec.yaml:
No file or variants found for asset: images/a_dot_burr.jpeg.
''';

processManager = FakeProcessManager.list(<FakeCommand>[
cmakeGenerationCommand(),
buildCommand('Release',
stdout: stdout,
),
]);

await createTestCommandRunner(command).run(
const <String>['windows', '--no-pub']
);
// Just the warnings and errors should be surfaced.
expect(testLogger.errorText, r'''
Error detected in pubspec.yaml:
No file or variants found for asset: images/a_dot_burr.jpeg.
''');
}, overrides: <Type, Generator>{
FileSystem: () => fileSystem,
ProcessManager: () => processManager,
Platform: () => windowsPlatform,
FeatureFlags: () => TestFeatureFlags(isWindowsEnabled: true),
});
}

class FakeVisualStudio extends Fake implements VisualStudio {
Expand Down

0 comments on commit efc9e16

Please sign in to comment.