dart-neats icon indicating copy to clipboard operation
dart-neats copied to clipboard

Dartdoc_test reports no tests run when everything works

Open sigurdm opened this issue 1 year ago • 2 comments

Given this lib/abd.dart

/// This class is excellent
/// ```dart
/// void main() {
///   print('hi');
///   main();
/// }
/// ```
class Foo {}
> dart test
00:01 +0: loading test/dartdoc_test.dart                                                                                       Extracting code samples ...
Analyzing code samples ...
No tests ran.                                                                                                                   
No tests were found.

I would have expected at least a single test to have run. If I make a syntax error it does indeed report a failed test.

sigurdm avatar Sep 02 '24 10:09 sigurdm

@takumma FYI, in case you're interested.

jonasfj avatar Sep 04 '24 13:09 jonasfj

The issue I analyzed is that the dartdoc_test doesn't recognize or detect the test running inside the documentation.

Solution I proposed:

Modify test/dartdoc_test.dart to explicitly scan and run the code samples in lib/abd.dart

syntax:

import 'package:dartdoc_test/dartdoc_test.dart';

// main definition void main () { testDartdocExamples('lib/abd.dart'); }

Why this is helpful:

The tool might not automatically detect the test, so explicitly registering it forces dartdoc_test to analyze lib/abd.dart.

to run:

dart test

Hira-Iftikhar-123 avatar Feb 02 '25 19:02 Hira-Iftikhar-123