2020-12-22 17:45:36 +02:00
|
|
|
|
2020-12-01 10:34:22 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
2020-12-22 17:45:36 +02:00
|
|
|
"fmt"
|
|
|
|
|
"io/ioutil"
|
|
|
|
|
"os"
|
|
|
|
|
"strings"
|
|
|
|
|
"testing"
|
2020-12-01 10:34:22 +02:00
|
|
|
)
|
|
|
|
|
|
2020-12-22 17:45:36 +02:00
|
|
|
func TestHelloWorld(t *testing.T) {
|
|
|
|
|
rescueStdout := os.Stdout
|
|
|
|
|
r, w, _ := os.Pipe()
|
|
|
|
|
os.Stdout = w
|
2020-12-01 10:34:22 +02:00
|
|
|
|
2020-12-22 17:45:36 +02:00
|
|
|
main()
|
|
|
|
|
|
|
|
|
|
w.Close()
|
|
|
|
|
out, _ := ioutil.ReadAll(r)
|
|
|
|
|
os.Stdout = rescueStdout
|
|
|
|
|
|
|
|
|
|
fmt.Println(string(out))
|
|
|
|
|
|
|
|
|
|
var outputString string = string(out)
|
2020-12-01 10:34:22 +02:00
|
|
|
|
2020-12-22 17:45:36 +02:00
|
|
|
if strings.TrimSpace(outputString) != "Hello World" {
|
|
|
|
|
t.Errorf("Expected %s, got %s", "Hello World", out)
|
|
|
|
|
}
|
2020-12-01 10:34:22 +02:00
|
|
|
}
|