mardi 29 mai 2018

why fmt.Scanf doesn't work in golang test

why fmt.Scanf doesn't work properly in a test file?

I have some test code as below, the test itself finishes without waiting for me to type in something.

package sometests

import (
    "fmt"
    "testing"
)

func TestScanf(t *testing.T) {
    fmt.Printf("type someting:\n")
    var s string
    fmt.Scanf("%s\n", &s)
    // test should wait here for me to type, but it won't
    fmt.Printf("you type: %q\n", s)
}

Aucun commentaire:

Enregistrer un commentaire