Skip to content

feat: add ability to run code samples as tests (#252)#397

Open
assassinaj602 wants to merge 5 commits into
google:masterfrom
assassinaj602:add-run-tests
Open

feat: add ability to run code samples as tests (#252)#397
assassinaj602 wants to merge 5 commits into
google:masterfrom
assassinaj602:add-run-tests

Conversation

@assassinaj602

Copy link
Copy Markdown

Description

Adds ability to actually run code samples marked with #test tag.

What It Does

  • Detects #test tag in code samples
  • Runs the code as a test using dart run
  • Reports pass/fail results
  • New --run flag to enable testing

Example

/// ```dart#test
/// assert(2 + 2 == 4);
/// ```
int add(int a, int b) => a + b;

The Summary class was counting errors with commentSpan differently from
the isFailed check, causing 'FAILED: 0 issues found' when errors existed
but without commentSpan.

Now both isFailed and errors count use the same consistent logic.

Fixes google#275
The hasMain getter only detected 'void main()', causing failures for:
- Future<void> main()
- main() (no return type)
- Future main()

Now uses regex to detect all main function declarations.

Fixes google#251
- Fix unnecessary null comparison in extractor.dart
- Remove unused variable in reporter.dart
- Fix unintended HTML in model.dart doc comments
- Detect #test tag in code samples
- Add --run flag to execute tests
- Report test results with pass/fail status
- Clean up temporary files after test execution

Closes google#252
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant