Skip to content

testing: examples fail if output is colored #34284

@GuillaumeLescure

Description

@GuillaumeLescure

Issue :
go test fail if the output is colored.

Even if the tags are in the output (the comment line), it fails and seems to be litterally evaluated.

Exemple :
In myColored_test.go :

package main

import (
"fmt"
)

func Example_ColorTerm() {
fmt.Print("\033[31mHello World\033[0m")
//Output: Hello World
}

Expectation :
Be able to pass the test either :

  • as litteral "Hello World" (colors ignored)
  • as interpreted string "\033[31mHello World\033[0m" (colors are also checked)

I personally prefere the second solution because it allows more accurate tests.

Environment :

  • go version go1.12.9 linux/amd64
  • Manjaro (Linux 4.19.69-1)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions