[test] chdir and set logger only once
This commit is contained in:
parent
8d6ebaa183
commit
f740f61fbb
|
@ -4,6 +4,7 @@ import "testing"
|
|||
|
||||
func TestMatch(t *testing.T) {
|
||||
t.Parallel()
|
||||
initTests()
|
||||
|
||||
tests := []struct {
|
||||
m Matcher
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package complete
|
||||
|
||||
import (
|
||||
"os"
|
||||
"sort"
|
||||
"strings"
|
||||
"testing"
|
||||
|
@ -9,12 +8,7 @@ import (
|
|||
|
||||
func TestPredicate(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Change to tests directory for testing completion of files and directories
|
||||
err := os.Chdir("./tests")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
initTests()
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
|
|
14
run_test.go
14
run_test.go
|
@ -8,19 +8,7 @@ import (
|
|||
|
||||
func TestCompleter_Complete(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Set debug environment variable so logs will be printed
|
||||
if testing.Verbose() {
|
||||
os.Setenv(envDebug, "1")
|
||||
// refresh the logger with environment variable set
|
||||
Log = getLogger()
|
||||
}
|
||||
|
||||
// Change to tests directory for testing completion of files and directories
|
||||
err := os.Chdir("./tests")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
initTests()
|
||||
|
||||
c := Command{
|
||||
Sub: map[string]Command{
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
package complete
|
||||
|
||||
import (
|
||||
"os"
|
||||
"sync"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var once = sync.Once{}
|
||||
|
||||
func initTests() {
|
||||
once.Do(func() {
|
||||
// Set debug environment variable so logs will be printed
|
||||
if testing.Verbose() {
|
||||
os.Setenv(envDebug, "1")
|
||||
// refresh the logger with environment variable set
|
||||
Log = getLogger()
|
||||
}
|
||||
|
||||
// Change to tests directory for testing completion of files and directories
|
||||
err := os.Chdir("./tests")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
})
|
||||
}
|
Loading…
Reference in New Issue