Skip to content

Commit

Permalink
x/log TestBasic
Browse files Browse the repository at this point in the history
  • Loading branch information
xushiwei committed Feb 5, 2024
1 parent 9a82de4 commit 5f5e831
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 2 deletions.
16 changes: 16 additions & 0 deletions log/logext.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
Copyright 2019 Qiniu Limited (qiniu.com)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package log

import (
Expand Down
56 changes: 54 additions & 2 deletions log/logext_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
//go:build unix
// +build unix

/*
Copyright 2019 Qiniu Limited (qiniu.com)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package log

import (
Expand All @@ -10,6 +26,42 @@ import (
"testing"
)

func TestBasicf(t *testing.T) {
doSth := func(lvl int) {
old := Std.Level
defer func() {
Std.Level = old
}()
Std.Level = lvl
fns := []func(format string, v ...interface{}){
Debugf, Infof, Warnf, Errorf,
}
for _, fn := range fns {
fn("log %d\n", 100)
}
}
doSth(Ldebug)
doSth(Lfatal)
}

func TestBasic(t *testing.T) {
doSth := func(lvl int) {
old := Std.Level
defer func() {
Std.Level = old
}()
Std.Level = lvl
fns := []func(v ...interface{}){
Debug, Info, Warn, Error,
}
for _, fn := range fns {
fn("log", 100)
}
}
doSth(Ldebug)
doSth(Lfatal)
}

func TestFormatFile(t *testing.T) {
tcs := []struct {
file string
Expand Down Expand Up @@ -60,7 +112,7 @@ func TestLongFile(t *testing.T) {
logx := New(&out, Std.Prefix(), Llongfile|Llevel|LstdFlags)
logx.Info("hello")
result := out.String()
suffix := "x/log/logext_test.go:61: hello\n"
suffix := "x/log/logext_test.go:113: hello\n"
if !strings.HasSuffix(result, suffix) {
t.Errorf("Llongfile mode, logx.Info() = %v, which expected to include suffix %v ", result, suffix)
}
Expand All @@ -71,7 +123,7 @@ func TestShortFile(t *testing.T) {
logx := New(&out, Std.Prefix(), Lshortfile|Llevel|LstdFlags)
logx.Info("hello")
result := out.String()
suffix := "logext_test.go:72: hello\n"
suffix := "logext_test.go:124: hello\n"
if !strings.HasSuffix(result, suffix) {
t.Errorf("Lshortfile mode, logx.Info() = %v, which expected to include suffix %v ", result, suffix)
}
Expand Down
16 changes: 16 additions & 0 deletions log/logext_windows_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
//go:build windows
// +build windows

/*
Copyright 2019 Qiniu Limited (qiniu.com)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package log

import (
Expand Down

0 comments on commit 5f5e831

Please sign in to comment.