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

Statically parse, rather than run, test files to extract @testitems #41

Closed
nickrobinson251 opened this issue Apr 13, 2023 · 6 comments · Fixed by #179
Closed

Statically parse, rather than run, test files to extract @testitems #41

nickrobinson251 opened this issue Apr 13, 2023 · 6 comments · Fixed by #179
Labels
perf About improving the performance of the package speculative a feature idea that we are undecided about

Comments

@nickrobinson251
Copy link
Collaborator

We could change the @testitem scanning from calling include to instead parsing the files (e.g. Meta.parse(read(file, String))) then walk the AST looking for top-level @testitems that we then eval.

This would have a few potential benefits:

  • We could error on any non-top-level @testitems (/ @testsetups)
  • We could @warn on @testitems that were not in _test.jl files
  • We could error on any top-level code in _test.jl files that's not a @testitem (or @testsetup)
  • We wouldn’t necessarily need the _test.jl suffix, since we could scan any file and just eval the @testitem

This is also more similar to what the VS Code extension does (#18)

@NHDaly
Copy link
Member

NHDaly commented Apr 13, 2023

We wouldn’t necessarily need the _test.jl suffix, since we could scan any file and just eval the @testitem

One possible policy that i think could be good for everyone would be any file that contains a @testitem or @testsetup must only contain testitems and testsetups. That could be a way to do away with the _test.jl suffix and still keep the other benefits of catching malformed testitems.

(But this aspect is much less relevant than the main thrust of what you're describing here, and i'd rather start with what you proposed 👍)

@NHDaly
Copy link
Member

NHDaly commented May 26, 2023

@nickrobinson251 oh haha sorry i forgot we'd already detailed these steps. sorry i spammed it on that slack thread!

@nickrobinson251
Copy link
Collaborator Author

i'm still gonna add you suggestion here 😁

literally replace include() with this simple function that does exactly the same thing:

  julia> function my_include(file)
          block = Meta.parse("begin\n" * read(file, String) * "\nend")
          exprs = block.args
          for expr in exprs
              eval(expr)
          end
      end

We can just start with that, which is a noop change, and then literally just add some super tiny error checks in there that each expression is either at @testitem or a @testsetup and boom we've done it, and now we've switched to the "static parsing" approach but everything else is unchanged! :)

We can even continue to run includes as well, if we want to, to make the transition easier

@NHDaly
Copy link
Member

NHDaly commented Jul 21, 2023

we didn't end up doing this yet, did we? Just trying to remember and clean up issues

@nickrobinson251
Copy link
Collaborator Author

In #78 we switched to first iterating over the parsed Exprs as part of the include, so we can assert that every Expr is a @testitem or @testsetup macro call. But we still only include files with the _test.jl or _testsetup.jl suffix.

@nickrobinson251 nickrobinson251 added the speculative a feature idea that we are undecided about label Jan 11, 2024
@nickrobinson251
Copy link
Collaborator Author

After #170 (+ #179) we just parse the file to do all selection/filtering of @testitems (by name or tags)

I'm closing this issue as done and have opened an issue for the remaining idea from this thread: #181

@nickrobinson251 nickrobinson251 added the perf About improving the performance of the package label Sep 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
perf About improving the performance of the package speculative a feature idea that we are undecided about
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants