github.com/goplusjs/gopherjs@v1.2.6-0.20211206034512-f187917453b8/tests/lowlevel_test.go (about) 1 package tests_test 2 3 import ( 4 "bytes" 5 "io/ioutil" 6 "os/exec" 7 "path/filepath" 8 "runtime" 9 "testing" 10 ) 11 12 // Test for internalization/externalization of time.Time/Date when time package is imported 13 // but time.Time is unused, causing it to be DCEed (or time package not imported at all). 14 // 15 // See https://github.com/gopherjs/gopherjs/issues/279. 16 func TestTimeInternalizationExternalization(t *testing.T) { 17 if runtime.GOARCH == "js" { 18 t.Skip("test meant to be run using normal Go compiler (needs os/exec)") 19 } 20 21 got, err := exec.Command("gopherjs", "run", filepath.Join("testdata", "time_inexternalization.go")).Output() 22 if err != nil { 23 t.Fatalf("%v:\n%s", err, got) 24 } 25 26 want, err := ioutil.ReadFile(filepath.Join("testdata", "time_inexternalization.out")) 27 if err != nil { 28 t.Fatalf("error reading .out file: %v", err) 29 } 30 31 if !bytes.Equal(got, want) { 32 t.Fatalf("got != want:\ngot:\n%s\nwant:\n%s", got, want) 33 } 34 }