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

Add stage argument to tell checking functions what type of check is being performed #610

Merged
merged 7 commits into from
Nov 17, 2021

Conversation

rossellhayes
Copy link
Contributor

@rossellhayes rossellhayes commented Nov 12, 2021

Calls to try_checker() within evaluate_exercise() gain the argument stage – one of "code_check", "error_check", or "check" – which is passed to the checking function to indicate which kind of check is being performed.

This simplifies the implementation of custom checking functions, which no longer need to infer the stage from other arguments. For example, the example function in the learnr docs becomes:

custom_checker <- function(label, user_code, check_code, envir_result, evaluate_result, last_value, stage, ...) {
  # this is a code check
  if (stage == "code_check") {
    if (is_bad_code(user_code, check_code)) {
      return(list(message = "I wasn't expecting that code", correct = FALSE))
    }
    return(list(message = "Nice code!", correct = TRUE))
  }
  # this is a fully evaluated chunk check
  if (is_bad_result(last_value, check_code)) {
    return(list(message = "I wasn't expecting that result", correct = FALSE))
  }
  list(message = "Great job!", correct = TRUE, location = "append")
}

For backwards compatibility, if the function signature of the checking function does not include stage or ..., stage is not passed.

Closes #567.

@rossellhayes rossellhayes self-assigned this Nov 12, 2021
@rossellhayes rossellhayes added the type: enhancement Adds a new, backwards-compatible feature label Nov 12, 2021
Copy link
Member

@gadenbuie gadenbuie left a comment

Choose a reason for hiding this comment

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

Looks great, thank you! I think the changes in the docs do a good job showcasing the improvement!

R/exercise.R Outdated
)
message(msg)
rlang::return_from(rlang::caller_env(), exercise_result_error(msg))
# Don't throw an error if the only missing argument is `stage`
Copy link
Member

Choose a reason for hiding this comment

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

It'd be better if this comment explained why we're making the exception for stage.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How does 5b36cf1 look?

@gadenbuie
Copy link
Member

Oh and let's bump the dev version for this one

@rossellhayes
Copy link
Contributor Author

@gadenbuie Dev version bumped! Should this go in the NEWS as a "new feature" or a "minor new feature"?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement Adds a new, backwards-compatible feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Exercise checking should include an argument indicating which type of check is being perfomed
2 participants