-
Notifications
You must be signed in to change notification settings - Fork 19
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
[WIP] Create a framework to exercise the go test
output
#14
base: master
Are you sure you want to change the base?
Conversation
What do you think? I was missing a way to properly test all the features of the If you think this is a good idea, I will add unit tests for the features already there - error handling, sub-tests, parsing errors, etc. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not crazy about running go
from the test.. Couldn't we change the infrastructure to take a testing.TB and provide an instrumented implementation for the purposes of testing?
That was my first idea actually, but I found it unsatisfying for two reasons. The first reason is that it's quite a large amount of work. Not just the interface change, which is minor; the implementation of a mock The second reason (and for me the main reason) is that I really want to test the output produced by failing
It looks to me like the amount of refactoring / mock injection needed to test these aspects is unreasonably large compared to the (relative) simplicity of the approach I took here instead. What do you think? |
Prior to this patch, there was no way to exercise the behavior of `-rewrite` nor how errors and sub-tests would be reported in the output of `go test -v`. This patch introduces such "reflective" tests, where a test can compare the output and modified file through running `go test` recursively.
4dcde51
to
7cec255
Compare
I was thinking the implementation would still use a *testing.T underneath (the one from our test), you'd just intercept some of the calls we care about (Error,Fatal). I might be missing some subtleties though, I'll leave it to you to decide since you spent more time thinking about this. I don't have strong objections given that it's testing code and not even in the main repo. I'll look more closely at the final change. |
I'd like to understand more: how do you mock something that properly casts down to |
|
Oh TIL. Ok I'll experiment with that. |
It wouldn't cast down, but it would implement testing.TB. Hm though I guess that doesn't have everything we need (eg Run). We'd need to define our own interface and that will make the API more complicated. Your solution is probably better. |
It doesn't have |
Prior to this patch, there was no way to exercise the behavior of
-rewrite
nor how errors and sub-tests would be reported in theoutput of
go test -v
.This patch introduces such "reflective" tests, where a test can
compare the output and modified file through running
go test
recursively.
This change is