cuelang.org/go@v0.13.0/internal/core/compile/compile_test.go (about) 1 // Copyright 2020 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 package compile_test 16 17 import ( 18 "flag" 19 "fmt" 20 "strings" 21 "testing" 22 23 "cuelang.org/go/cue/errors" 24 "cuelang.org/go/cue/parser" 25 "cuelang.org/go/internal/core/compile" 26 "cuelang.org/go/internal/core/debug" 27 "cuelang.org/go/internal/core/runtime" 28 "cuelang.org/go/internal/cuetxtar" 29 ) 30 31 var ( 32 todo = flag.Bool("todo", false, "run tests marked with #todo-compile") 33 ) 34 35 func TestCompile(t *testing.T) { 36 test := cuetxtar.TxTarTest{ 37 Root: "../../../cue/testdata/", 38 Name: "compile", 39 } 40 41 if *todo { 42 test.ToDo = nil 43 } 44 45 test.Run(t, func(t *cuetxtar.Test) { 46 r := runtime.New() 47 // TODO: use high-level API. 48 49 a := t.Instance() 50 51 v, err := compile.Files(nil, r, "", a.Files...) 52 53 // Write the results. 54 t.WriteErrors(err) 55 56 if v == nil { 57 return 58 } 59 60 for i, f := range a.Files { 61 if i > 0 { 62 fmt.Fprintln(t) 63 } 64 fmt.Fprintln(t, "---", t.Rel(f.Filename)) 65 t.Write(debug.AppendNode(nil, r, v.ConjunctAt(i).Elem(), &debug.Config{ 66 Cwd: t.Dir, 67 })) 68 } 69 fmt.Fprintln(t) 70 }) 71 } 72 73 // TestX is for debugging. Do not delete. 74 func TestX(t *testing.T) { 75 in := ` 76 ` 77 78 if strings.TrimSpace(in) == "" { 79 t.Skip() 80 } 81 82 file, err := parser.ParseFile("TestX", in) 83 if err != nil { 84 t.Fatal(err) 85 } 86 r := runtime.New() 87 88 arc, err := compile.Files(nil, r, "", file) 89 if err != nil { 90 t.Error(errors.Details(err, nil)) 91 } 92 t.Error(debug.NodeString(r, arc.ConjunctAt(0).Elem(), nil)) 93 }