Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[dartdoc_test] add documentation samples analyzer #242

Merged
merged 23 commits into from
Jul 8, 2024

Conversation

takumma
Copy link
Contributor

@takumma takumma commented Jun 17, 2024

Comment on lines 81 to 85
final expectText = '''
This is a linux line break comment.
```dart
final x = 1;
```''';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Consider writing it on the same form as the actualText that way it becomes super easy to compare what charaters changed.

Suggested change
final expectText = '''
This is a linux line break comment.
```dart
final x = 1;
```''';
final expectText = '''This is a linux line break comment.\n```dart\nfinal x = 1;\n```''';

Copy link
Contributor Author

@takumma takumma Jun 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed it so. thank you :)

).contextFor(_current.absolute.path);
);

final currentContext = _contextCollection.contextFor(_current.absolute.path);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd avoid making stateful global variables like currentContext, testDirectory, resourceProvider.

Consider making a DartDocTestContext and placing all the state you need on that. Or something like that. Could also be called a TestContext just to keep name short and simple :D

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created a singleton class called TestContext.

@takumma takumma marked this pull request as ready for review June 25, 2024 11:51
chinmoy12c
chinmoy12c approved these changes Jun 30, 2024
Comment on lines 1 to 2
A sample command-line application with an entrypoint in `bin/`, library code
in `lib/`, and example unit test in `test/`.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand this README. Can we have a proper README explaining, how to setup and test things?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a example app's README, but I made it better :)

Comment on lines 10 to 21
## install

```bash
dart pub global active dartdoc_test
```

## Usage

```bash
# analyze dart code samples in documentation comments
dartdoc_test analyze
```
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest not using global activate.

Instead, I'd suggest user do:

# Add dartdoc_test as a dev-dependency
dart pub add dev:dartdoc_test

# Run dartdoc_test directly
dart run dartdoc_test     # This will run bin/dartdoc_test.dart from package:dartdoc_test in your dependencies.

# Add a file to your own tests
cat << EOF > test/dartdoc_test.dart
import 'package:dartdoc_test:dartdoc_test.dart';
import 'package:test/test.dart';
void main() {
  test('analyze documentation code samples' {
    DartDocTest().analyze();
  });
}
EOF

# Now you can run tests with
dart test

We could also make:

# add dartdoc_test as a dev-depenedency
dart pub add dev:dartdoc_test

# run dartdoc test
dart run dartdoc_test

# Add a file in test/dartdoc_test.dart
dart run dartdoc_test add

Future<void> main(List<String> args) async {
final dartdocTest = DartDocTest(DartDocTestOptions.parse(args));
dartdocTest.analyze();
void main() {
Copy link
Member

@jonasfj jonasfj Jul 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit

Suggested change
void main() {
void main() => runDartdocTest();

@jonasfj jonasfj merged commit 28cae70 into google:dartdoc_test Jul 8, 2024
16 of 17 checks passed
@takumma takumma deleted the add-samples-analyzer branch August 12, 2024 10:48
jonasfj added a commit that referenced this pull request Aug 28, 2024
* Initial dartdoc_test packages with some hacks

* Update CI configuration

* update dartdoc_test (#239)

* add more examples and fix extracting

* code splitting and print code samples and it's location.

* set overlay of sample code and update dart sdk

* [dartdoc_test] add extractor tests and wrap code with imports (#241)

* add test

* fix

* add import

* fix indent

* move to getter

* fix for ci

* fix sdk version

* fix

* [dartdoc_test] add documentation samples analyzer (#242)

* implement analyze and output samples to .dartdoc_test directory

* add CRLF/LF line breaks tests

* add license headers to all files

* add documentation and some modified

* fix extractor test and add TestContext

* update to make analyzer work

* translate original span from sample file span

* make DartDocTestContext to singleton no longer

* add example dart project

* add write options to write sample code to file (for debug)

* updated README. minor fixes

* add new analyzer test

* update example README

* update README, add .gitignore for .dartdoc_test, and create add subcommand to generate test file

* fix

* rename DartDoc -> Dartdoc

* fix extractor and add tests

* fix span translation and add test

* add CommandRunner and make some commands to subCommand

* fix

* fix analyzer and ignore warning

* fix print of analyze results

* create integration test

* [dartdoc_test] implement good logging! (#245)

* move some codes to src/

* set analyze to default command, and print usage when -h flag is set

* remove extract command and fix integration_test

* add logger and varbose option

* add test for verbose

* fix log

* move log to Command

* [dartdoc_test] implement Reporter (#247)

* create logger class

* add summary log

* move command

* create reporter

* fix

* add ansi and fix extractor to allow code blocks with no specified language

* add output directory option

* add extractor test

* import and print relative path

* fix format

* apply review suggestions and update Reporter

* update reporter

* use stdout reporter

* allow analyze command options in default command

* add integration test for runDartdocTest()

* update report to print relative path

* fix to work test reporter in example directory

* fix

* [dartdoc_test] add some ways to ignore analysis (#248)

* implement code sample ignoring

* add comments

* fix ignoring and test

* update documentations

* add exclude option

* fix summary and make ReporterForTest use verbose flag

* move models to model.dart

* only run integration test on ./example

* do not wrap code samples with main() when code sample includes main()

* fix

* rename code sample output directory

* add doc comments

* update ignoring to use code block tagging (dart#no-test)

* add public member documentations

* fix

* switch default output directory to

* update CHANGELOG

* fix to make some class to final

* remove Reporter constructor, add some comments, and some fixes

* add missing doc comment

* fix output code

* fix for ci

* fix readme

---------

Co-authored-by: takumma <[email protected]>
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.

3 participants