this repo has no description
0
fork

Configure Feed

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

cue: move fuzz_test.go from cue/parser and expand a bit

We want to fuzz more than just cue/parser.
For example, I just ran into a panic with `cue fix`
because cue/ast.TryClause is not covered in cue/ast/astutil.Apply;
that's a bug that we could have easily caught with some fuzzing.

The cue package is a better home for a high-level and broad fuzzer.
We will expand this fuzzer in the following commits.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
Change-Id: Ia8c6ef211a0ab96aecbb18031b0ada7891e05e5a
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1234631
Reviewed-by: Matthew Sackman <matthew@cue.works>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>

+77 -63
+77
cue/fuzz_test.go
··· 1 + // Copyright 2019 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 cue_test 16 + 17 + import ( 18 + "testing" 19 + 20 + "cuelang.org/go/cue/parser" 21 + ) 22 + 23 + func FuzzStandaloneCUE(f *testing.F) { 24 + // Add a wide sample of different kinds of supported syntax. 25 + f.Add(`package p`) 26 + f.Add(` 27 + import "list" 28 + 29 + list.Concat(["foo"], []) 30 + `) 31 + f.Add(` 32 + // some comment 33 + // group // here 34 + `) 35 + f.Add(`"some string"`) 36 + f.Add(`[1, 2.3, 4M, 5Gi]`) 37 + f.Add(`if foo { if bar if baz { x } }`) 38 + f.Add(`[x for x in [a, b, c]]`) 39 + f.Add(`foo: "bar": (baz): "\(x)": y`) 40 + f.Add(`{x: _, y: _|_}`) 41 + f.Add(`3 & int32`) 42 + f.Add(`string | *"foo"`) 43 + f.Add(`let x = y`) 44 + f.Add(`[1+1, 2-2, 3*3, 4/4]`) 45 + f.Add(`[1>1, 2>=2, 3==3, 4!=4]`) 46 + f.Add(`[=~"^a"]: bool`) 47 + f.Add(`[X=string]: Y={}`) 48 + f.Add(`[len(x), close(y), and([]), or([]), div(5, 2)]`) 49 + f.Add(`[null, bool, float, bytes, int16, uint128]`) 50 + f.Add(`[ [...string], {x: string, ...}]]`) 51 + f.Add(`{regular: x, required!: x, optional?: x}`) 52 + f.Add(`{_hidden: x, #Definition: x, αβ: x}`) 53 + f.Add(`["\u65e5本\U00008a9e", '\xff\u00FF']`) 54 + f.Add(`["\(expr)", #"\#(expr) \(notexpr)"#]`) 55 + f.Add(`{@jsonschema(id="foo"), field: string @go(Field,type=Other)}`) 56 + f.Add(`@experiment(explicitopen), out: #Schema... & data`) 57 + f.Add(`@experiment(aliasv2), "-foo"~A: 42`) 58 + f.Add(`@experiment(try), a?: int, try { b: a? + 1 }`) 59 + f.Add(`@experiment(try), if false { "yes" } else { "no" }`) 60 + f.Add(`@experiment(try), for x in [] { x } fallback { "zero" }`) 61 + f.Fuzz(func(t *testing.T, s string) { 62 + if len(s) > 100 { 63 + t.Skip() // keep inputs reasonably small for now 64 + } 65 + _, err := parser.ParseFile("fuzz.cue", s, parser.ParseComments) 66 + if err != nil { 67 + t.Skip() // skip inputs which aren't valid syntax 68 + } 69 + 70 + // TODO: cover the compiler and evaluator, and various common operations like export 71 + // ctx := cuecontext.New() 72 + // v := ctx.BuildFile(f) 73 + // if err := v.Err(); err != nil { 74 + // return 75 + // } 76 + }) 77 + }
-63
cue/parser/fuzz_test.go
··· 1 - // Copyright 2019 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 parser_test 16 - 17 - import ( 18 - "testing" 19 - 20 - "cuelang.org/go/cue/parser" 21 - ) 22 - 23 - func FuzzParseFile(f *testing.F) { 24 - // Add a wide sample of different kinds of supported syntax. 25 - f.Add([]byte(` 26 - package p 27 - 28 - import "foo" 29 - import b "bar" 30 - import . "baz" 31 - `)) 32 - f.Add([]byte(` 33 - // some comment 34 - // group // here 35 - `)) 36 - f.Add([]byte(`"some string"`)) 37 - f.Add([]byte(`[1, 2.3, 4M, 5Gi]`)) 38 - f.Add([]byte(`if foo { if bar if baz { x } }`)) 39 - f.Add([]byte(`[x for x in [a, b, c]]`)) 40 - f.Add([]byte(`foo: "bar": (baz): "\(x)": y`)) 41 - f.Add([]byte(`{x: _, y: _|_}`)) 42 - f.Add([]byte(`3 & int32`)) 43 - f.Add([]byte(`string | *"foo"`)) 44 - f.Add([]byte(`let x = y`)) 45 - f.Add([]byte(`[1+1, 2-2, 3*3, 4/4]`)) 46 - f.Add([]byte(`[1>1, 2>=2, 3==3, 4!=4]`)) 47 - f.Add([]byte(`[=~"^a"]: bool`)) 48 - f.Add([]byte(`[X=string]: Y={}`)) 49 - f.Add([]byte(`[len(x), close(y), and([]), or([])]`)) 50 - f.Add([]byte(`[null, bool, float, bytes, int16, uint128]`)) 51 - f.Add([]byte(`[ [...string], {x: string, ...}]]`)) 52 - f.Add([]byte(`{regular: x, required!: x, optional?: x}`)) 53 - f.Add([]byte(`{_hidden: x, #Definition: x, αβ: x}`)) 54 - f.Add([]byte(`["\u65e5本\U00008a9e", '\xff\u00FF']`)) 55 - f.Add([]byte(`["\(expr)", #"\#(expr) \(notexpr)"#]`)) 56 - f.Add([]byte(`{@jsonschema(id="foo"), field: string @go(Field)}`)) 57 - f.Fuzz(func(t *testing.T, b []byte) { 58 - _, err := parser.ParseFile("fuzz.cue", b) 59 - if err != nil { 60 - t.Skip() 61 - } 62 - }) 63 - }