Skip to content

larschri/testable-example-output

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

testable-example-output

This is a workaround for golang/go#26460

The expected example output goes through some processing of whitespace that doesn't happen to the actual output. This is a tiny hack that processes the actual output correspondingly.

go get github.com/larschri/testable-example-output

Example:

package main

import (
        "fmt"
        "os"

        testable "github.com/larschri/testable-example-output"
)

func ExampleCRLF() {
        capture := testable.CaptureStdout()

        fmt.Println("x\r\ny")

        os.Stdout.Write(testable.Normalize(capture()))
        // Output:
        // x
        // y
}

// Same as above, but with convenience function
func ExampleFixExampleOutput() {
        done := testable.FixExampleOutput()
        defer done()

        fmt.Println("x\r\ny")
        // Output:
        // x
        // y
}

About

Fix golang example output

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages