From f080acafaecd86cda001f1ff7e6ae15582185604 Mon Sep 17 00:00:00 2001 From: kyoh86 Date: Fri, 4 Jun 2021 02:25:29 +0900 Subject: [PATCH] highlight filename and line num (#35) * highlight filename and line num but also the following text in theline lose colors. * fix: remove unnecessary followin new-line * fix: use previousStyle to highlight following text of the filenamne * generate * fix test ouput * generate * use [ \t] instead of \s * Revert "use [ \t] instead of \s" This reverts commit 8e416a2d9cb01d25af6a5644636881c59e24d598. * use [ \t] instead of \s * use [^ \t] instead of \S * fix test resource * fix test resource --- Makefile | 1 - config/concat.go | 56 +++++++++++++++++++----------------- config/style.go | 22 ++++++++++---- editor/test/statik/statik.go | 2 +- editor/test/test.go | 20 ++++++------- sample/out_colored.txt | 24 ++++++---------- sample/out_raw.txt | 2 +- 7 files changed, 66 insertions(+), 61 deletions(-) diff --git a/Makefile b/Makefile index 625046b..3fdc2a0 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,6 @@ COMMIT := `git rev-parse HEAD` gen: go run github.com/rakyll/statik -src=./sample -dest editor/test -include='*.txt' -f - gofmt -w editor/test/output_test.go lint: gen golangci-lint run diff --git a/config/concat.go b/config/concat.go index 52b5580..668b6d3 100644 --- a/config/concat.go +++ b/config/concat.go @@ -31,19 +31,21 @@ func concatConfig(base, other *Config) *Config { other = &Config{} } return &Config{ - LabelType: concatLabelType(base.LabelType, other.LabelType), - BuildStyle: concatStyle(base.BuildStyle, other.BuildStyle), - StartStyle: concatStyle(base.StartStyle, other.StartStyle), - PassStyle: concatStyle(base.PassStyle, other.PassStyle), - FailStyle: concatStyle(base.FailStyle, other.FailStyle), - SkipStyle: concatStyle(base.SkipStyle, other.SkipStyle), - FileStyle: concatStyle(base.FileStyle, other.FileStyle), - LineStyle: concatStyle(base.LineStyle, other.LineStyle), - CoverThreshold: concatInt(base.CoverThreshold, other.CoverThreshold), - CoveredStyle: concatStyle(base.CoveredStyle, other.CoveredStyle), - UncoveredStyle: concatStyle(base.UncoveredStyle, other.UncoveredStyle), - Removals: append(base.Removals, other.Removals...), - LeaveTestPrefix: concatBool(base.LeaveTestPrefix, other.LeaveTestPrefix), + LabelType: concatLabelType(base.LabelType, other.LabelType), + BuildStyle: concatStyle(base.BuildStyle, other.BuildStyle), + StartStyle: concatStyle(base.StartStyle, other.StartStyle), + PassStyle: concatStyle(base.PassStyle, other.PassStyle), + FailStyle: concatStyle(base.FailStyle, other.FailStyle), + PassPackageStyle: concatStyle(base.PassPackageStyle, other.PassPackageStyle), + FailPackageStyle: concatStyle(base.FailPackageStyle, other.FailPackageStyle), + SkipStyle: concatStyle(base.SkipStyle, other.SkipStyle), + FileStyle: concatStyle(base.FileStyle, other.FileStyle), + LineStyle: concatStyle(base.LineStyle, other.LineStyle), + CoverThreshold: concatInt(base.CoverThreshold, other.CoverThreshold), + CoveredStyle: concatStyle(base.CoveredStyle, other.CoveredStyle), + UncoveredStyle: concatStyle(base.UncoveredStyle, other.UncoveredStyle), + Removals: append(base.Removals, other.Removals...), + LeaveTestPrefix: concatBool(base.LeaveTestPrefix, other.LeaveTestPrefix), } } @@ -52,19 +54,21 @@ func actualConfig(config *Config) *Config { config = &Config{} } return &Config{ - LabelType: actualLabelType(config.LabelType), - BuildStyle: actualStyle(config.BuildStyle), - StartStyle: actualStyle(config.StartStyle), - PassStyle: actualStyle(config.PassStyle), - FailStyle: actualStyle(config.FailStyle), - SkipStyle: actualStyle(config.SkipStyle), - FileStyle: actualStyle(config.FileStyle), - LineStyle: actualStyle(config.LineStyle), - CoverThreshold: actualInt(config.CoverThreshold), - CoveredStyle: actualStyle(config.CoveredStyle), - UncoveredStyle: actualStyle(config.UncoveredStyle), - Removals: config.Removals, - LeaveTestPrefix: actualBool(config.LeaveTestPrefix), + LabelType: actualLabelType(config.LabelType), + BuildStyle: actualStyle(config.BuildStyle), + StartStyle: actualStyle(config.StartStyle), + PassStyle: actualStyle(config.PassStyle), + FailStyle: actualStyle(config.FailStyle), + PassPackageStyle: actualStyle(config.PassPackageStyle), + FailPackageStyle: actualStyle(config.FailPackageStyle), + SkipStyle: actualStyle(config.SkipStyle), + FileStyle: actualStyle(config.FileStyle), + LineStyle: actualStyle(config.LineStyle), + CoverThreshold: actualInt(config.CoverThreshold), + CoveredStyle: actualStyle(config.CoveredStyle), + UncoveredStyle: actualStyle(config.UncoveredStyle), + Removals: config.Removals, + LeaveTestPrefix: actualBool(config.LeaveTestPrefix), } } diff --git a/config/style.go b/config/style.go index f851cea..e37a6f5 100644 --- a/config/style.go +++ b/config/style.go @@ -40,13 +40,10 @@ type Style struct { Background *Color `json:"background,omitempty" yaml:"background,omitempty"` } -// Apply style To string -func (s *Style) Apply(str string) string { +// ANSI get the ANSI string +func (s *Style) ANSI() aec.ANSI { if s == nil { - return str // when a prevLineStyle is not set, editor/test/test.go calls it in nil - } - if s.Hide != nil && *s.Hide { - return "" + return emptyColor // when a prevLineStyle is not set, editor/test/test.go calls it in nil } ansi := s.Background.B() @@ -72,6 +69,19 @@ func (s *Style) Apply(str string) string { ansi = ansi.With(style.ansi) } } + return ansi +} + +// Apply style To string +func (s *Style) Apply(str string) string { + if s.Hide != nil && *s.Hide { + return "" + } + + ansi := s.ANSI() + if ansi == emptyColor { + return str + } if len(ansi.String()) == 0 { return str diff --git a/editor/test/statik/statik.go b/editor/test/statik/statik.go index 968150c..9a41b94 100644 --- a/editor/test/statik/statik.go +++ b/editor/test/statik/statik.go @@ -8,7 +8,7 @@ import ( func init() { - data := "PK\x03\x04\x14\x00\x08\x00\x08\x00\x84\x80\x9bQ\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0f\x00 \x00out_colored.txtUT\x05\x00\x01x\xb0\xe8_\xac\x95Ao\xda0\x14\xc7\xcf\xedW\xe8\xe5M\xd34\xba\xa9\xc1!b\x94\xdcX7&DU\xaa\x86\xed\x12!\x14\x12\x13,\xec8\xc2\xce6$>\xfc\xe4\xc4\x90\x00\x06\xd2j\x16\x07\x0b?\xff\xdf\xef\xfdm\xbf\xdc\xf8\x8e\xc3n|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\xe8\x03\xf8\xef\xd5\x98\xaa19\xd2\xb9\x04\x1a\xea<\xa5w\x85(\x9fW\x0c4S\xf7(5c\xf7(=\xcfm\xa3\nx>\xde\x08\x1ePZ!\xd7\xb2&\xf4\xf2\x92\xe8O\x8f\x0b\x7f\x82U\x92O\x12\x9e\xff)@rXe\xc9\x1er\xf1\xd1\xd3\xd8\x05\xf4t7^\x0f\x8dY*\xd7*Y\x85\xba\x86\xddO<\x0f7\xb6\x89\xa4X\xab\xf6\xae \x0cqz\xfc\x00\xb5\x8a\xf1h\xfes\x9d\x1a\xaan\x95E\x87\xba,\xaaj\xbc\xf2\xf5y\xc1\x9cP\xac\xdfv\xde\n\xf0_\"s\xfdL@\xeb\xfa_\x00\x00\x00\xff\xffPK\x07\x088]\x0f8f\x02\x00\x00! \x00\x00PK\x03\x04\x14\x00\x08\x00\x08\x00\x84\x80\x9bQ\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0b\x00 \x00out_raw.txtUT\x05\x00\x01x\xb0\xe8_\xa4\x94Q\xab\xda0\x14\xc7\x9f\xed\xa78c\x8c\xe9\x865\x9d8\xaf\x01\x192p\x88C/\xab{\xba\xc8\xa5\xb6\xb1\x0d\xa6I1\xe9\x86\xdf~$V\xad5\xadr\x07>\x84\x9cs\xfe\xff\xdf9\x9e\xe6=\xc4T%\xf9\xc6\x0dE\xda\xdb\x1dD\xf2\xf4\xb5\xb7\xa7a\x12\x8b\x9e\x0c\xd2\x8c\x91\xde&\xa7,\xda\x06\x94\xc1\xcb\xc3\xa9\xae\"R\xad\x9d\xea\xf5\xe5\xf4\xaa\x13\xdcX\xe0'<\xc4\xa0\xdc\xa9\x10\x90\xf3\x88l)'\x11\xb4\xd5!#\xf0I\xe7P\x1e\xbb+H\x02 \\\xc0\x96\x12\x16\x81\xd8CJT\"\"\x98\n\xd1q\xc6\xe31\xfc\xfa\xbd\x00\x80\x15\x91\xca7\x96\x8b\x1f\x0e\x00\xc0\xd1\xff\x95\xc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x00\x00PK\x01\x02\x14\x03\x14\x00\x08\x00\x08\x00\x84\x80\x9bQ8]\x0f8f\x02\x00\x00! \x00\x00\x0f\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4\x81\x00\x00\x00\x00out_colored.txtUT\x05\x00\x01x\xb0\xe8_PK\x01\x02\x14\x03\x14\x00\x08\x00\x08\x00\x84\x80\x9bQc\xdc\xfe\xb8#\x02\x00\x00\xd8\x07\x00\x00\x0b\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4\x81\xac\x02\x00\x00out_raw.txtUT\x05\x00\x01x\xb0\xe8_PK\x05\x06\x00\x00\x00\x00\x02\x00\x02\x00\x88\x00\x00\x00\x11\x05\x00\x00\x00\x00" + data := "PK\x03\x04\x14\x00\x08\x00\x08\x00\xb9\x8a\xc3R\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0f\x00 \x00out_colored.txtUT\x05\x00\x01\xae\x0f\xb9`\xac\x95\xdfn\xda<\x18\xc6\x8f\xdb[\xe0\xe4\xfd\xf4i\x1a\xdd\xd4\xe04\xa2-9c\xdd:!\xaaR5l'\x11B!1\xc1\xc2\x8e#\xe2lC\xe2\xe2''\x86\xa4\x89C\x18\x9b\xc5\x81\x89\xdf?\xbf\xe7Ilw\\\xcbb\x1d\xd7d\x9f\xbe\x8d\x9e>\xef $b\x95.\x0c\x9f\xb3\xdez\xcbW\xf7\xb7\xbd\x0d\xf1W!\xef%\x1e\x8b)\xee-RB\x83\xa5G(\xb8'\x87\x1a\x02'b\xd6q\x11\xbb<\xb4\x039v\xd0q\xad[V\x8d/fs\x99i\x84\\\xe6v\\\xab\xcf\xec{\xfbN\xfd\xc9\xeb\xd8 \x8cG\xce!\x8d\x02\xbc$\x11\x0e\xa0+\xb61\x86\x0f2\x93D\xa11\x85\x95\x97@\xc4aI0\x0d\x80o\x80a\xb1\xe2\x01\xa2\x81\x8d\xd0yt}\xad\xc9\x05\xa2u\xc3^\x86\x8e\x03\x85\x0bU_\x0f\x01:\x0d-\x9e:k\x12\xb7r'k\x12kvL \xbcT}\xd4\xfa^\xd0_\xf0\xbe\xf9\x9c\x1b\xccU\xdd4\xcc\xb9\xac#T-:\xa7\x84a\x9e\x8aF\x9dj}_\xf1mx\x15S\xadB\xd7:\xfe!\xe8\x8b\xd6\xd3\x94\x8f>\xff\x817^\x88mp#\x0e\x89\xf0\x04f8\x12\xc9L\xbb\x83/Z\xce\xe9\x0b\xd9\xc5J\xce\xca-_\x07\xd9\x14\xe4\x1c\x07\xb3\x9a\x7f\x0f\x92\x19\xf5k\x16\xa8\xe7\xf5\xbd\xf20\xf9\xfe\xe5u\x07}d\xa0w\xe0\xfe/\xc7\\\x8eY\xadD\x1b\xa3\xafZ\x14\xb6\xe5E\xf9\xb2\xe4\x9d\x1exH\xa9\x9exHi#\xb2\x89J\xcc\xd98\x93\xd9\xa3\xb4\x04\xad\xca\xea\xa8\x8bOC\xddz6\xfc\xf46Q6\x89x\xf60\x01\xc1a\x93F\xfb\x8c\xfc\xf6T\xc49\xef\xfc0\xfe\x9c\x17\xb3Xle\x9f\x12\xf0 &?\xf3,\xbc\xf9\xa4\x88\xf2\x80\xe3\xa7\x9a\xe7\xfb8\xae\xefAU\xbc\xfa\x9e\xfe\xb1rEx\xaa\xee\xfc|j/*\x05_\xb8\xea\xe5\xc1\x92P\xac\xb67\xfeEDV:M\xe0\xe6\xf2w\x00\x00\x00\xff\xffPK\x07\x08Aj\xd0\xbcr\x02\x00\x00\xbf \x00\x00PK\x03\x04\x14\x00\x08\x00\x08\x00\xf1\x8a\xc3R\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0b\x00 \x00out_raw.txtUT\x05\x00\x01\x17\x10\xb9`\xa4\x94Q\xab\xda0\x14\xc7\x9f\xed\xa78c\x8c\xe9\x865\x9d\xb8{o@\x86\x0c\x1c\xe2\xd0\xcb\xea\x9e.r\xa9ml\x83iRL\xba\xe1\xb7\x1f\x89\xad\xd6\x9aV\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x86A\x98\x90\xa8\xd7i\xd7\xb4\xa0N\x18\xb3\xb1N\x18k\x82\xf5\xd0\x7f\xd1\x06\x8c\xd9p\xad\xaa\xc5C\x8c\xe1o\xb0\xe7\xe6\xc0\x05\xe8K J\xc0>\xe7u\xb6\xb7\x92\x914S\x07-lC\xbb\x165\xdbV\xe5\xa8o\xc1B\x98r\xb3\xdb\xfcx\xae>\x1cA\x18\x92\xac\xfeu\x145Mc\x7fkk\x85\xfd}\x8d9\xdf\xe0.I3\xaar\x08\xb0\xa5\x8c\x14\x9f\x9c\xf3/\x00\x00\xff\xffPK\x07\x08\xb6\x05\x0f\x1b\"\x02\x00\x00\xd8\x07\x00\x00PK\x01\x02\x14\x03\x14\x00\x08\x00\x08\x00\xb9\x8a\xc3RAj\xd0\xbcr\x02\x00\x00\xbf \x00\x00\x0f\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4\x81\x00\x00\x00\x00out_colored.txtUT\x05\x00\x01\xae\x0f\xb9`PK\x01\x02\x14\x03\x14\x00\x08\x00\x08\x00\xf1\x8a\xc3R\xb6\x05\x0f\x1b\"\x02\x00\x00\xd8\x07\x00\x00\x0b\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4\x81\xb8\x02\x00\x00out_raw.txtUT\x05\x00\x01\x17\x10\xb9`PK\x05\x06\x00\x00\x00\x00\x02\x00\x02\x00\x88\x00\x00\x00\x1c\x05\x00\x00\x00\x00" fs.Register(data) } \ No newline at end of file diff --git a/editor/test/test.go b/editor/test/test.go index 7e8a8a0..9441b81 100644 --- a/editor/test/test.go +++ b/editor/test/test.go @@ -37,8 +37,8 @@ var ( passtail = regexp.MustCompile(`(?m)^([ \t]*)--- PASS: Test.*`) skiptail = regexp.MustCompile(`(?m)^([ \t]*)--- SKIP: Test.*`) failtail = regexp.MustCompile(`(?m)^([ \t]*)--- FAIL: Test.*`) - passlonely = regexp.MustCompile(`(?m)^PASS$`) - faillonely = regexp.MustCompile(`(?m)^FAIL$`) + passlonely = regexp.MustCompile(`(?m)^PASS[ \t]*$`) + faillonely = regexp.MustCompile(`(?m)^FAIL[ \t]*$`) okPath = regexp.MustCompile(`(?m)^ok[ \t]+([^ \t]+)[ \t]*(?:[\d\.]+\w+|\(cached\))?[ \t]*(?:[ \t]+(coverage:[ \t]+\d+\.\d+% of statements)[ \t]*)?(?:` + noTestPattern + `)?$`) failPath = regexp.MustCompile(`(?m)^FAIL[ \t]+[^ \t]+[ \t]+(?:[\d\.]+\w+|\[build failed\])$`) @@ -46,7 +46,7 @@ var ( coverage = regexp.MustCompile(`(?m)^coverage: ((\d+)\.\d)+% of statements?$`) - filename = regexp.MustCompile(`(?m)([^[ \t]:]+\.go):(\d+)`) + filename = regexp.MustCompile(`(?m)([^\s:]+\.go)((?::\d+){1,2})`) emptyline = regexp.MustCompile(`(?m)^[ \t]*\r?\n`) importpath = regexp.MustCompile(`(?m)^# ([^ ]+)(?: \[[^ \[\]]+\])?$`) @@ -185,24 +185,22 @@ func (e *test) Edit(line string) (string, error) { Exp: passlonely, Func: func(s string) string { processed = true - style = config.C.PassPackageStyle - - return style.Apply("PASS") + return config.C.PassPackageStyle.Apply("PASS") }, }, editor.RegexRepl{ Exp: faillonely, Func: func(s string) string { processed = true - style = config.C.FailPackageStyle - - return style.Apply("FAIL") + return config.C.FailPackageStyle.Apply("FAIL") }, }, editor.RegexRepl{ - Exp: filename, - Repl: config.C.FileStyle.Apply(`$1`) + ":" + config.C.LineStyle.Apply(`$2`), + Exp: filename, + Func: func(s string) string { + return filename.ReplaceAllString(s, config.C.FileStyle.Apply(`$1`)+config.C.LineStyle.Apply(`$2`)) + e.prevLineStyle.ANSI().String() + }, }, ) diff --git a/sample/out_colored.txt b/sample/out_colored.txt index e7b27fb..1ae8420 100644 --- a/sample/out_colored.txt +++ b/sample/out_colored.txt @@ -1,54 +1,48 @@ BUILD| github.com/kyoh86/richgo/sample/buildfail [github.com/kyoh86/richgo/sample/buildfail.test] - | sample/buildfail/buildfail_test.go:8:7: t.Foo undefined (type *testing.T has no field or method Foo) + | sample/buildfail/buildfail_test.go:8:7: t.Foo undefined (type *testing.T has no field or method Foo) START| SampleNG - | sample_ng_test.go:9: It's not OK... :( + | sample_ng_test.go:9: It's not OK... :( START| SampleNG/SubtestNG - | sample_ng_test.go:13: It's also not OK... :( + | sample_ng_test.go:13: It's also not OK... :( FAIL | SampleNG (0.00s) FAIL | SampleNG/SubtestNG (0.00s) START| SampleOK - | sample_ok_test.go:11: It's OK! + | sample_ok_test.go:11: It's OK! START| SampleOK/SubtestOK  | time:2017-01-01T01:01:01+09:00 - | sample_ok_test.go:15: It's also OK! + | sample_ok_test.go:15: It's also OK! PASS | SampleOK (0.00s) PASS | SampleOK/SubtestOK (0.00s) START| SampleSkip - | sample_skip_test.go:8:  + | sample_skip_test.go:8:  SKIP | SampleSkip (0.00s) START| SampleSkipSub START| SampleSkipSub/SubtestSkip - | sample_skip_test.go:13:  + | sample_skip_test.go:13:  PASS | SampleSkipSub (0.00s) SKIP | SampleSkipSub/SubtestSkip (0.00s) START| SampleTimeout START| SampleTimeout/SubtestTimeout PASS | SampleTimeout (3.00s) PASS | SampleTimeout/SubtestTimeout (3.00s) -FAIL  | coverage: [no statements] -FAIL | github.com/kyoh86/richgo/sample 3.097s +FAIL | github.com/kyoh86/richgo/sample 3.003s FAIL | github.com/kyoh86/richgo/sample/buildfail [build failed] START| Cover05 PASS | Cover05 (0.00s) -PASS COVER| 50.0% [#####_____] PASS | github.com/kyoh86/richgo/sample/cover05 coverage: 50.0% of statements START| CoverAll PASS | CoverAll (0.00s) -PASS COVER| 100.0% [##########] PASS | github.com/kyoh86/richgo/sample/coverall coverage: 100.0% of statements  | testing: warning: no tests to run -PASS COVER| 0.0% [__________] PASS | github.com/kyoh86/richgo/sample/emptytest coverage: 0.0% of statements START| Nocover - | nocover_test.go:8: accept + | nocover_test.go:8: accept PASS | Nocover (0.00s) -PASS COVER| 0.0% [__________] PASS | github.com/kyoh86/richgo/sample/nocover coverage: 0.0% of statements SKIP | github.com/kyoh86/richgo/sample/notest [no test files] -FAIL exit status 2 diff --git a/sample/out_raw.txt b/sample/out_raw.txt index 9f00c68..0f2728e 100644 --- a/sample/out_raw.txt +++ b/sample/out_raw.txt @@ -27,7 +27,7 @@ time:2017-01-01T01:01:01+09:00 --- PASS: TestSampleTimeout/SubtestTimeout (3.00s) FAIL coverage: [no statements] -FAIL github.com/kyoh86/richgo/sample 3.097s +FAIL github.com/kyoh86/richgo/sample 3.003s FAIL github.com/kyoh86/richgo/sample/buildfail [build failed] === RUN TestCover05 --- PASS: TestCover05 (0.00s)