github.com/grantbow/fit@v0.7.1-0.20220916164603-1f7c88ac81e6/fitapp/Version_test.go (about)

     1  package fitapp
     2  
     3  import (
     4  	//"fmt"
     5  	//	"io"
     6  	//"io/ioutil"
     7  	//"os"
     8  	"regexp"
     9  	//"runtime"
    10  	"testing"
    11  )
    12  
    13  // Captures stdout and stderr to ensure that
    14  // a usage line gets printed to Stderr when
    15  // no parameters are specified
    16  func TestVersionOutput(t *testing.T) {
    17  
    18  	stdout, stderr := captureOutput(func() {
    19  		PrintVersion()
    20  	}, t)
    21  
    22  	if stdout == "" {
    23  		t.Error("No output on stdout.")
    24  	}
    25  	if stderr != "" {
    26  		t.Error("Unexpected output on stderr.")
    27  	}
    28  
    29  	expected := "version .* built using .*"
    30  	// was == fmt.Sprintf("%s version %s built using %s\n", os.Args[0], ProgramVersion(), runtime.Version())
    31  	re := regexp.MustCompile(expected)
    32  	matched := re.MatchString(string(stdout))
    33  	if !matched {
    34  		t.Error("Unexpected output on stdout.")
    35  	}
    36  }