Skip to content
This repository has been archived by the owner on Jul 18, 2019. It is now read-only.

Add gometalinter tests #96

Merged
merged 20 commits into from
Feb 17, 2017
Merged

Add gometalinter tests #96

merged 20 commits into from
Feb 17, 2017

Conversation

ghost
Copy link

@ghost ghost commented Feb 7, 2017

Trying out some of the other tests we want in .taskcluster.yml. There will likely be more added to this PR shortly.

@djmitche
Copy link
Contributor

djmitche commented Feb 8, 2017

The TaskCluster task says:

# cd /go/src/github.com/taskcluster/taskcluster-cli; git pull --ff-only

I have no idea where that could have come from, though.. does gometalinter do a git pull??? @walac?

@ghost
Copy link
Author

ghost commented Feb 9, 2017

Yes, seems weird. I have some things I'm going to mess around with tomorrow to troubleshoot. This is my first time seeing this type of error though, and I have run many similar commands in task creator.

@ghost
Copy link
Author

ghost commented Feb 9, 2017

The problem was in trying to checkout and then 'go get -u ./...' in that order. Being on a detached head messed this up. So now we get all our packages first, then checkout, then do the tests.

This wasn't a problem before because I was testing on branches before PR #67 was merged and didn't need 'go get -u ./...' at all. But after this merge I was getting import errors. So, good problem to have now, as .taskcluster.yml will be more robust for future changes.

@ghost
Copy link
Author

ghost commented Feb 9, 2017

This has some extra test features, using both 'gometalinter' and adding to 'go test':

Gometalinter:
This can check for a variety of Go warning and errors. We've included:
gotype - Syntactic and semantic analysis similar to the Go compiler.
golint - Google's (mostly stylistic) linter.
deadcode - Finds unused code. -- Just realized I've got this one (ironically) enabled twice.
staticcheck - Statically detect bugs, both obvious and subtle ones.
misspell - Finds commonly misspelled English words.
go vet --shadow - Reports variables that may have been unintentionally shadowed
gosimple - Report simplifications in code.
(Taken from: https://github.com/alecthomas/gometalinter/blob/master/README.md)

Test flags:
-v (verbose): logs and prints all tests
-race: checks for race conditions

.taskcluster.yml Outdated
&& go get -u github.com/alecthomas/gometalinter
&& gometalinter --install
&& go get -u ./...
&& git checkout {{ event.head.sha }}
Copy link
Contributor

Choose a reason for hiding this comment

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

These lines have me a little worried -- it's running go get -u on the default branch (the one go get -t github.com/taskcluster/taskcluster-cli/... found), then switching to the commit we want to test. If those have different dependent packages, would this still work?

@walac this is pretty far over my golang head -- can you comment here?

Copy link
Contributor

Choose a reason for hiding this comment

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

This is to make gometalinter happy, as it doesn't look for packages inside vendor. Unfortunately, there is no much more we can do about it, since if we try to do go get after git checkout, it will fail due to the repo being in a detached state.

Copy link
Contributor

Choose a reason for hiding this comment

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

Does that mean that we're running our tests against the latest versions of everything, rather than the vendored versions? Or is this just updating gometalinter's own dependencies?

Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be possible to use gometalinter --vendor?

Copy link
Contributor

Choose a reason for hiding this comment

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

@djmitche nope, tests run under vendor, just gometalinter

@t0xicCode oh, I was not aware of vendor option, thanks. @lteigrob could you please give it a try?

Copy link
Author

Choose a reason for hiding this comment

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

Yep, I'll add in that flag right now.

t0xicCode
t0xicCode previously approved these changes Feb 10, 2017
Copy link
Contributor

@t0xicCode t0xicCode left a comment

Choose a reason for hiding this comment

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

Looks good to me 🚢

@t0xicCode t0xicCode dismissed their stale review February 10, 2017 14:32

Changing review based on @djmitche's comments

.taskcluster.yml Outdated
&& go test -v -race ./...
&& gometalinter --disable-all --enable=gotype --enable=golint
--enable=deadcode --enable=staticcheck --enable=deadcode
--enable=misspell --enable=vet --enable=vetshadow --enable=gosimple
Copy link
Contributor

Choose a reason for hiding this comment

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

Also, this doesn't run on any of the sub-packages.

Copy link
Author

Choose a reason for hiding this comment

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

Shoot. Right you are.

Copy link
Contributor

@t0xicCode t0xicCode left a comment

Choose a reason for hiding this comment

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

A few adjustments (see comments)

Copy link
Contributor

@t0xicCode t0xicCode left a comment

Choose a reason for hiding this comment

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

A few more points :)

.taskcluster.yml Outdated
&& go test ./...
&& go get -u github.com/alecthomas/gometalinter
&& gometalinter --install --force
&& go get -u ./...
Copy link
Contributor

Choose a reason for hiding this comment

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

We shouldn't need this anymore.

Copy link
Author

Choose a reason for hiding this comment

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

You're probably right, but what about with the added race condition check?

Copy link
Contributor

Choose a reason for hiding this comment

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

go test if fully compatible with vendoring. It's kinda funny the way it does it. When the code is compiled to be tested, the toolchain will pull the dependencies from vendor/, as expected. Then, when go test runs the tests, it will actually recurse into the folders in vendor/, but because govendor removes all of the test files from dependencies, no tests are run.

In essence, it matches the behaviour of un-vendored code.

.taskcluster.yml Outdated
&& go get -u ./...
&& git checkout {{ event.head.sha }}
&& go test -v -race ./...
&& gometalinter --vendor --disable-all --enable=gotype --enable=golint
Copy link
Contributor

Choose a reason for hiding this comment

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

But we might have to run go install ./... before this. gotype uses the compiled data that is generated by install to run its checks.

@ghost
Copy link
Author

ghost commented Feb 10, 2017

Perhaps for discussion in the meeting:

Now that I'm checking subdirectories with gometalinter, my task is failing, I believe due to warnings. You can see this here:
https://tools.taskcluster.net/task-inspector/#d8c67_q0SLCiR61kYcU1Kw/0
(Go to Runs->Run0 and then Logs, and scrolling down you can see warnings with the type given in parentheses on the right of each)
where this task is the same but I've just omitted the specific gometalinter tests giving the warnings, and it's fine:
https://tools.taskcluster.net/task-inspector/#WH-069lNSCqkXdvOJibOCQ/0

From what I can tell this is due to gometalinter setting the exit status to 1 for any such warning. Is this what we want? If so, we'd just have to go through and fix up all these warnings to get everything up to this level of strictness. Alternatively, we allow these warnings but figure out how to keep exit status as zero. I'm not sure there's a way to do this using gometalinter as-is.

I'm sure it will fail, but I'll push the change for discussion purposes :) I'd like to talk more about @t0xicCode's comments too

@t0xicCode
Copy link
Contributor

I'm actually building a PR to fix most of the linting issues.

@ghost
Copy link
Author

ghost commented Feb 10, 2017

Oh, perfect!

@ghost
Copy link
Author

ghost commented Feb 13, 2017

Nice, I'll just figure out the go install vs. go get -u issue and we should be good

@t0xicCode
Copy link
Contributor

@lteigrob Could you rebase on top of master? I've merged the linting fixes that you approved :)

@ghost
Copy link
Author

ghost commented Feb 13, 2017

One does not simply git rebase it... @t0xicCode, I also had to fetch and merge with the remote gometalinter branch. Not sure if that's normal. I've looked at the code and I don't think I killed anything.

@t0xicCode
Copy link
Contributor

I may have managed to do it 😄 but I manually removed a bunch of duplicated commits.

Copy link
Contributor

@t0xicCode t0xicCode left a comment

Choose a reason for hiding this comment

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

Single point

.taskcluster.yml Outdated
&& go get -u github.com/alecthomas/gometalinter
&& gometalinter --install --force
&& go install ./...
&& git checkout {{ event.head.sha }}
Copy link
Contributor

Choose a reason for hiding this comment

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

You should checkout before running go install or make, in case the dependencies changed.

@t0xicCode
Copy link
Contributor

t0xicCode commented Feb 13, 2017

Also, you'll have to do a force pull (git fetch && git reset --hard @{upstream}) before continuing.

.taskcluster.yml Outdated
&& go install ./...
&& git checkout {{ event.head.sha }}
&& go test -v -race ./...
&& gometalinter --vendor --disable-all --enable=gotype --enable=golint
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider --skip=apis/ to skip the auto-generated source (for #100)

@ghost
Copy link
Author

ghost commented Feb 17, 2017

Cool, this sequence seems to be working now. I'm sure @djmitche will be happy :)

Aaand I got excited and forgot to do the force pull :( If things need to be fixed we can discuss tomorrow.

Finally, I'm working on getting '--skip=apis' to work. Like everything else since adding in gometalinter, it's not as simple as it seems.

@djmitche
Copy link
Contributor

Success on Taskcluster!! Should we merge this?

Copy link
Contributor

@t0xicCode t0xicCode left a comment

Choose a reason for hiding this comment

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

This seems good. I'd still like to see the code rebased and the duplicate commits removed to keep history clean. @lteigrob you can run git rebase -i master to remove any of the duplicates and reorder the commits.

@djmitche
Copy link
Contributor

I can just squash it when merging.. that'll be easier, I think.

@djmitche djmitche merged commit 711b3a2 into master Feb 17, 2017
@t0xicCode
Copy link
Contributor

t0xicCode commented Feb 17, 2017 via email

@ghost ghost deleted the gometalinter branch February 17, 2017 18:57
@ghost ghost mentioned this pull request Feb 17, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants