github.com/solo-io/cue@v0.4.7/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 "github.com/solo-io/cue/cue/errors" 24 "github.com/solo-io/cue/cue/parser" 25 "github.com/solo-io/cue/internal/core/compile" 26 "github.com/solo-io/cue/internal/core/debug" 27 "github.com/solo-io/cue/internal/core/runtime" 28 "github.com/solo-io/cue/internal/cuetest" 29 "github.com/solo-io/cue/internal/cuetxtar" 30 ) 31 32 var ( 33 todo = flag.Bool("todo", false, "run tests marked with #todo-compile") 34 ) 35 36 func TestCompile(t *testing.T) { 37 test := cuetxtar.TxTarTest{ 38 Root: "../../../cue/testdata/", 39 Name: "compile", 40 Update: cuetest.UpdateGoldenFiles, 41 Skip: alwaysSkip, 42 ToDo: needFix, 43 } 44 45 if *todo { 46 test.ToDo = nil 47 } 48 49 r := runtime.New() 50 51 test.Run(t, func(t *cuetxtar.Test) { 52 // TODO: use high-level API. 53 54 a := t.ValidInstances() 55 56 v, err := compile.Files(nil, r, "", a[0].Files...) 57 58 // Write the results. 59 t.WriteErrors(err) 60 61 if v == nil { 62 return 63 } 64 65 for i, f := range a[0].Files { 66 if i > 0 { 67 fmt.Fprintln(t) 68 } 69 fmt.Fprintln(t, "---", t.Rel(f.Filename)) 70 debug.WriteNode(t, r, v.Conjuncts[i].Expr(), &debug.Config{ 71 Cwd: t.Dir, 72 }) 73 } 74 fmt.Fprintln(t) 75 }) 76 } 77 78 var alwaysSkip = map[string]string{ 79 "fulleval/031_comparison against bottom": "fix bin op binding in test", 80 } 81 82 var needFix = map[string]string{ 83 "DIR/NAME": "explanation", 84 } 85 86 // TestX is for debugging. Do not delete. 87 func TestX(t *testing.T) { 88 in := ` 89 ` 90 91 if strings.TrimSpace(in) == "" { 92 t.Skip() 93 } 94 95 file, err := parser.ParseFile("TestX", in) 96 if err != nil { 97 t.Fatal(err) 98 } 99 r := runtime.New() 100 101 arc, err := compile.Files(nil, r, "", file) 102 if err != nil { 103 t.Error(errors.Details(err, nil)) 104 } 105 t.Error(debug.NodeString(r, arc.Conjuncts[0].Expr(), nil)) 106 }