Skip to content

Commit

Permalink
pkg/internal/builtin: use normal formatting for builtin test results
Browse files Browse the repository at this point in the history
Change-Id: I631bb9af3ce934b13d89a6d1b6a4a524412755a4
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/7849
Reviewed-by: CUE cueckoo <cueckoo@gmail.com>
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
  • Loading branch information
mpvl committed Dec 2, 2020
1 parent e7e27e0 commit fb3b02e
Show file tree
Hide file tree
Showing 24 changed files with 354 additions and 701 deletions.
5 changes: 2 additions & 3 deletions pkg/crypto/md5/testdata/gen.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@ import "crypto/md5"

t1: len(md5.Sum("hash me"))
-- out/md5 --
(struct){
t1: (int){ 16 }
}
t1: 16

5 changes: 2 additions & 3 deletions pkg/crypto/sha1/testdata/gen.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@ import "crypto/sha1"

t1: len(sha1.Sum("hash me"))
-- out/sha1 --
(struct){
t1: (int){ 20 }
}
t1: 20

9 changes: 4 additions & 5 deletions pkg/crypto/sha256/testdata/gen.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ t1: sha256.Sum256("hash me")
t2: len(sha256.Sum256("hash me"))
t3: len(sha256.Sum224("hash me"))
-- out/sha256 --
(struct){
t1: (bytes){ '\xeb \x1a\xf5\xaa\xf0\xd6\x06)\xd3Ҧ\x1eFl\xfc\x0f\xed\xb5\x17\xad\xd81\xec\xacR5\xe1کc\xd6' }
t2: (int){ 32 }
t3: (int){ 28 }
}
t1: '\xeb \x1a\xf5\xaa\xf0\xd6\x06)\xd3Ҧ\x1eFl\xfc\x0f\xed\xb5\x17\xad\xd81\xec\xacR5\xe1کc\xd6'
t2: 32
t3: 28

11 changes: 5 additions & 6 deletions pkg/crypto/sha512/testdata/gen.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ t2: len(sha512.Sum384("hash me"))
t3: len(sha512.Sum512_224("hash me"))
t4: len(sha512.Sum512_256("hash me"))
-- out/sha512 --
(struct){
t1: (int){ 64 }
t2: (int){ 48 }
t3: (int){ 28 }
t4: (int){ 32 }
}
t1: 64
t2: 48
t3: 28
t4: 32

16 changes: 5 additions & 11 deletions pkg/encoding/base64/testdata/gen.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,8 @@ error in call to encoding/base64.Decode: base64: unsupported encoding: cannot us
error in call to encoding/base64.Decode: illegal base64 data at input byte 0

Result:
(_|_){
// [eval]
t1: (string){ "Zm9v" }
t2: (bytes){ 'foo' }
t3: (_|_){
// [eval] error in call to encoding/base64.Decode: illegal base64 data at input byte 0
}
t4: (_|_){
// [eval] error in call to encoding/base64.Decode: base64: unsupported encoding: cannot use value {} (type struct) as null
}
}
t1: "Zm9v"
t2: 'foo'
t3: _|_ // error in call to encoding/base64.Decode: illegal base64 data at input byte 0 (and 1 more errors)
t4: _|_ // error in call to encoding/base64.Decode: base64: unsupported encoding: cannot use value {} (type struct) as null (and 1 more errors)

29 changes: 13 additions & 16 deletions pkg/encoding/csv/testdata/gen.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,16 @@ t1: csv.Decode("1,2,3\n4,5,6")
t2: csv.Encode([[1,2,3],[4,5],[7,8,9]])
t3: csv.Encode([["a", "b"], ["c"]])
-- out/csv --
(struct){
t1: (#list){
0: (#list){
0: (string){ "1" }
1: (string){ "2" }
2: (string){ "3" }
}
1: (#list){
0: (string){ "4" }
1: (string){ "5" }
2: (string){ "6" }
}
}
t2: (string){ "1,2,3\n4,5\n7,8,9\n" }
t3: (string){ "a,b\nc\n" }
}
t1: [["1", "2", "3"], ["4", "5", "6"]]
t2: """
1,2,3
4,5
7,8,9

"""
t3: """
a,b
c

"""

17 changes: 8 additions & 9 deletions pkg/encoding/hex/testdata/gen.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ Errors:
error in call to encoding/hex.Decode: encoding/hex: invalid byte: U+006F 'o'

Result:
(_|_){
// [eval]
t1: (string){ "666f6f" }
t2: (bytes){ 'foo' }
t3: (_|_){
// [eval] error in call to encoding/hex.Decode: encoding/hex: invalid byte: U+006F 'o'
}
t4: (string){ "00000000 66 6f 6f |foo|\n" }
}
t1: "666f6f"
t2: 'foo'
t3: _|_ // error in call to encoding/hex.Decode: encoding/hex: invalid byte: U+006F 'o' (and 1 more errors)
t4: """
00000000 66 6f 6f |foo|

"""

47 changes: 29 additions & 18 deletions pkg/encoding/json/testdata/gen.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,33 @@ Errors:
a: error in call to encoding/json.Validate: invalid value 10 (out of bound <3)

Result:
(_|_){
// [eval]
t1: (bool){ true }
t2: (_|_){
// [eval] a: error in call to encoding/json.Validate: invalid value 10 (out of bound <3)
}
t3: (bool){ true }
t4: (string){ "[1,2]" }
t5: (string){ "{\n \"a\": 1,\n \"b\": 2\n}" }
t6: (int){ 1 }
t7: (string){ "{\"a\":1}\n{\"b\":2}\n" }
t8: (struct){
x: (int){ int }
y: (_|_){
// [incomplete] cannot convert incomplete value "int" to JSON
}
}
t9: (string){ "{\"a\":1}\n{\"b\":2}\n" }
import "encoding/json"

t1: true
t2: _|_ // error in call to encoding/json.Validate: a: invalid value 10 (out of bound <3) (and 1 more errors)
t3: true
t4: "[1,2]"
t5: """
{
"a": 1,
"b": 2
}
"""
t6: 1
t7: """
{"a":1}
{"b":2}

"""
t8: {
x: int
y: json.Marshal({
a: x
})
}
t9: """
{"a":1}
{"b":2}

"""

41 changes: 23 additions & 18 deletions pkg/encoding/yaml/testdata/gen.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,26 @@ a: error in call to encoding/yaml.ValidatePartial: invalid value 4 (out of bound
b: error in call to encoding/yaml.Validate: incomplete value int

Result:
(_|_){
// [eval]
t1: (_|_){
// [eval] a: error in call to encoding/yaml.Validate: invalid value 4 (out of bound <3)
}
t2: (bool){ true }
t3: (_|_){
// [eval] b: error in call to encoding/yaml.Validate: incomplete value int
}
t4: (_|_){
// [eval] a: error in call to encoding/yaml.ValidatePartial: invalid value 4 (out of bound <3)
}
t5: (bool){ true }
t6: (bool){ true }
t7: (string){ "a: 1\n---\nb: 2\n" }
t8: (string){ "b: 2\n" }
t9: (string){ "a: 1\n---\nb: 2\n" }
}
t1: _|_ // error in call to encoding/yaml.Validate: a: invalid value 4 (out of bound <3) (and 1 more errors)
t2: true
t3: _|_ // error in call to encoding/yaml.Validate: b: incomplete value int (and 1 more errors)
t4: _|_ // error in call to encoding/yaml.ValidatePartial: a: invalid value 4 (out of bound <3) (and 1 more errors)
t5: true
t6: true
t7: """
a: 1
---
b: 2

"""
t8: """
b: 2

"""
t9: """
a: 1
---
b: 2

"""

25 changes: 19 additions & 6 deletions pkg/internal/builtintest/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ import (
"testing"

"cuelang.org/go/cue"
"cuelang.org/go/internal/core/debug"
"cuelang.org/go/cue/format"
"cuelang.org/go/internal/core/eval"
"cuelang.org/go/internal/core/export"
"cuelang.org/go/internal/core/validate"
"cuelang.org/go/internal/cuetxtar"
)
Expand All @@ -36,9 +37,9 @@ func Run(name string, t *testing.T) {
test.Run(t, func(t *cuetxtar.Test) {
a := t.ValidInstances()

v, err := r.Build(a[0])
if err != nil {
t.Fatal(err)
v, errs := r.Build(a[0])
if errs != nil {
t.Fatal(errs)
}

e := eval.New(r)
Expand All @@ -54,7 +55,19 @@ func Run(name string, t *testing.T) {
fmt.Fprintln(t, "Result:")
}

debug.WriteNode(t, r, v, &debug.Config{Cwd: t.Dir})
fmt.Fprintln(t)
p := export.All
p.ShowErrors = true

files, errs := p.Vertex(r, test.Name, v)
if errs != nil {
t.Fatal(errs)
}

b, err := format.Node(files)
if err != nil {
t.Fatal(err)
}

fmt.Fprintln(t, string(b))
})
}

0 comments on commit fb3b02e

Please sign in to comment.