cuelang.org/go@v0.10.1/cue/interpreter/wasm/exe_test.go (about)

     1  // Copyright 2023 CUE Authors
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  // TestExe expects cmd/cue to be configured with wasm support,
    16  // which it only is with the cuewasm build tag enabled.
    17  
    18  //go:build cuewasm
    19  
    20  package wasm_test
    21  
    22  import (
    23  	"os"
    24  	"path/filepath"
    25  	"testing"
    26  
    27  	"cuelang.org/go/cmd/cue/cmd"
    28  	"cuelang.org/go/internal/cuetest"
    29  
    30  	"github.com/rogpeppe/go-internal/gotooltest"
    31  	"github.com/rogpeppe/go-internal/testscript"
    32  )
    33  
    34  // We are using TestMain because we want to ensure Wasm is enabled and
    35  // works as expected with the command-line tool.
    36  func TestMain(m *testing.M) {
    37  	os.Exit(testscript.RunMain(m, map[string]func() int{
    38  		"cue": cmd.Main,
    39  	}))
    40  }
    41  
    42  // TestExe tests Wasm using the command-line tool.
    43  func TestExe(t *testing.T) {
    44  	root := must(filepath.Abs("testdata"))(t)
    45  	wasmFiles := filepath.Join(root, "cue")
    46  	p := testscript.Params{
    47  		Dir:                 "testdata/cue",
    48  		UpdateScripts:       cuetest.UpdateGoldenFiles,
    49  		RequireExplicitExec: true,
    50  		RequireUniqueNames:  true,
    51  		Setup: func(e *testscript.Env) error {
    52  			copyWasmFiles(t, e.WorkDir, wasmFiles)
    53  			e.Vars = append(e.Vars, "CUE_CACHE_DIR="+filepath.Join(e.WorkDir, ".tmp/cache"))
    54  			return nil
    55  		},
    56  		Condition: cuetest.Condition,
    57  	}
    58  	if err := gotooltest.Setup(&p); err != nil {
    59  		t.Fatal(err)
    60  	}
    61  	testscript.Run(t, p)
    62  }