diff options
author | Felix Lange <fjl@twurst.com> | 2016-01-26 06:35:25 +0800 |
---|---|---|
committer | Felix Lange <fjl@twurst.com> | 2016-01-26 06:35:25 +0800 |
commit | f2ab351e8d3b0a4e569ce56f6a4f17725ca5ba65 (patch) | |
tree | 424c1067530fd4013234983549b03b42aa994db2 /logger/glog/glog_test.go | |
parent | 6e6931ef73c68d1a8ae45475f7719bdc962cb2c1 (diff) | |
parent | e4d794851b713b5a22147c570963ff76ec26c7d0 (diff) | |
download | go-tangerine-f2ab351e8d3b0a4e569ce56f6a4f17725ca5ba65.tar go-tangerine-f2ab351e8d3b0a4e569ce56f6a4f17725ca5ba65.tar.gz go-tangerine-f2ab351e8d3b0a4e569ce56f6a4f17725ca5ba65.tar.bz2 go-tangerine-f2ab351e8d3b0a4e569ce56f6a4f17725ca5ba65.tar.lz go-tangerine-f2ab351e8d3b0a4e569ce56f6a4f17725ca5ba65.tar.xz go-tangerine-f2ab351e8d3b0a4e569ce56f6a4f17725ca5ba65.tar.zst go-tangerine-f2ab351e8d3b0a4e569ce56f6a4f17725ca5ba65.zip |
Merge pull request #2136 from fjl/glog-prefix
logger/glog: improve vmodule
Diffstat (limited to 'logger/glog/glog_test.go')
-rw-r--r-- | logger/glog/glog_test.go | 51 |
1 files changed, 36 insertions, 15 deletions
diff --git a/logger/glog/glog_test.go b/logger/glog/glog_test.go index 0fb376e1f..30861a48d 100644 --- a/logger/glog/glog_test.go +++ b/logger/glog/glog_test.go @@ -180,7 +180,7 @@ func TestHeader(t *testing.T) { pid = 1234 Info("test") var line int - format := "I0102 15:04:05.067890 1234 glog_test.go:%d] test\n" + format := "I0102 15:04:05.067890 logger/glog/glog_test.go:%d] test\n" n, err := fmt.Sscanf(contents(infoLog), format, &line) if n != 1 || err != nil { t.Errorf("log format error: %d elements, error %s:\n%s", n, err, contents(infoLog)) @@ -253,7 +253,7 @@ func TestV(t *testing.T) { func TestVmoduleOn(t *testing.T) { setFlags() defer logging.swap(logging.newBuffers()) - logging.vmodule.Set("glog_test=2") + logging.vmodule.Set("glog_test.go=2") defer logging.vmodule.Set("") if !V(1) { t.Error("V not enabled for 1") @@ -290,22 +290,43 @@ func TestVmoduleOff(t *testing.T) { } } +var patternTests = []struct{ input, want string }{ + {"foo/bar/x.go", ".*/foo/bar/x\\.go$"}, + {"foo/*/x.go", ".*/foo(/.*)?/x\\.go$"}, + {"foo/*", ".*/foo(/.*)?/[^/]+\\.go$"}, +} + +func TestCompileModulePattern(t *testing.T) { + for _, test := range patternTests { + re, err := compileModulePattern(test.input) + if err != nil { + t.Fatalf("%s: %v", err) + } + if re.String() != test.want { + t.Errorf("mismatch for %q: got %q, want %q", test.input, re.String(), test.want) + } + } +} + // vGlobs are patterns that match/don't match this file at V=2. var vGlobs = map[string]bool{ // Easy to test the numeric match here. - "glog_test=1": false, // If -vmodule sets V to 1, V(2) will fail. - "glog_test=2": true, - "glog_test=3": true, // If -vmodule sets V to 1, V(3) will succeed. - // These all use 2 and check the patterns. All are true. - "*=2": true, - "?l*=2": true, - "????_*=2": true, - "??[mno]?_*t=2": true, - // These all use 2 and check the patterns. All are false. - "*x=2": false, - "m*=2": false, - "??_*=2": false, - "?[abc]?_*t=2": false, + "glog_test.go=1": false, // If -vmodule sets V to 1, V(2) will fail. + "glog_test.go=2": true, + "glog_test.go=3": true, // If -vmodule sets V to 1, V(3) will succeed. + + // Import path prefix matching + "logger/glog=1": false, + "logger/glog=2": true, + "logger/glog=3": true, + + // Import path glob matching + "logger/*=1": false, + "logger/*=2": true, + "logger/*=3": true, + + // These all use 2 and check the patterns. + "*=2": true, } // Test that vmodule globbing works as advertised. |