this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

doc/tutorial/basics: make test scripts run again

The test scripts have been silently skipped since
https://cue-review.googlesource.com/c/cue/+/6081 was merged in mid 2020.
The reason is that the following bit of code:

if !info.IsDir() {
return nil
}

was replaced with

if info.IsDir() {
return filepath.SkipDir
}

The old code simply ran testscript on each directory found under the
current directory, which makes sense as we have a handful of directories
containing testscript files.

The new code, however, would skip all directories. Crucially, the walk
begins at the root directory, so it wouldn't do any walking at all.

This wasn't picked up for over two years, as it's hard to notice when
tests stop working completely. They behave almost exactly like passing
tests, except perhaps that they take nearly no time at all.

Fix the test code so that they run again. We could keep using directory
walking, but we don't really need to: ReadDir is enough, combined with a
regexp to match directories that follow the n_ABC naming pattern. It's
also simpler, and we can complain if we find zero directories.

In the process we also fix the tutorial tests that are broken. These
changes fall into a number of categories:

* Whitespace differences in output (indenting, formatting of CUE).
* Simple updates to output; ordering of fields or detail in error
messages.
* Whilst we await a fix for #1786, we drop use of the -i (or --ignore)
flag, output stderr instead of stdout, and expect command failure.
These changes can be undone if/when we fix #1786. Or we can leave
with stderr, on the basis this is the more likely experience for a
user.

Rename doc/tutorial/basics/0_intro/10_json.txtarar =>
doc/tutorial/basics/0_intro/10_json.txtar too.

A number of tutorial entries no longer make sense in the context of
changes that have happened over time, but we leave those semantic and
content changes for later, instead focussing on fixing up broken test
cases for now.

The result of this CL has been previewed for cuelang.org in:

https://github.com/cue-lang/cuelang.org/pull/267

Fixes #1884.

Co-authored-by: Paul Jolly <paul@myitcv.io>
Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
Change-Id: I662b5c0fee6deb072441e4fe9d2c1c6ec99ea22a
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/542692
Unity-Result: CUEcueckoo <cueckoo@cuelang.org>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>

authored by

Daniel Martí
Paul Jolly
and committed by
Paul Jolly
6cb877ec 74566cff

+129 -101
+5 -5
doc/tutorial/basics/0_intro/10_json.txtarar doc/tutorial/basics/0_intro/10_json.txtar
··· 1 - cue export json.cue 1 + exec cue export json.cue 2 2 cmp stdout expect-stdout-cue 3 3 4 4 -- frontmatter.toml -- ··· 42 42 43 43 -- expect-stdout-cue -- 44 44 { 45 + "one": 1, 46 + "two": 2, 47 + "two-and-a-half": 2.5, 45 48 "list": [ 46 49 1, 47 50 2, 48 51 3 49 - ], 50 - "one": 1, 51 - "two": 2, 52 - "two-and-a-half": 2.5 52 + ] 53 53 }
+1 -1
doc/tutorial/basics/0_intro/47_validation.txtar
··· 26 26 name: Norwegian 27 27 28 28 -- expect-stderr -- 29 - languages.1.name: invalid value "dutch" (does not match =~"^\\p{Lu}"): 29 + languages.1.name: invalid value "dutch" (out of bound =~"^\\p{Lu}"): 30 30 ./schema.cue:3:8 31 31 ./data.yaml:5:12
+2 -1
doc/tutorial/basics/0_intro/50_order.txtar
··· 1 - exec cue eval -i order.cue 1 + # TODO: revert to cue eval -i post fix for #1786 2 + exec cue eval order.cue 2 3 cmp stdout expect-stdout-cue 3 4 4 5 -- frontmatter.toml --
+12 -8
doc/tutorial/basics/2_types/20_bottom.txtar
··· 1 - exec cue eval -i bottom.cue 2 - cmp stdout expect-stdout-cue 1 + # TODO: revert to cue eval -i post fix for #1786 2 + ! exec cue eval bottom.cue 3 + cmp stderr expect-stderr 3 4 4 5 -- frontmatter.toml -- 5 6 title = "Bottom / Error" ··· 27 28 list: [0, 1, 2] 28 29 val: list[3] 29 30 30 - -- expect-stdout-cue -- 31 - list: [0, 1, 2] 32 - a: _|_ // conflicting values 4 and 5 33 - l: [1, _|_, // conflicting values 2 and 3 34 - ] 35 - val: _|_ // index 3 out of bounds 31 + -- expect-stderr -- 32 + a: conflicting values 5 and 4: 33 + ./bottom.cue:1:4 34 + ./bottom.cue:2:4 35 + l.1: conflicting values 3 and 2: 36 + ./bottom.cue:4:9 37 + ./bottom.cue:5:9 38 + val: index out of range [3] with length 3: 39 + ./bottom.cue:8:11
+7 -8
doc/tutorial/basics/2_types/30_numbers.txtar
··· 1 - exec cue eval -i numbers.cue 2 - cmp stdout expect-stdout-cue 1 + # TODO: revert to cue eval -i post fix for #1786 2 + ! exec cue eval numbers.cue 3 + cmp stderr expect-stderr 3 4 4 5 -- frontmatter.toml -- 5 6 title = "Numbers" ··· 37 38 0x1000_0000, // 268_435_456 38 39 ] 39 40 40 - -- expect-stdout-cue -- 41 - a: 4 42 - b: 4.0 43 - c: _|_ // conflicting values int and 4.0 (mismatched types int and float) 44 - d: 4 45 - e: [1234, 5000000, 1610612736, 268435456] 41 + -- expect-stderr -- 42 + c: conflicting values int and 4.0 (mismatched types int and float): 43 + ./numbers.cue:7:4 44 + ./numbers.cue:8:4
+7 -7
doc/tutorial/basics/2_types/45_stringraw.txtar
··· 29 29 -- expect-stdout-cue -- 30 30 msg1: "The sequence \"\\U0001F604\" renders as 😄." 31 31 msg2: """ 32 - A regular expression can conveniently be written as: 33 - 34 - #\"\\d{3}\"# 35 - 36 - This construct works for bytes, strings and their 37 - multi-line variants. 38 - """ 32 + A regular expression can conveniently be written as: 33 + 34 + #"\\d{3}"# 35 + 36 + This construct works for bytes, strings and their 37 + multi-line variants. 38 + """
+8 -7
doc/tutorial/basics/2_types/50_closed.txtar
··· 1 - exec cue eval -i structs.cue 2 - cmp stdout expect-stdout-cue 1 + # TODO: revert to cue eval -i post fix for #1786 2 + ! exec cue eval structs.cue 3 + cmp stderr expect-stderr 3 4 4 5 -- frontmatter.toml -- 5 6 title = "Closed structs" ··· 26 27 feild: 3 27 28 } 28 29 29 - -- expect-stdout-cue -- 30 - a: { 31 - field: int 32 - } 33 - b: _|_ // field "feild" not allowed in closed struct 30 + -- expect-stderr -- 31 + b.feild: field not allowed: 32 + ./structs.cue:1:10 33 + ./structs.cue:5:4 34 + ./structs.cue:6:5
+8 -8
doc/tutorial/basics/2_types/55_defs.txtar
··· 1 - exec cue eval -ic defs.cue 2 - cmp stdout expect-stdout-cue 1 + # TODO: revert to cue eval -i post fix for #1786 2 + ! exec cue eval -c defs.cue 3 + cmp stderr expect-stderr 3 4 4 5 -- frontmatter.toml -- 5 6 title = "Definitions" ··· 26 27 a: #A & { field: 3 } 27 28 err: #A & { feild: 3 } 28 29 29 - -- expect-stdout-cue -- 30 - msg: "Hello world!" 31 - a: { 32 - field: 3 33 - } 34 - err: _|_ // field "feild" not allowed in closed struct 30 + -- expect-stderr -- 31 + err.feild: field not allowed: 32 + ./defs.cue:5:5 33 + ./defs.cue:10:6 34 + ./defs.cue:10:13
+1 -1
doc/tutorial/basics/2_types/65_defaults.txtar
··· 26 26 27 27 -- expect-stdout-cue -- 28 28 replicas: 1 29 - protocol: "tcp" | "udp" | *_|_ 29 + protocol: "tcp" | "udp"
+10 -9
doc/tutorial/basics/2_types/70_bounds.txtar
··· 1 - exec cue eval -ic bounds.cue 2 - cmp stdout expect-stdout-cue 1 + # TODO: revert to cue eval -i post fix for #1786 2 + ! exec cue eval -c bounds.cue 3 + cmp stderr expect-stderr 3 4 4 5 -- frontmatter.toml -- 5 6 title = "Bounds" ··· 28 29 29 30 r1: #rn & >=5 & <10 30 31 31 - -- expect-stdout-cue -- 32 - a: 3.5 33 - b: _|_ // conflicting values #ri and 3.5 (mismatched types int and float) 34 - c: 3 35 - d: "ma" 36 - e: _|_ // invalid value "mu" (out of bound <"mo") 37 - r1: >=5 & <8 32 + -- expect-stderr -- 33 + b: conflicting values int and 3.5 (mismatched types int and float): 34 + ./bounds.cue:2:17 35 + ./bounds.cue:7:10 36 + e: invalid value "mu" (out of bound <"mo"): 37 + ./bounds.cue:4:14 38 + ./bounds.cue:10:10
+6 -6
doc/tutorial/basics/2_types/75_bounddef.txtar
··· 1 - exec cue eval -ic bound.cue 2 - cmp stdout expect-stdout-cue 1 + # TODO: revert to cue eval -i post fix for #1786 2 + ! exec cue eval -c bound.cue 3 + cmp stderr expect-stderr 3 4 4 5 -- frontmatter.toml -- 5 6 title = "Predefined Bounds" ··· 37 38 b: #byte & 128 38 39 c: #word & 2_000_000_000 39 40 40 - -- expect-stdout-cue -- 41 - a: _|_ // invalid value -1 (out of bound int & >=0) 42 - b: 128 43 - c: 2000000000 41 + -- expect-stderr -- 42 + a: invalid value -1 (out of bound >=0): 43 + ./bound.cue:5:16
+17 -7
doc/tutorial/basics/2_types/80_lists.txtar
··· 1 - exec cue eval -i lists.cue 2 - cmp stdout expect-stdout-cue 1 + # TODO: revert to cue eval -i post fix for #1786 2 + ! exec cue eval lists.cue 3 + cmp stderr expect-stderr 3 4 4 5 -- frontmatter.toml -- 5 6 title = "Lists" ··· 38 39 yourIP: PrivateIP 39 40 yourIP: [11, 1, 2, 3] 40 41 41 - -- expect-stdout-cue -- 42 - IP: [uint8, uint8, uint8, uint8] 43 - PrivateIP: [10, uint8, uint8, uint8] | [192, 168, uint8, uint8] | [172, >=16 & <=32 & uint8, uint8, uint8] 44 - myIP: [10, 2, 3, 4] 45 - yourIP: _|_ // ; empty disjunction: conflicting values 192 and 11; empty disjunction: conflicting values 172 and 11 42 + -- expect-stderr -- 43 + yourIP: 3 errors in empty disjunction: 44 + yourIP.0: conflicting values 10 and 11: 45 + ./lists.cue:6:13 46 + ./lists.cue:13:9 47 + ./lists.cue:14:10 48 + yourIP.0: conflicting values 172 and 11: 49 + ./lists.cue:8:6 50 + ./lists.cue:13:9 51 + ./lists.cue:14:10 52 + yourIP.0: conflicting values 192 and 11: 53 + ./lists.cue:7:6 54 + ./lists.cue:13:9 55 + ./lists.cue:14:10
+1 -1
doc/tutorial/basics/2_types/90_templates.txtar
··· 44 44 } 45 45 nginx: { 46 46 name: "nginx" 47 - replicas: 2 48 47 command: "nginx" 48 + replicas: 2 49 49 } 50 50 }
+1 -1
doc/tutorial/basics/4_references/10_scopes.txtar
··· 29 29 v: 1 30 30 a: { 31 31 v: 2 32 - b: 2 33 32 c: 1 33 + b: 2 34 34 } 35 35 b: 1
+1 -1
doc/tutorial/basics/4_references/50_emit.txtar
··· 1 - exec cue eval emit.cue 1 + exec cue export emit.cue 2 2 cmp stdout expect-stdout-cue 3 3 4 4 -- frontmatter.toml --
+6 -7
doc/tutorial/basics/4_references/80_cycle.txtar
··· 1 - exec cue eval -i -c cycle.cue 2 - cmp stdout expect-stdout-cue 1 + # TODO: revert to cue eval -i post fix for #1786 2 + ! exec cue eval -c cycle.cue 3 + cmp stderr expect-stderr 3 4 4 5 -- frontmatter.toml -- 5 6 title = "Reference Cycles" ··· 26 27 a: b + 100 27 28 b: a - 100 28 29 29 - -- expect-stdout-cue -- 30 - x: 200 31 - y: 100 32 - a: _|_ // cycle detected 33 - b: _|_ // cycle detected 30 + -- expect-stderr -- 31 + cycle error: 32 + ./cycle.cue:7:4
+1 -1
doc/tutorial/basics/4_references/85_cycleref.txtar
··· 20 20 21 21 -- expect-stdout-cue -- 22 22 labels: { 23 - name: "bar" 24 23 app: "foo" 24 + name: "bar" 25 25 } 26 26 selectors: { 27 27 name: "bar"
+1 -1
doc/tutorial/basics/6_expressions/20_interpolation.txtar
··· 1 - exec cue eval interpolation.cue 1 + exec cue export interpolation.cue 2 2 cmp stdout expect-stdout-cue 3 3 4 4 -- frontmatter.toml --
+7 -2
doc/tutorial/basics/6_expressions/40_listcomp.txtar
··· 1 - exec cue eval listcomp.cue 1 + exec cue export listcomp.cue 2 2 cmp stdout expect-stdout-cue 3 3 4 4 -- frontmatter.toml -- ··· 16 16 #items: [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ] 17 17 18 18 -- expect-stdout-cue -- 19 - [4, 16, 36, 64] 19 + [ 20 + 4, 21 + 16, 22 + 36, 23 + 64 24 + ]
+3 -3
doc/tutorial/basics/6_expressions/50_fieldcomp.txtar
··· 26 26 27 27 -- expect-stdout-cue -- 28 28 barcelona: { 29 - name: "Barcelona" 30 29 pos: 1 30 + name: "Barcelona" 31 31 nameLen: 9 32 32 } 33 33 shanghai: { 34 - name: "Shanghai" 35 34 pos: 2 35 + name: "Shanghai" 36 36 nameLen: 8 37 37 } 38 38 munich: { 39 - name: "Munich" 40 39 pos: 3 40 + name: "Munich" 41 41 nameLen: 6 42 42 }
+1 -1
doc/tutorial/basics/6_expressions/55_conditional.txtar
··· 23 23 price: 200 24 24 25 25 -- expect-stdout-cue -- 26 - price: 200 27 26 justification: string 27 + price: 200
+8 -8
doc/tutorial/basics/6_expressions/70_regexp.txtar
··· 1 - exec cue eval -i regexp.cue 2 - cmp stdout expect-stdout-cue 1 + # TODO: revert to cue eval -i post fix for #1786 2 + ! exec cue eval regexp.cue 3 + cmp stderr expect-stderr 3 4 4 5 -- frontmatter.toml -- 5 6 title = "Regular expressions" ··· 26 27 e: c 27 28 e: "foo bar" 28 29 29 - -- expect-stdout-cue -- 30 - a: true 31 - b: true 32 - c: =~"^[a-z]{3}$" 33 - d: "foo" 34 - e: _|_ // invalid value "foo bar" (does not match =~"^[a-z]{3}$") 30 + -- expect-stderr -- 31 + e: invalid value "foo bar" (out of bound =~"^[a-z]{3}$"): 32 + ./regexp.cue:4:4 33 + ./regexp.cue:9:4 34 + ./regexp.cue:10:4
+15 -7
doc/tutorial/basics/script_test.go
··· 5 5 "os" 6 6 "path" 7 7 "path/filepath" 8 + "regexp" 8 9 "strings" 9 10 "testing" 10 11 ··· 51 52 } 52 53 53 54 func TestScript(t *testing.T) { 54 - if err := filepath.WalkDir(".", func(path string, entry fs.DirEntry, err error) error { 55 - if entry.IsDir() { 56 - return filepath.SkipDir 55 + tourDir := regexp.MustCompile(`^\d+_.+`) 56 + entries, err := os.ReadDir(".") 57 + if err != nil { 58 + t.Fatal(err) 59 + } 60 + didWork := false 61 + for _, entry := range entries { 62 + if !entry.IsDir() || !tourDir.MatchString(entry.Name()) { 63 + continue 57 64 } 65 + didWork = true 58 66 testscript.Run(t, testscript.Params{ 59 - Dir: path, 67 + Dir: entry.Name(), 60 68 UpdateScripts: cuetest.UpdateGoldenFiles, 61 69 RequireExplicitExec: true, 62 70 }) 63 - return nil 64 - }); err != nil { 65 - t.Fatal(err) 71 + } 72 + if !didWork { 73 + t.Fatal("failed to find any steps in the tour") 66 74 } 67 75 } 68 76