- Notifications
You must be signed in to change notification settings - Fork24
Enrich `go test` outputs with text decorations.
License
kyoh86/richgo
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Rich-Go will enrichgo test outputs with text decorations
For some years, I've not been usingrichgo.Now I don't feel much effect that a little bit of tweaking to the appearance of the test output.And It is poor method thatrichgo parses and adjusts the standard output ofgo test.So now I recommend you that you do NOT userichgo, get use to purego test, train an ability to find the error from the output and contribute to improve officialgo test if you needed.Some may think that I have too much faith in pure Go, but this is my honest feeling.
If you want a good suggestion for alternative tools for this one, you may find it in theissue #57.
(go get):
go get -u github.com/kyoh86/richgo(homebrew):
brew install kyoh86/tap/richgo(asdf):
asdf plugin add richgoasdf install richgo 0.3.6richgotest ./...If your build scripts expect to interact with the standard output format ofgo test (for instance, if you're usinggo-junit-report), you'll need touse thetestfilter subcommand ofrichgo.
For example:
gotest ./...| tee>(richgo testfilter)| go-junit-report
This will "tee" the output of the standardgo test run into arichgo testfilter process as well as passing the original output togo-junit-report.
Note that at some point this recommendation may change, as the "go test" toolmay learn how to produce a standard output formatgolang/go#2981 that both this tooland others could rely on.
You can define alias so thatgo test prints rich outputs:
- bash:
~/.bashrc - zsh:
~/.zshrc
alias go=richgoIt's possible to change styles with the preference file.Rich-Go loads preferences from the files in the following order.
${CWD}/.richstyle${CWD}/.richstyle.yaml${CWD}/.richstyle.yml${GOPATH}/.richstyle${GOPATH}/.richstyle.yaml${GOPATH}/.richstyle.yml${GOROOT}/.richstyle${GOROOT}/.richstyle.yaml${GOROOT}/.richstyle.yml${HOME}/.richstyle${HOME}/.richstyle.yaml${HOME}/.richstyle.yml
Setting the environment variableRICHGO_LOCAL to 1, Rich-Go loads only${CWD}/.richstyle*.
Now Rich-Go supports only YAML formatted.
# Type of the label that notes a kind of each lines.labelType:(long | short | none)# Style of "Build" lines.buildStyle:# Hide lineshide:(true | false)# Bold or increased intensity.bold:(true | false)faint:(true | false)italic:(true | false)underline:(true | false)blinkSlow:(true | false)blinkRapid:(true | false)# Swap the foreground color and background color.inverse:(true | false)conceal:(true | false)crossOut:(true | false)frame:(true | false)encircle:(true | false)overline:(true | false)# Fore-color of textforeground:("#xxxxxx" | rgb(0-256,0-256,0-256) | rgb(0x00-0xFF,0x00-0xFF,0x00-0xFF) | (name of colors))# Back-color of textbackground:# Same format as `foreground`# Style of the "Start" lines.startStyle:# Same format as `buildStyle`# Style of the "Pass" lines.passStyle:# Same format as `buildStyle`# Style of the "Fail" lines.failStyle:# Same format as `buildStyle`# Style of the "Skip" lines.skipStyle:# Same format as `buildStyle`# Style of the "File" lines.fileStyle:# Same format as `buildStyle`# Style of the "Line" lines.lineStyle:# Same format as `buildStyle`# Style of the "Pass" package lines.passPackageStyle:# Same format as `buildStyle`# Style of the "Fail" package lines.failPackageStyle:# Same format as `buildStyle`# A threashold of the coveragecoverThreshold:(0-100)# Style of the "Cover" lines with the coverage that is higher than coverThreshold.coveredStyle:# Same format as `buildStyle`# Style of the "Cover" lines with the coverage that is lower than coverThreshold.uncoveredStyle:# Same format as `buildStyle`# If you want to delete lines, write the regular expressions.removals: -(regexp)# If you want to leave `Test` prefixes, set it "true".leaveTestPrefix:(true | false)
Rich-Go separate the output-lines in following categories.
Build:
When the Go fails to build, it prints errors like this:# github.com/kyoh86/richgo/sample/buildfailsample/buildfail/buildfail_test.go:6: t.Foo undefined (type testing.T has no field or method Foo)Start:
In the top of test, Go prints that name like this:=== RUN TestSampleOK/SubtestOKPass:
When a test is successed, Go prints that name like this:---PASS: TestSampleOK/SubtestOKFail:
When a test is failed, Go prints that name like this:--- FAIL: TestSampleNG (0.00s)sample_ng_test.go:9: It's not OK... :(Skip:
If there is no test files in directory or a test is skipped, Go prints that path or the name like this:--- SKIP: TestSampleSkip (0.00s)sample_skip_test.go:6:
? github.com/kyoh86/richgo/sample/notest [no test files]
PassPackage:
When tests in package are successed, Go prints just:PASSFail:
When a test in package are failed, Go prints just:FAILCover:
If the coverage analysis is enabled, Go prints the coverage like this:=== RUN TestCover05
--- PASS: TestCover05 (0.00s)PASScoverage: 50.0% of statementsok github.com/kyoh86/richgo/sample/cover050.012scoverage: 50.0% of statements
Each categories can be styled seperately.
Long:
- Build: "BUILD"
- Start: "START"
- Pass: "PASS"
- Fail: "FAIL"
- Skip: "SKIP"
- Cover: "COVER"
Short:
- Build: "!!"
- Start: ">"
- Pass: "o"
- Fail: "x"
- Skip: "-"
- Cover: "%"
None:Rich-Go will never output labels.
labelType:longbuildStyle:bold:trueforeground:yellowstartStyle:foreground:lightBlackpassStyle:foreground:greenfailStyle:bold:trueforeground:redskipStyle:foreground:lightBlackpassPackageStyle:foreground:greenhide:truefailPackageStyle:bold:trueforeground:redhide:truecoverThreshold:50coveredStyle:foreground:greenuncoveredStyle:bold:trueforeground:yellowfileStyle:foreground:cyanlineStyle:foreground:magenta
By default,richgo determines whether or not to colorize its output basedon whether it's connected to a TTY or not. This works for most use cases, butmay not behave as expected if you userichgo in a pipeline of commands, whereSTDOUT is being piped to another command.
To force colorization, addRICHGO_FORCE_COLOR=1 to the environment you'rerunning in. For example:
RICHGO_FORCE_COLOR=1 richgotest ./...| tee test.log
The bright-black is used for background color in Solarized dark theme.Richgo uses that color for "startStyle" and "skipStyle", so "START" and "SKIP" lines can not be seen on the screen with Solarized dark theme.
To resolve that conflict, you can set another color for "startStyle" and "skipStyle" in.richstyle like below.
startStyle: foreground: yellowskipStyle: foreground: lightYellowIf you want to get a version of therichgo, this information is embedded in the binary (since Go 1.18).You can view it with go version -m, e.g. for richgo 0.3.10:
$go version -m$(command -v richgo)./richgo: go1.18pathgithub.com/kyoh86/richgomodgithub.com/kyoh86/richgov0.3.10h1:iSGvcjhtQN2IVrBDhPk0if0R/RMQnCN1E/9OyAW4UUs=[...]
And just a little more advanced way (with POSIXawk):
$go version -m$(command -v richgo)| awk'$1 == "mod" && $2 == "github.com/kyoh86/richgo" {print $3;}'v0.3.10
This is distributed under theMIT License.
About
Enrich `go test` outputs with text decorations.
Topics
Resources
License
Code of conduct
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors6
Uh oh!
There was an error while loading.Please reload this page.
