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

get rid of the test.xxx flags in build version #94

Open
arkbriar opened this issue Apr 29, 2016 · 1 comment
Open

get rid of the test.xxx flags in build version #94

arkbriar opened this issue Apr 29, 2016 · 1 comment

Comments

@arkbriar
Copy link

arkbriar commented Apr 29, 2016

Importing "testing" in files whose name doesn't end _test.go will cause a lot of test.xxx flags in those go program which have both imported "flag" and "github.com/jmcvetta/neoism".

Here is the example:

package main

import (
    "os"
    "fmt"
    "flag"
    "github.com/jmcvetta/neoism"
)

func main() {
    if file, err := os.Open("."); err != nil {
        panic(err)
    } else {
        dir, err := file.Readdir(-1)
        if err != nil {
            panic(err)
        }

        for _, fi := range dir {
            fmt.Println(fi.Name())
        }
    }

    db, _ := neoism.Connect("http://neo4j:xxx@localhost:7474/db/data")
    fmt.Println(db)
    flag.Parse()
}
> ./test
......
Usage of ./test:
  -httptest.serve string
        if non-empty, httptest.NewServer serves on this address and blocks
  -test.bench string
        regular expression to select benchmarks to run
  -test.benchmem
        print memory allocations for benchmarks
  -test.benchtime duration
        approximate run time for each benchmark (default 1s)
  -test.blockprofile string
        write a goroutine blocking profile to the named file after execution
  -test.blockprofilerate int
        if >= 0, calls runtime.SetBlockProfileRate() (default 1)
  -test.count n
        run tests and benchmarks n times (default 1)
......

And I got the "httptest.serve" left even if I removed all the test.go files in neoism.
This is really annoying, so I hope it will be fixed soon.
Thanks for your effort.

ArkBriar
2016-4-29

@jmcvetta
Copy link
Owner

Please feel free to submit a PR correcting this problem.

co0p added a commit to co0p/neoism that referenced this issue Feb 25, 2018
Importing the testing package in a file, which is used by the main binary, will pollute the flags package with testing help usage messages. This hinders the usage of the neoism package in a cli application. The file benchmark_test*.go are loading the testing package and are therefore responsible for the flag pollution. To exclude the benchmark_connect helpers one can suffix the files with _test. This will ensure that the benchmark_connect helpers are only loaded during testing and do not pollute the main binary. Another solution would be to introduce a neoism_test package, which would result a massive code reorganization.
co0p added a commit to co0p/neoism that referenced this issue Feb 25, 2018
Importing the testing package in a file, which is used by the main binary, will pollute the flags package with testing help usage messages. This hinders the usage of the neoism package in a cli application. The file benchmark_test*.go are loading the testing package and are therefore responsible for the flag pollution. To exclude the benchmark_connect helpers one can suffix the files with _test. This will ensure that the benchmark_connect helpers are only loaded during testing and do not pollute the main binary. Another solution would be to introduce a neoism_test package, which would result a massive code reorganization.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants