[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) {
|
func TestMatch(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
initTests()
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
m Matcher
|
m Matcher
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package complete
|
package complete
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -9,12 +8,7 @@ import (
|
||||||
|
|
||||||
func TestPredicate(t *testing.T) {
|
func TestPredicate(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
initTests()
|
||||||
// Change to tests directory for testing completion of files and directories
|
|
||||||
err := os.Chdir("./tests")
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
|
|
14
run_test.go
14
run_test.go
|
@ -8,19 +8,7 @@ import (
|
||||||
|
|
||||||
func TestCompleter_Complete(t *testing.T) {
|
func TestCompleter_Complete(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
initTests()
|
||||||
// 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)
|
|
||||||
}
|
|
||||||
|
|
||||||
c := Command{
|
c := Command{
|
||||||
Sub: map[string]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