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

expect_lint() error for missing {testthat} should reference which function called it #2585

Open
MichaelChirico opened this issue May 27, 2024 · 6 comments · May be fixed by #2587
Open

expect_lint() error for missing {testthat} should reference which function called it #2585

MichaelChirico opened this issue May 27, 2024 · 6 comments · May be fixed by #2587

Comments

@MichaelChirico
Copy link
Collaborator

          ideally this will just reference the actual call for clarity, but we can save that for later.

Originally posted by @MichaelChirico in #2582 (comment)

@F-Noelle
Copy link
Contributor

I am thinking something along the line of:

who_called_me <- as.character(sys.call(sys.parent())) |>
  stringr::str_split(stringr::fixed("("))
who_called_me <- who_called_me[[1]]

I am not sure if there would be a more elegant way to get this info which function did the original call.

Or you create a third unexported function called "expect_lint_logic" who does all the heavy lifting and has an addition parameter which is simply the name of the calling function.

Any better ideas?

I wanted to write the expect_no_lint_linter as well, given that this should be a fairly easy linter to write as it just needs to check for NULL on the second positional parameter of the function, as far as I understood the xpath logic

@MichaelChirico
Copy link
Collaborator Author

I wanted to write the expect_no_lint_linter as well, given that this should be a fairly easy linter to write as it just needs to check for NULL on the second positional parameter of the function, as far as I understood the xpath logic

Follow #1874 for some discussion about how exactly to go about that. We might want something more generalizable than just expect_no_lint_linter().

@AshesITR
Copy link
Collaborator

Regarding the caller logic, you can look at the code of Linter() which auto-names using a similar approach.

@MichaelChirico
Copy link
Collaborator Author

I would use:

tail(as.character(sys.call(sys.parent())[[1]]), 1L)

That covers lintr::expect_no_lint() and plain expect_no_lint().

The lintr:::linter_auto_name() logic might be overkill in this case.

Alternatively, we can just copy-paste the requireNamespace() call into the body of expect_no_lint().

@AshesITR
Copy link
Collaborator

Alternatively, we can just copy-paste the requireNamespace() call into the body of expect_no_lint().

This is the way to go I think.

@F-Noelle
Copy link
Contributor

Probably the most simple solution indeed.

@F-Noelle F-Noelle linked a pull request May 28, 2024 that will close this issue
@IndrajeetPatil IndrajeetPatil linked a pull request May 31, 2024 that will close this issue
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 a pull request may close this issue.

3 participants