Closed sockol closed 4 years ago
LGTM. I'm wondering why travis didn't run for this check.
Does it make sense to add a test to make sure this doesn't break again?
Seems like the build failed but the check never reported the status here. https://travis-ci.org/github/franela/goblin/builds/669559996
Added a test that more closely simulates passing in tags. It should catch if this error shows up again, but I am not sure if this is the best way handle it.
I am not sure why the build failed though. Let's see how this new build will do
This tests is still failing: https://travis-ci.org/github/franela/goblin/builds/670824469#L442-L448
Pushed some changes - the new approach is to move runRegex into matchRegex() It could be improved by not compiling regex every time that function is called by checking if the -goblin.run parameter changed, but this should work for now.
the new approach is to move runRegex into matchRegex() It could be improved by not compiling regex every time that function is called by checking if the -goblin.run parameter changed, but this should work for now.
I don't quite understand why we need to do this. Compiling the regex every time doesn't make a lot of sense since the regex won't change in the execution of the tests. Can we refactor so we make the compilation happen once :pray:
For record keeping - there seem to be a couple ways of working around this:
1) Build that regex on runtime (as you pointed out, not a good workaround)
2) Check if the flag has been set, and compile regex if so
3) Rework the tests to test flags the same way I wrote the TestItRegexExec
test
4) Find a different way to spoof flags in tests
I was able to get option 2 working and adjusted this commit https://github.com/franela/goblin/pull/79/commits/cef5fa09466336ea3edfd1213abe4c152a7b3253 to only compile when the regex param changes.
@sockol I believe I've fixed it here without too many hacky stuff. WDYT? https://github.com/franela/goblin/pull/83
Fixed by #83
Passed in flags like goblin.run are never parsed because the default testing package calls flag.Parse() before goblin calls flag.Parse(), which means the runRegex flag never gets set.
Resolves #74
Test manually: 1) Make a new test file like flag_test.go
2) run
go test -timeout 30s -run ^TestFlagRegex -v -goblin.run=Auth
3) the output will haveAuth 1
andAuth 2
, but notMismatched test
Some exploration of the bug:
run
go test -run ^TestHandleItRegexExec -goblin.run="TestsrunPass"
So this test doesnt parse the "runRegex" since flag.Parse() has been called
If we adjust the condition to be
The command works as expected
But the tests break - the new args passed into the "TestRegex" test are not parsed,
[ runRegex]
is not set