oleiade / lane

Generic PriorityQueues, Queues, Stacks, and Deque data structures for Go
https://pkg.go.dev/github.com/oleiade/lane#pkg-types
MIT License
877 stars 76 forks source link

Rename test_helpers.go to helpers_test.go #15

Closed anantn closed 8 years ago

anantn commented 8 years ago

This avoids polluting the flags of all packages that depend on this one.

STR: Run this program before and after this change:

package main

import (
    "flag"
    "fmt"

    "github.com/oleiade/lane"
)

var myflag int

func main() {
    flag.IntVar(&myflag, "myflag", 1, "my flag")
    flag.Parse()

    q := lane.NewPQueue(10)
    q.Push(1, 1)
    fmt.Printf("Done!")
}

Before:

$ lanetest -h
Usage of lanetest:
  -myflag int
        my flag (default 1)
  -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)
  -test.coverprofile string
        write a coverage profile to the named file after execution
  -test.cpu string
        comma-separated list of number of CPUs to use for each test
  -test.cpuprofile string
        write a cpu profile to the named file during execution
  -test.memprofile string
        write a memory profile to the named file after execution
  -test.memprofilerate int
        if >=0, sets runtime.MemProfileRate
  -test.outputdir string
        directory in which to write profiles
  -test.parallel int
        maximum test parallelism (default 8)
  -test.run string
        regular expression to select tests and examples to run
  -test.short
        run smaller test suite to save time
  -test.timeout duration
        if positive, sets an aggregate time limit for all tests
  -test.trace string
        write an execution trace to the named file after execution
  -test.v
        verbose: print additional output

After:

$ lanetest -h
Usage of lanetest:
  -myflag int
        my flag (default 1)
oleiade commented 8 years ago

Hi @anantn

If my memory is correct, the test_helpers where named like that to avoid being considered as tests by the go compiler when running go test. But I might be wrong, please correct me if I'm wrong. Please also note that I'm open to rename it!

anantn commented 8 years ago

@oleiade It's safe to have a test file that has no tests in it (like helpers_test.go). The problem is when you have a file that imports the testing package but isn't recognized as a test by Go.

All of the flags introduced by the testing package now leak into your main package (and everyone who depends on it!).

So my point is that you actually do want Go to recognize the helpers as a test file, not as a regular file that's part of your package (because you call import testing inside it).

oleiade commented 8 years ago

Sounds reasonable to me then! Thanks for the info, I learned something today :-) Let's merge that baby. Cheers