Skip to content

Commit fb3b02e

Browse files
committed
pkg/internal/builtin: use normal formatting for builtin test results
Change-Id: I631bb9af3ce934b13d89a6d1b6a4a524412755a4 Reviewed-on: https://cue-review.googlesource.com/c/cue/+/7849 Reviewed-by: CUE cueckoo <[email protected]> Reviewed-by: Marcel van Lohuizen <[email protected]>
1 parent e7e27e0 commit fb3b02e

File tree

24 files changed

+354
-701
lines changed

24 files changed

+354
-701
lines changed

pkg/crypto/md5/testdata/gen.txtar

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,5 @@ import "crypto/md5"
55

66
t1: len(md5.Sum("hash me"))
77
-- out/md5 --
8-
(struct){
9-
t1: (int){ 16 }
10-
}
8+
t1: 16
9+

pkg/crypto/sha1/testdata/gen.txtar

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,5 @@ import "crypto/sha1"
55

66
t1: len(sha1.Sum("hash me"))
77
-- out/sha1 --
8-
(struct){
9-
t1: (int){ 20 }
10-
}
8+
t1: 20
9+

pkg/crypto/sha256/testdata/gen.txtar

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ t1: sha256.Sum256("hash me")
77
t2: len(sha256.Sum256("hash me"))
88
t3: len(sha256.Sum224("hash me"))
99
-- out/sha256 --
10-
(struct){
11-
t1: (bytes){ '\xeb \x1a\xf5\xaa\xf0\xd6\x06)\xd3Ҧ\x1eFl\xfc\x0f\xed\xb5\x17\xad\xd81\xec\xacR5\xe1کc\xd6' }
12-
t2: (int){ 32 }
13-
t3: (int){ 28 }
14-
}
10+
t1: '\xeb \x1a\xf5\xaa\xf0\xd6\x06)\xd3Ҧ\x1eFl\xfc\x0f\xed\xb5\x17\xad\xd81\xec\xacR5\xe1کc\xd6'
11+
t2: 32
12+
t3: 28
13+

pkg/crypto/sha512/testdata/gen.txtar

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ t2: len(sha512.Sum384("hash me"))
88
t3: len(sha512.Sum512_224("hash me"))
99
t4: len(sha512.Sum512_256("hash me"))
1010
-- out/sha512 --
11-
(struct){
12-
t1: (int){ 64 }
13-
t2: (int){ 48 }
14-
t3: (int){ 28 }
15-
t4: (int){ 32 }
16-
}
11+
t1: 64
12+
t2: 48
13+
t3: 28
14+
t4: 32
15+

pkg/encoding/base64/testdata/gen.txtar

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,8 @@ error in call to encoding/base64.Decode: base64: unsupported encoding: cannot us
1313
error in call to encoding/base64.Decode: illegal base64 data at input byte 0
1414

1515
Result:
16-
(_|_){
17-
// [eval]
18-
t1: (string){ "Zm9v" }
19-
t2: (bytes){ 'foo' }
20-
t3: (_|_){
21-
// [eval] error in call to encoding/base64.Decode: illegal base64 data at input byte 0
22-
}
23-
t4: (_|_){
24-
// [eval] error in call to encoding/base64.Decode: base64: unsupported encoding: cannot use value {} (type struct) as null
25-
}
26-
}
16+
t1: "Zm9v"
17+
t2: 'foo'
18+
t3: _|_ // error in call to encoding/base64.Decode: illegal base64 data at input byte 0 (and 1 more errors)
19+
t4: _|_ // error in call to encoding/base64.Decode: base64: unsupported encoding: cannot use value {} (type struct) as null (and 1 more errors)
20+

pkg/encoding/csv/testdata/gen.txtar

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,16 @@ t1: csv.Decode("1,2,3\n4,5,6")
77
t2: csv.Encode([[1,2,3],[4,5],[7,8,9]])
88
t3: csv.Encode([["a", "b"], ["c"]])
99
-- out/csv --
10-
(struct){
11-
t1: (#list){
12-
0: (#list){
13-
0: (string){ "1" }
14-
1: (string){ "2" }
15-
2: (string){ "3" }
16-
}
17-
1: (#list){
18-
0: (string){ "4" }
19-
1: (string){ "5" }
20-
2: (string){ "6" }
21-
}
22-
}
23-
t2: (string){ "1,2,3\n4,5\n7,8,9\n" }
24-
t3: (string){ "a,b\nc\n" }
25-
}
10+
t1: [["1", "2", "3"], ["4", "5", "6"]]
11+
t2: """
12+
1,2,3
13+
4,5
14+
7,8,9
15+
16+
"""
17+
t3: """
18+
a,b
19+
c
20+
21+
"""
22+

pkg/encoding/hex/testdata/gen.txtar

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,11 @@ Errors:
1212
error in call to encoding/hex.Decode: encoding/hex: invalid byte: U+006F 'o'
1313

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

pkg/encoding/json/testdata/gen.txtar

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,33 @@ Errors:
2020
a: error in call to encoding/json.Validate: invalid value 10 (out of bound <3)
2121

2222
Result:
23-
(_|_){
24-
// [eval]
25-
t1: (bool){ true }
26-
t2: (_|_){
27-
// [eval] a: error in call to encoding/json.Validate: invalid value 10 (out of bound <3)
28-
}
29-
t3: (bool){ true }
30-
t4: (string){ "[1,2]" }
31-
t5: (string){ "{\n \"a\": 1,\n \"b\": 2\n}" }
32-
t6: (int){ 1 }
33-
t7: (string){ "{\"a\":1}\n{\"b\":2}\n" }
34-
t8: (struct){
35-
x: (int){ int }
36-
y: (_|_){
37-
// [incomplete] cannot convert incomplete value "int" to JSON
38-
}
39-
}
40-
t9: (string){ "{\"a\":1}\n{\"b\":2}\n" }
23+
import "encoding/json"
24+
25+
t1: true
26+
t2: _|_ // error in call to encoding/json.Validate: a: invalid value 10 (out of bound <3) (and 1 more errors)
27+
t3: true
28+
t4: "[1,2]"
29+
t5: """
30+
{
31+
"a": 1,
32+
"b": 2
33+
}
34+
"""
35+
t6: 1
36+
t7: """
37+
{"a":1}
38+
{"b":2}
39+
40+
"""
41+
t8: {
42+
x: int
43+
y: json.Marshal({
44+
a: x
45+
})
4146
}
47+
t9: """
48+
{"a":1}
49+
{"b":2}
50+
51+
"""
52+

pkg/encoding/yaml/testdata/gen.txtar

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,26 @@ a: error in call to encoding/yaml.ValidatePartial: invalid value 4 (out of bound
1919
b: error in call to encoding/yaml.Validate: incomplete value int
2020

2121
Result:
22-
(_|_){
23-
// [eval]
24-
t1: (_|_){
25-
// [eval] a: error in call to encoding/yaml.Validate: invalid value 4 (out of bound <3)
26-
}
27-
t2: (bool){ true }
28-
t3: (_|_){
29-
// [eval] b: error in call to encoding/yaml.Validate: incomplete value int
30-
}
31-
t4: (_|_){
32-
// [eval] a: error in call to encoding/yaml.ValidatePartial: invalid value 4 (out of bound <3)
33-
}
34-
t5: (bool){ true }
35-
t6: (bool){ true }
36-
t7: (string){ "a: 1\n---\nb: 2\n" }
37-
t8: (string){ "b: 2\n" }
38-
t9: (string){ "a: 1\n---\nb: 2\n" }
39-
}
22+
t1: _|_ // error in call to encoding/yaml.Validate: a: invalid value 4 (out of bound <3) (and 1 more errors)
23+
t2: true
24+
t3: _|_ // error in call to encoding/yaml.Validate: b: incomplete value int (and 1 more errors)
25+
t4: _|_ // error in call to encoding/yaml.ValidatePartial: a: invalid value 4 (out of bound <3) (and 1 more errors)
26+
t5: true
27+
t6: true
28+
t7: """
29+
a: 1
30+
---
31+
b: 2
32+
33+
"""
34+
t8: """
35+
b: 2
36+
37+
"""
38+
t9: """
39+
a: 1
40+
---
41+
b: 2
42+
43+
"""
44+

pkg/internal/builtintest/testing.go

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ import (
1919
"testing"
2020

2121
"cuelang.org/go/cue"
22-
"cuelang.org/go/internal/core/debug"
22+
"cuelang.org/go/cue/format"
2323
"cuelang.org/go/internal/core/eval"
24+
"cuelang.org/go/internal/core/export"
2425
"cuelang.org/go/internal/core/validate"
2526
"cuelang.org/go/internal/cuetxtar"
2627
)
@@ -36,9 +37,9 @@ func Run(name string, t *testing.T) {
3637
test.Run(t, func(t *cuetxtar.Test) {
3738
a := t.ValidInstances()
3839

39-
v, err := r.Build(a[0])
40-
if err != nil {
41-
t.Fatal(err)
40+
v, errs := r.Build(a[0])
41+
if errs != nil {
42+
t.Fatal(errs)
4243
}
4344

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

57-
debug.WriteNode(t, r, v, &debug.Config{Cwd: t.Dir})
58-
fmt.Fprintln(t)
58+
p := export.All
59+
p.ShowErrors = true
60+
61+
files, errs := p.Vertex(r, test.Name, v)
62+
if errs != nil {
63+
t.Fatal(errs)
64+
}
65+
66+
b, err := format.Node(files)
67+
if err != nil {
68+
t.Fatal(err)
69+
}
70+
71+
fmt.Fprintln(t, string(b))
5972
})
6073
}

0 commit comments

Comments
 (0)