1+ // Copyright 2022 The go-python Authors. All rights reserved.
2+ // Use of this source code is governed by a BSD-style
3+ // license that can be found in the LICENSE file.
4+
15package main
26
37import (
@@ -9,8 +13,6 @@ import (
913 "testing"
1014)
1115
12- const embeddingTestOutput = "testdata/embedding_out_golden.txt"
13-
1416var regen = flag .Bool ("regen" , false , "regenerate golden files" )
1517
1618func TestEmbeddedExample (t * testing.T ) {
@@ -25,33 +27,36 @@ func TestEmbeddedExample(t *testing.T) {
2527 cmd := exec .Command ("go" , "build" , "-o" , exe , "." )
2628 err = cmd .Run ()
2729 if err != nil {
28- t .Fatalf ("failed to compile embedding example: %v" , err )
30+ t .Fatalf ("failed to compile embedding example: %+ v" , err )
2931 }
3032
3133 out := new (bytes.Buffer )
3234 cmd = exec .Command (exe , "mylib-demo.py" )
3335 cmd .Stdout = out
36+ cmd .Stderr = out
3437
3538 err = cmd .Run ()
3639 if err != nil {
37- t .Fatalf ("failed to run embedding binary: %v" , err )
40+ t .Fatalf ("failed to run embedding binary: %+ v" , err )
3841 }
3942
40- testOutput := out .Bytes ()
43+ const fname = "testdata/embedding_out_golden.txt"
44+
45+ got := out .Bytes ()
4146
4247 flag .Parse ()
4348 if * regen {
44- err = os .WriteFile (embeddingTestOutput , testOutput , 0644 )
49+ err = os .WriteFile (fname , got , 0644 )
4550 if err != nil {
46- t .Fatalf ("failed to write test output : %v" , err )
51+ t .Fatalf ("could not write golden file : %+ v" , err )
4752 }
4853 }
4954
50- mustMatch , err := os .ReadFile (embeddingTestOutput )
55+ want , err := os .ReadFile (fname )
5156 if err != nil {
52- t .Fatalf ("failed read %q " , embeddingTestOutput )
57+ t .Fatalf ("could not read golden file: %+v " , err )
5358 }
54- if ! bytes .Equal (testOutput , mustMatch ) {
55- t .Fatalf ("embedded test output did not match accepted output from %q " , embeddingTestOutput )
59+ if ! bytes .Equal (got , want ) {
60+ t .Fatalf ("stdout differ: \n got: \n %s \n want: \n %s \n " , got , want )
5661 }
5762}
0 commit comments