Skip to content

#3128. Initial commit #3129

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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

Conversation

sgrekhov
Copy link
Contributor

@sgrekhov sgrekhov commented Apr 3, 2025

Please note Tools/spec_coverage/resources/readme.txt

@sgrekhov sgrekhov requested review from eernstg and athomas April 3, 2025 08:52
@sgrekhov sgrekhov requested a review from athomas April 3, 2025 14:17
Copy link
Member

@athomas athomas left a comment

Choose a reason for hiding this comment

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

LGTM, will not merge and let Erik take a look as well.

@eernstg
Copy link
Member

eernstg commented Apr 8, 2025

(Just FYI: I'm working on this. ;-)

Copy link
Member

@eernstg eernstg left a comment

Choose a reason for hiding this comment

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

Many good things here! I'm not quite sure about the status—some parts of the code look like it is not nearly finished. So we need to find a good approach to check in this code such that it is well-understood what the status is, and what the code is expected to be able to do. We should probably talk about these things in an online meeting because it's a new situation.

main(List<String> args) {
Config config = Config.fromJson(readConfig());
Spec spec = Spec.fromTxt(config.specPath);
Co19 co19 = Co19(config.co19Dir);
Copy link
Member

Choose a reason for hiding this comment

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

Co19 goes along with Json, it's almost a word in this context. ;-)

findSpecChapters(co19.language.subDirs, spec.chapters);
}

void findSpecChapters(List<TestDir> testDirs, List<Chapter> chapters) {
Copy link
Member

Choose a reason for hiding this comment

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

I think this name is confusing. findSpecChapters may describe what's going on, but it makes no sense to find something and then not deliver the entities that were found, or doing something to them, or with them.

Perhaps the code is not doing anything (other than print) because it's unfinished? In that case we might want to wait a bit until we have some code that is sufficiently complete to be understood and used in some concrete cases.

It would still make sense to land various pieces of code that are reasonably well-understood (e.g., the handling of configurations in a *.json file will probably not need to change much, but findSpecChapters looks like it will change substantially before we can run those scenarios).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renamed to compareChaptersAndDirs

for (TestDir td in testDirs) {
bool found = false;
for(Chapter ch in chapters) {
if (td.name.toLowerCase() == ch.co19DirName.toLowerCase()) {
Copy link
Member

Choose a reason for hiding this comment

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

This is approximately O(n^2) where n is the number of chapters-or-dirs. That's probably not too bad (we have about 208 sections/subsections/subsubsections, and there are about 505 co19 directories), but it still seems reasonable to sort each of those lists and take the toLowerCase once and for all, and then proceed to search for matching names by holding an index into each of those two lists. That would be more like linear time.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you. Fixed! Please review.

}

static String resolvePath(String relativePath) {
String basePath = Directory.current.path;
Copy link
Member

Choose a reason for hiding this comment

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

So this utility must be executed from the root of the package? OK, I think that's a rather common restriction (but it might be nice to have an error message if the current directory at startup doesn't look like a package root).

class Spec {
late final List<Chapter> chapters;

Spec.fromTxt(String path) {
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps this could be a static method returning Spec (possibly renamed as Specification). The class could then have a private constructor accepting the list, and chapters wouldn't have to be late.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Found another way. Fixed.

@@ -0,0 +1,61 @@
import 'spec.dart';

class SpecParser {
Copy link
Member

Choose a reason for hiding this comment

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

OK, so this class depends in detail on the format of spec.txt. It's a good thing that this dependency is encapsulated to this class alone.

Copy link
Contributor Author

@sgrekhov sgrekhov left a comment

Choose a reason for hiding this comment

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

Thank you for the very detailed and useful review! Updated, PTAL. For now the only that this tool does is comparing spec chapters and test directories names and print the output like:

Found spec for co19\Language\Generics
Not found spec for co19\Language\Generics\Superbounded_types. Chapters are:
instantiation_to_bound
super_bounded_types
variance

And we immediately realyse why the appropriate chapter was not found for the directory.
The next step is to parse spec text and find appropriate assertions there.

PTAL.

class Spec {
late final List<Chapter> chapters;

Spec.fromTxt(String path) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Found another way. Fixed.

for (TestDir td in testDirs) {
bool found = false;
for(Chapter ch in chapters) {
if (td.name.toLowerCase() == ch.co19DirName.toLowerCase()) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you. Fixed! Please review.

findSpecChapters(co19.language.subDirs, spec.chapters);
}

void findSpecChapters(List<TestDir> testDirs, List<Chapter> chapters) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renamed to compareChaptersAndDirs

@sgrekhov sgrekhov requested a review from eernstg April 10, 2025 10:00
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