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

Test all code excerpts #1803

Closed
13 of 23 tasks
kwalrath opened this issue Jul 31, 2019 · 11 comments
Closed
13 of 23 tasks

Test all code excerpts #1803

kwalrath opened this issue Jul 31, 2019 · 11 comments
Labels
a.language Relates to the Dart language tour e3-weeks Complete in < 4 weeks of normal, not dedicated, work fix.examples Adds or changes example infra.structure Relates to the tools that create dart.dev p2-medium Necessary but not urgent concern. Resolve when possible. test.general Relates to unit, integration, perf testing

Comments

@kwalrath
Copy link
Contributor

kwalrath commented Jul 31, 2019

This bug replaces #407, which is the equivalent for the pre-dart.dev version of this site. We'll need to be able to test all samples as null safety is released.


New pages that need tests for code excerpts:

Old pages that should have tests for code excerpts, including DartPad code (which in most cases is contained in a Gist):

Lower priority code in new pages:

  • Some pages migrated from the old webdev site:

Other:

Tested to some extent:

  • codelabs/async-await: copies of runnable code are in the repo; it's possible for the gists and repo to get out of sync, though.

Done:

Intentionally not testing:

@kwalrath kwalrath added infra.structure Relates to the tools that create dart.dev p1-high Major but not urgent concern: Resolve in months. Update each month. p2-medium Necessary but not urgent concern. Resolve when possible. fix.examples Adds or changes example test.general Relates to unit, integration, perf testing e3-weeks Complete in < 4 weeks of normal, not dedicated, work and removed p2-medium Necessary but not urgent concern. Resolve when possible. labels Jul 31, 2019
@chalin chalin self-assigned this Sep 11, 2019
chalin added a commit that referenced this issue Sep 15, 2019
…1900)

There are **NO doc changes in this PR**, only infrastructure updates.

Prep work to #1803.

Details:
- create_site_main_example.dart: apply dart --fix and other cleanup
- create_site_main_example.dart: refactoring to support multiple src files
- create_site_main_example.dart: support tool tip title
- create_site_main_example.dart refactoring
- create_site_main_example.dart: add support for tooltips on their own line
- create_site_main_example.dart: skip docregion lines
- pi_monte_carlo.dart: adjust tip instructions so that we can run dartfmt on file
@chalin chalin mentioned this issue Sep 15, 2019
chalin added a commit that referenced this issue Sep 15, 2019
Prep work for #1803.
chalin added a commit that referenced this issue Sep 16, 2019
…iles (#1908)

No site content changes.

Prep work so that we can actually show code excerpts using analyzer ignore directives.
Contributes to #1803
@chalin
Copy link
Contributor

chalin commented Sep 17, 2019

Kathy, I've moved into the opening comment the work items that used to appear in separate comments. That will make it a bit easier to track.

chalin added a commit that referenced this issue Sep 17, 2019
chalin added a commit that referenced this issue Sep 19, 2019
Resolves the second item of #1803.

* Analysis options page: ensure code excerpts are analyzed/tested

* Replace images of code with tooltip by code excerpts

* Edits inspired by Kathy's comments

* Add IDE-like analyzer-error highlighting to implicit-casts example

* Drop linenums from implicit-casts example
chalin added a commit that referenced this issue Sep 24, 2019
Contributes to #1803.
Followup to #1902.

* Move cat_no_hash.dart from lib to bin

Fixes #1927

* Add a basic test for each of the three "cat" commands

* Ensure that there are no errors when dcat or dcat1 are run
@chalin chalin mentioned this issue Oct 25, 2019
19 tasks
@jddeep
Copy link
Contributor

jddeep commented Feb 28, 2020

@kwalrath So I noticed the src for the Dart cheatsheet codelab to be here https://github.com/dart-lang/site-www/edit/master/src/codelabs/dart-cheatsheet.md. So if were to add the code-excerpt for the code snippet:

int a; // The initial value of a is null.
a ??= 3;
print(a); // <-- Prints 3.

a ??= 5;
print(a); // <-- Still prints 3.

Is there the code file for this snippet already there to be linked or we need to create first? Also should it be just a gist or we should add as .dart file in this repo itself?

@kwalrath
Copy link
Contributor Author

You've got the right source file for the cheatsheet codelab, although it'd probably be easiest to edit it locally rather than in GitHub.

I believe that all of those samples are untested, and grepping the repo for ??= 3 brings up nothing. Gists aren't testable, so ideally we'd add .dart files to the repo so that Travis will analyze the code, and perhaps actually test it.

Once that code is in your copy of the repo, then in a separate commit (for the same branch & PR) you could add code-excerpt above each excerpt. If you have the local build working, then you can run tool/refresh-code-excerpts.sh to update the code excerpts — and if there are changes/mistakes, you'll see them in the diffs.

Does that make sense?

@jddeep
Copy link
Contributor

jddeep commented Feb 28, 2020

Yes, @kwalrath that makes sense.
Am on it.

@jddeep
Copy link
Contributor

jddeep commented Feb 28, 2020

@kwalrath Adding all the code snippets as in the cheatsheet.md file, into a single dart file, say, dart_cheatsheet.dart isn't feasible cause, in the .md file there are various objects and classes with the same name as for demonstration.
So should I go ahead to make separate code files(as fewer files needed) at /misc/bin/ of the repo?
If yes, could I open an issue to add the code files for this dart cheatsheet. Once that issue is resolved and we add the needed code files, I can direct to this issue with a PR for the code-excerpts.
Please do let me know your thoughts :) Thanks.

@kwalrath
Copy link
Contributor Author

I'm fine with splitting this up into two PRs, although what I'm about to say next might change your mind...

To deal with multiple objects/classes having the same name, one possibility is to put them in different files, as you said. Another one is to change the names used in the samples, so they aren't all the same. (We generally don't do this, since the names were the same for a reason.) A technique we often use is to have one file with different names for the objects/classes — and then to modify them to be the same name by using replace in the code-excerpt.

I don't remember exactly where I've done the latter, but if you do the following command in your copy of the repo, you can see lots of examples of using replace in the language tour:

$ fgrep -R code-excerpt src/_guides/language/language-tour.md | grep replace

Many of those uses are for the purpose of highlighting (by surrounding it with [!...!]). For example, replace="/async|await/[!$&!]/g" highlights async and await in an excerpt. But other uses are to change the actual displayed code.

For example, instead of having myObject, you could have myObject1, myObject2, etc. and then use replace to change them all to myObject.

@jddeep
Copy link
Contributor

jddeep commented Feb 29, 2020

@kwalrath Thanks for letting me know about this technique :) Will implement when I work on the next files.
Actually, I have already made different files for the code snippets used in the cheatsheet and will make a PR with the code files now. So should I direct/refer to this issue (#1803) only in that PR body or I should make a separate issue for adding the code files?
Thanks.

@kwalrath
Copy link
Contributor Author

kwalrath commented Mar 3, 2020

I'd love to see that PR and how Travis likes it. Did you find any issues with the code while creating those files?

It'd probably be good to have a separate issue for adding the cheatsheet code samples. (Then I can add that issue above by the cheatsheet item.) Either you or I can create that issue.

@jddeep
Copy link
Contributor

jddeep commented Mar 3, 2020

Nope i didn't find any such issues while creating the files.
@kwalrath Could you then open the issue for the same and let me know. Will make the PR and direct to the issue. Thanks :)

@jddeep
Copy link
Contributor

jddeep commented Mar 3, 2020

@kwalrath nvm :) have opened the issue for us.

@kwalrath kwalrath added this to the Null safety: stable release milestone Mar 31, 2020
@kwalrath kwalrath added the a.language Relates to the Dart language tour label Feb 12, 2021
@kwalrath kwalrath self-assigned this Feb 12, 2021
@kwalrath kwalrath added p2-medium Necessary but not urgent concern. Resolve when possible. and removed p1-high Major but not urgent concern: Resolve in months. Update each month. labels Feb 23, 2021
@kwalrath kwalrath removed their assignment Jun 24, 2021
@parlough
Copy link
Member

parlough commented Aug 2, 2023

This issue is quite out of date as a lot of progress has been made. I'm going to close this in favor of more specific issues as we determine excerpts are needed.

@parlough parlough closed this as completed Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a.language Relates to the Dart language tour e3-weeks Complete in < 4 weeks of normal, not dedicated, work fix.examples Adds or changes example infra.structure Relates to the tools that create dart.dev p2-medium Necessary but not urgent concern. Resolve when possible. test.general Relates to unit, integration, perf testing
Projects
None yet
Development

No branches or pull requests

4 participants