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

Error not recorded if it happens in expect_message() #380

Closed
wants to merge 7 commits into from

Conversation

krlmlr
Copy link
Member

@krlmlr krlmlr commented Mar 1, 2016

Adapted reporter test, currently failing.

Closes #387 (=includes it).

@krlmlr krlmlr force-pushed the feature/error-in-message branch 4 times, most recently from 84f0b89 to 5f14798 Compare March 1, 2016 15:41
@krlmlr
Copy link
Member Author

krlmlr commented Mar 1, 2016

The error is recorded, it's just not printed, because it's handled when sink() is still active. This also affects expect_warning() and expect_output(). I've added the resulting differences to this PR. Please advise.

@krlmlr
Copy link
Member Author

krlmlr commented Mar 1, 2016

Seems tricky. Best idea so far: Use a new CachingReporter in evaluate_promise() that defers actual reporting until the sink is closed again. Will try.

@krlmlr
Copy link
Member Author

krlmlr commented Mar 1, 2016

Works for me now, PTAL. I'm not inheriting from SilentReporter because I need to forward context and test, too.

2: g() at reporters/tests.R:32
3: h() at reporters/tests.R:33
4: stop("!") at reporters/tests.R:34
1: expect_message(f(), NA) at reporters/tests.R:36
Copy link
Member

Choose a reason for hiding this comment

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

You'll also need to tweak the constants in test_code() to avoid the extra stuff here

Copy link
Member Author

Choose a reason for hiding this comment

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

Done, requires #387 (already included in here).

@krlmlr krlmlr force-pushed the feature/error-in-message branch 2 times, most recently from 53f3714 to 6cce66e Compare March 1, 2016 21:26
@krlmlr
Copy link
Member Author

krlmlr commented Mar 2, 2016

Depends on #387 (which needs #390); let's wait for these two.

@hadley
Copy link
Member

hadley commented Mar 2, 2016

Can you please rebase/merge and I'll give a detailed review

@krlmlr krlmlr force-pushed the feature/error-in-message branch from 6cce66e to afd51c0 Compare March 2, 2016 17:05
@@ -18,7 +18,7 @@ stop

6. Error: Error:3 (@tests.R#36) ------------------------------------------------
!
1: f() at reporters/tests.R:36
1: f()
Copy link
Member Author

Choose a reason for hiding this comment

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

Rebased. I wonder if we can do anything about this srcref loss here.

@hadley
Copy link
Member

hadley commented Mar 3, 2016

I think I need a bit more info on this problem. Your test:

reporter <- with_reporter("silent", {
  test_that("", expect_warning(stop()))
})
expect_equal(length(reporter$expectations()), 1)
expect_true(expectation_error(reporter$expectations()[[1L]]))

Currently works for me, and that makes sense - the error causes a premature exit from evaluate_promise(), so by the time the reporter prints something the sink has been terminated.

It's not clear your patch preserves the desirable behaviour of suppressing warnings when called from expect_warning(), while propagating them when called from expect_message(). I think what we actually need is finer control over evaluate promise so we can opt out of capturing messages or warnings. I'll tweak evaluate_promise() to do this.

Can you have a go at creating a simple test case that illustrates the current problem?

hadley added a commit that referenced this pull request Mar 3, 2016
@krlmlr - I'm not sure if this actually fixes the problem you were seeing, but we should be doing this anyway.

#380
@krlmlr krlmlr force-pushed the feature/error-in-message branch from afd51c0 to 724d192 Compare March 3, 2016 23:13
Kirill Müller added 5 commits March 4, 2016 00:14
with update of golden files to show the problem
so that reporter output doesn't interfere with testing
@krlmlr krlmlr force-pushed the feature/error-in-message branch from 724d192 to 27536b7 Compare March 3, 2016 23:15
@krlmlr
Copy link
Member Author

krlmlr commented Mar 3, 2016

Summary of commits:

  • fe2ea0e is the demo
  • 133c75e is the fix, which solves the issue (with minor flaws)
  • 27536b7 is the correction of the call stack, which (almost) restores the original behavior.

Could you sketch an example where this implementation would misbehave?

…ssage

Includes an update of the test results.
@krlmlr
Copy link
Member Author

krlmlr commented Mar 10, 2016

I don't like this anymore either: My new DebugReporter (internal WIP) doesn't work here. Perhaps we can teach evaluate_promise() to temporarily close its sink when a reporter is activated.

@krlmlr krlmlr closed this Mar 10, 2016
@hadley
Copy link
Member

hadley commented Mar 10, 2016

I think the way forward is to break evaluate_promise() into 3 separate pieces, one that captures outputs, one that captures warnings, and one that captures messages.

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.

2 participants