...

Source file src/cuelang.org/go/internal/core/compile/compile_test.go

Documentation: cuelang.org/go/internal/core/compile

     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  		Skip: alwaysSkip,
    40  		ToDo: needFix,
    41  	}
    42  
    43  	if *todo {
    44  		test.ToDo = nil
    45  	}
    46  
    47  	test.Run(t, func(t *cuetxtar.Test) {
    48  		r := runtime.New()
    49  		// TODO: use high-level API.
    50  
    51  		a := t.Instance()
    52  
    53  		v, err := compile.Files(nil, r, "", a.Files...)
    54  
    55  		// Write the results.
    56  		t.WriteErrors(err)
    57  
    58  		if v == nil {
    59  			return
    60  		}
    61  
    62  		for i, f := range a.Files {
    63  			if i > 0 {
    64  				fmt.Fprintln(t)
    65  			}
    66  			fmt.Fprintln(t, "---", t.Rel(f.Filename))
    67  			debug.WriteNode(t, r, v.Conjuncts[i].Elem(), &debug.Config{
    68  				Cwd: t.Dir,
    69  			})
    70  		}
    71  		fmt.Fprintln(t)
    72  	})
    73  }
    74  
    75  var alwaysSkip = map[string]string{
    76  	"fulleval/031_comparison against bottom": "fix bin op binding in test",
    77  }
    78  
    79  var needFix = map[string]string{
    80  	"DIR/NAME": "explanation",
    81  }
    82  
    83  // TestX is for debugging. Do not delete.
    84  func TestX(t *testing.T) {
    85  	in := `
    86  	`
    87  
    88  	if strings.TrimSpace(in) == "" {
    89  		t.Skip()
    90  	}
    91  
    92  	file, err := parser.ParseFile("TestX", in)
    93  	if err != nil {
    94  		t.Fatal(err)
    95  	}
    96  	r := runtime.New()
    97  
    98  	arc, err := compile.Files(nil, r, "", file)
    99  	if err != nil {
   100  		t.Error(errors.Details(err, nil))
   101  	}
   102  	t.Error(debug.NodeString(r, arc.Conjuncts[0].Elem(), nil))
   103  }
   104  

View as plain text