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

Parsing error for precompiled testing packages #597

Closed
tonobo opened this issue Dec 13, 2017 · 3 comments
Closed

Parsing error for precompiled testing packages #597

tonobo opened this issue Dec 13, 2017 · 3 comments

Comments

@tonobo
Copy link

tonobo commented Dec 13, 2017

I have an binary which requires an external testing but i'm currently unable to do so with coverage tracking enabled. Please take a look at the following samples.

Creating test binary: go test -covermode=count -coverpkg ./... -o test-bin

Sample 1.

$ sudo ./test-bin -test.coverprofile=moo.cov pv allocation disable /dev/mapper/sda5_crypt
# Expected  => []string{"/dev/mapper/sda5_crypt"}
#      Got  => []string{}

Sample 2.

$ sudo ./test-bin pv allocation disable /dev/mapper/sda5_crypt
# Expected  => []string{"/dev/mapper/sda5_crypt"}
#      Got  => []string{"/dev/mapper/sda5_crypt"}
@shin-
Copy link

shin- commented May 1, 2018

I'm currently having the same issue.

@tonobo Were you ever able to find a workaround?

@eparis
Copy link
Collaborator

eparis commented May 2, 2018

This patch to github.com/spf13/pflag seems to make it work:

diff --git a/flag.go b/flag.go
index 5eadc84..31f2cbd 100644
--- a/flag.go
+++ b/flag.go
@@ -990,11 +990,11 @@ func (f *FlagSet) parseLongArg(s string, args []string, fn parseFunc) (a []strin
 }
 
 func (f *FlagSet) parseSingleShortArg(shorthands string, args []string, fn parseFunc) (outShorts string, outArgs []string, err error) {
+       outArgs = args
        if strings.HasPrefix(shorthands, "test.") {
                return
        }
 
-       outArgs = args
        outShorts = shorthands[1:]
        c := shorthands[0]
 

@shin-
Copy link

shin- commented May 2, 2018

@eparis Thanks, that worked for me!

shin- added a commit to shin-/pflag that referenced this issue May 2, 2018
eparis pushed a commit to spf13/pflag that referenced this issue Jun 1, 2018
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

No branches or pull requests

3 participants