github.com/gopherjs/gopherjs@v1.19.0-beta1.0.20240506212314-27071a8796e4/tests/lowlevel_test.go (about)

     1  package tests_test
     2  
     3  import (
     4  	"os"
     5  	"os/exec"
     6  	"path/filepath"
     7  	"runtime"
     8  	"strings"
     9  	"testing"
    10  
    11  	"github.com/google/go-cmp/cmp"
    12  )
    13  
    14  // Test for internalization/externalization of time.Time/Date when time package is imported
    15  // but time.Time is unused, causing it to be DCEed (or time package not imported at all).
    16  //
    17  // See https://github.com/gopherjs/gopherjs/issues/279.
    18  func TestTimeInternalizationExternalization(t *testing.T) {
    19  	if runtime.GOOS == "js" {
    20  		t.Skip("test meant to be run using normal Go compiler (needs os/exec)")
    21  	}
    22  
    23  	gotb, err := exec.Command("gopherjs", "run", filepath.Join("testdata", "time_inexternalization.go")).Output()
    24  	got := string(gotb)
    25  	if err != nil {
    26  		t.Fatalf("%v:\n%s", err, got)
    27  	}
    28  
    29  	wantb, err := os.ReadFile(filepath.Join("testdata", "time_inexternalization.out"))
    30  	want := string(wantb)
    31  	if err != nil {
    32  		t.Fatalf("error reading .out file: %v", err)
    33  	}
    34  	got = strings.ReplaceAll(got, "\r\n", "\n")
    35  	want = strings.ReplaceAll(want, "\r\n", "\n")
    36  
    37  	if diff := cmp.Diff(want, got); diff != "" {
    38  		t.Fatalf("Got diff (-want,+got):\n%s", diff)
    39  	}
    40  }
    41  
    42  func TestDeferBuiltin(t *testing.T) {
    43  	if runtime.GOOS == "js" {
    44  		t.Skip("test meant to be run using normal Go compiler (needs os/exec)")
    45  	}
    46  
    47  	got, err := exec.Command("gopherjs", "run", filepath.Join("testdata", "defer_builtin.go")).CombinedOutput()
    48  	if err != nil {
    49  		t.Fatalf("%v:\n%s", err, got)
    50  	}
    51  }