diff --git a/lang/interpret_test.go b/lang/interpret_test.go index 65f4bde2..a7366139 100644 --- a/lang/interpret_test.go +++ b/lang/interpret_test.go @@ -587,31 +587,11 @@ func TestAstFunc1(t *testing.T) { Functions: ast.FuncPrefixToFunctionsScope(""), // runs funcs.LookupPrefix } - type errs struct { - failLexParse bool - failInit bool - failSetScope bool - failUnify bool - failGraph bool - } type test struct { // an individual test name string - path string // relative sub directory path inside tests dir - fail bool - //graph *pgraph.Graph - expstr string // expected graph in string format - errs errs + path string // relative txtar path inside tests dir } testCases := []test{} - //{ - // graph, _ := pgraph.NewGraph("g") - // testCases = append(testCases, test{ - // name: "simple hello world", - // path: "hello0/", - // fail: false, - // expstr: graph.Sprint(), - // }) - //} // build test array automatically from reading the dir files, err := ioutil.ReadDir(dir) @@ -621,87 +601,19 @@ func TestAstFunc1(t *testing.T) { } sorted := []string{} for _, f := range files { - if !f.IsDir() { + if !strings.HasSuffix(f.Name(), ".txtar") { continue } + sorted = append(sorted, f.Name()) } sort.Strings(sorted) for _, f := range sorted { - graphFile := f + ".graph" // expected graph file - graphFileFull := dir + graphFile - info, err := os.Stat(graphFileFull) - if err != nil || info.IsDir() { - p := dir + f + "." + "T" + "O" + "D" + "O" - if _, err := os.Stat(p); err == nil { - // if it's a WIP, then don't error things - t.Logf("missing: %s", p) - continue - } - t.Errorf("missing: %s", graphFile) - t.Errorf("(err: %+v)", err) - continue - } - content, err := ioutil.ReadFile(graphFileFull) - if err != nil { - t.Errorf("could not read graph file: %+v", err) - return - } - str := string(content) // expected graph - - // if the graph file has a magic error string, it's a failure - errStr := "" - failLexParse := false - failInit := false - failSetScope := false - failUnify := false - failGraph := false - if strings.HasPrefix(str, magicError) { - errStr = strings.TrimPrefix(str, magicError) - str = errStr - - if strings.HasPrefix(str, magicErrorLexParse) { - errStr = strings.TrimPrefix(str, magicErrorLexParse) - str = errStr - failLexParse = true - } - if strings.HasPrefix(str, magicErrorInit) { - errStr = strings.TrimPrefix(str, magicErrorInit) - str = errStr - failInit = true - } - if strings.HasPrefix(str, magicErrorSetScope) { - errStr = strings.TrimPrefix(str, magicErrorSetScope) - str = errStr - failSetScope = true - } - if strings.HasPrefix(str, magicErrorUnify) { - errStr = strings.TrimPrefix(str, magicErrorUnify) - str = errStr - failUnify = true - } - if strings.HasPrefix(str, magicErrorGraph) { - errStr = strings.TrimPrefix(str, magicErrorGraph) - str = errStr - failGraph = true - } - } - // add automatic test case testCases = append(testCases, test{ - name: fmt.Sprintf("dir: %s", f), - path: f + "/", - fail: errStr != "", - expstr: str, - errs: errs{ - failLexParse: failLexParse, - failInit: failInit, - failSetScope: failSetScope, - failUnify: failUnify, - failGraph: failGraph, - }, + name: fmt.Sprintf("%s", f), + path: f, // .txtar }) - //t.Logf("adding: %s", f + "/") } if testing.Short() { @@ -730,13 +642,87 @@ func TestAstFunc1(t *testing.T) { continue } t.Run(testName, func(t *testing.T) { - name, path, fail, expstr, errs := tc.name, tc.path, tc.fail, strings.Trim(tc.expstr, "\n"), tc.errs - src := dir + path // location of the test - failLexParse := errs.failLexParse - failInit := errs.failInit - failSetScope := errs.failSetScope - failUnify := errs.failUnify - failGraph := errs.failGraph + name, path := tc.name, tc.path + tmpdir := t.TempDir() // gets cleaned up at end, new dir for each call + src := tmpdir // location of the test + txtarFile := dir + path + + archive, err := txtar.ParseFile(txtarFile) + if err != nil { + t.Errorf("err parsing txtar(%s): %+v", txtarFile, err) + return + } + comment := strings.TrimSpace(string(archive.Comment)) + t.Logf("comment: %s\n", comment) + + // copy files out into the test temp directory + var testOutput []byte + found := false + for _, file := range archive.Files { + if file.Name == "OUTPUT" { + testOutput = file.Data + found = true + continue + } + + name := filepath.Join(tmpdir, file.Name) + dir := filepath.Dir(name) + if err := os.MkdirAll(dir, 0770); err != nil { + t.Errorf("err making dir(%s): %+v", dir, err) + return + } + if err := ioutil.WriteFile(name, file.Data, 0660); err != nil { + t.Errorf("err writing file(%s): %+v", name, err) + return + } + } + + if !found { // skip missing tests + return + } + + expstr := string(testOutput) // expected graph + + // if the graph file has a magic error string, it's a failure + errStr := "" + failLexParse := false + failInit := false + failSetScope := false + failUnify := false + failGraph := false + if strings.HasPrefix(expstr, magicError) { + errStr = strings.TrimPrefix(expstr, magicError) + expstr = errStr + + if strings.HasPrefix(expstr, magicErrorLexParse) { + errStr = strings.TrimPrefix(expstr, magicErrorLexParse) + expstr = errStr + failLexParse = true + } + if strings.HasPrefix(expstr, magicErrorInit) { + errStr = strings.TrimPrefix(expstr, magicErrorInit) + expstr = errStr + failInit = true + } + if strings.HasPrefix(expstr, magicErrorSetScope) { + errStr = strings.TrimPrefix(expstr, magicErrorSetScope) + expstr = errStr + failSetScope = true + } + if strings.HasPrefix(expstr, magicErrorUnify) { + errStr = strings.TrimPrefix(expstr, magicErrorUnify) + expstr = errStr + failUnify = true + } + if strings.HasPrefix(expstr, magicErrorGraph) { + errStr = strings.TrimPrefix(expstr, magicErrorGraph) + expstr = errStr + failGraph = true + } + } + + fail := errStr != "" + expstr = strings.Trim(expstr, "\n") t.Logf("\n\ntest #%d (%s) ----------------\npath: %s\n\n", index, name, src) diff --git a/lang/interpret_test/TestAstFunc1/changing-func.graph b/lang/interpret_test/TestAstFunc1/changing-func.txtar similarity index 89% rename from lang/interpret_test/TestAstFunc1/changing-func.graph rename to lang/interpret_test/TestAstFunc1/changing-func.txtar index aa9d9af4..0e4360c8 100644 --- a/lang/interpret_test/TestAstFunc1/changing-func.graph +++ b/lang/interpret_test/TestAstFunc1/changing-func.txtar @@ -1,3 +1,26 @@ +-- main.mcl -- +# this can return changing functions, and could be optimized, too +func funcgen($b) { + if $b { + func() { + "hello" + } + } else { + func() { + "world" + } + } +} + +$fn1 = funcgen(true) +$fn2 = funcgen(false) + +$out1 = $fn1() +$out2 = $fn2() + +test $out1 {} +test $out2 {} +-- OUTPUT -- Edge: bool(false) -> call:funcgen(bool(false)) # b Edge: bool(false) -> var(b) # var:b Edge: bool(true) -> call:funcgen(bool(true)) # b diff --git a/lang/interpret_test/TestAstFunc1/changing-func/main.mcl b/lang/interpret_test/TestAstFunc1/changing-func/main.mcl deleted file mode 100644 index b6f756ef..00000000 --- a/lang/interpret_test/TestAstFunc1/changing-func/main.mcl +++ /dev/null @@ -1,21 +0,0 @@ -# this can return changing functions, and could be optimized, too -func funcgen($b) { - if $b { - func() { - "hello" - } - } else { - func() { - "world" - } - } -} - -$fn1 = funcgen(true) -$fn2 = funcgen(false) - -$out1 = $fn1() -$out2 = $fn2() - -test $out1 {} -test $out2 {} diff --git a/lang/interpret_test/TestAstFunc1/classes-polyfuncs.graph b/lang/interpret_test/TestAstFunc1/classes-polyfuncs.txtar similarity index 84% rename from lang/interpret_test/TestAstFunc1/classes-polyfuncs.graph rename to lang/interpret_test/TestAstFunc1/classes-polyfuncs.txtar index b87a04ff..7143bab2 100644 --- a/lang/interpret_test/TestAstFunc1/classes-polyfuncs.graph +++ b/lang/interpret_test/TestAstFunc1/classes-polyfuncs.txtar @@ -1,3 +1,11 @@ +-- main.mcl -- +import "fmt" + +include c1([13, 42, 0, -37,]) +class c1($b) { + test fmt.printf("len is: %d", len($b)) {} # len is 4 +} +-- OUTPUT -- Edge: call:len(var(b)) -> call:fmt.printf(str("len is: %d"), call:len(var(b))) # a Edge: int(-37) -> list(int(13), int(42), int(0), int(-37)) # 3 Edge: int(0) -> list(int(13), int(42), int(0), int(-37)) # 2 diff --git a/lang/interpret_test/TestAstFunc1/classes-polyfuncs/main.mcl b/lang/interpret_test/TestAstFunc1/classes-polyfuncs/main.mcl deleted file mode 100644 index d35df348..00000000 --- a/lang/interpret_test/TestAstFunc1/classes-polyfuncs/main.mcl +++ /dev/null @@ -1,6 +0,0 @@ -import "fmt" - -include c1([13, 42, 0, -37,]) -class c1($b) { - test fmt.printf("len is: %d", len($b)) {} # len is 4 -} diff --git a/lang/interpret_test/TestAstFunc1/comment1.graph b/lang/interpret_test/TestAstFunc1/comment1.graph deleted file mode 100644 index 2459fc2a..00000000 --- a/lang/interpret_test/TestAstFunc1/comment1.graph +++ /dev/null @@ -1 +0,0 @@ -# empty! diff --git a/lang/interpret_test/TestAstFunc1/comment1.txtar b/lang/interpret_test/TestAstFunc1/comment1.txtar new file mode 100644 index 00000000..9373b3b1 --- /dev/null +++ b/lang/interpret_test/TestAstFunc1/comment1.txtar @@ -0,0 +1,4 @@ +-- main.mcl -- +# this is a comment +-- OUTPUT -- +# empty! diff --git a/lang/interpret_test/TestAstFunc1/comment1/main.mcl b/lang/interpret_test/TestAstFunc1/comment1/main.mcl deleted file mode 100644 index 74c84e93..00000000 --- a/lang/interpret_test/TestAstFunc1/comment1/main.mcl +++ /dev/null @@ -1 +0,0 @@ -# this is a comment diff --git a/lang/interpret_test/TestAstFunc1/doubleclass.graph b/lang/interpret_test/TestAstFunc1/doubleclass.txtar similarity index 89% rename from lang/interpret_test/TestAstFunc1/doubleclass.graph rename to lang/interpret_test/TestAstFunc1/doubleclass.txtar index 77fccb9e..339c27a2 100644 --- a/lang/interpret_test/TestAstFunc1/doubleclass.graph +++ b/lang/interpret_test/TestAstFunc1/doubleclass.txtar @@ -1,3 +1,20 @@ +-- main.mcl -- +import "fmt" + +# this value should only be built once +$some_value1 = 42 # or something more complex like the output of a slow function... +class foo($num) { + # we should have a different `$inside` value for each use of this class + $inside = $some_value1 + $some_value2 + 4 + test fmt.printf("test-%d-%d", $num, $inside) {} # some resource +} +$some_value2 = 13 # check that non-ordering works too! + +# We *don't* unnecessarily copy `4` on each include, because it's static! +include foo(1) +include foo(2) +include foo(3) +-- OUTPUT -- Edge: call:_operator(str("+"), call:_operator(str("+"), var(some_value1), var(some_value2)), int(4)) -> var(inside) # var:inside Edge: call:_operator(str("+"), call:_operator(str("+"), var(some_value1), var(some_value2)), int(4)) -> var(inside) # var:inside Edge: call:_operator(str("+"), call:_operator(str("+"), var(some_value1), var(some_value2)), int(4)) -> var(inside) # var:inside diff --git a/lang/interpret_test/TestAstFunc1/doubleclass/main.mcl b/lang/interpret_test/TestAstFunc1/doubleclass/main.mcl deleted file mode 100644 index f4ae138f..00000000 --- a/lang/interpret_test/TestAstFunc1/doubleclass/main.mcl +++ /dev/null @@ -1,15 +0,0 @@ -import "fmt" - -# this value should only be built once -$some_value1 = 42 # or something more complex like the output of a slow function... -class foo($num) { - # we should have a different `$inside` value for each use of this class - $inside = $some_value1 + $some_value2 + 4 - test fmt.printf("test-%d-%d", $num, $inside) {} # some resource -} -$some_value2 = 13 # check that non-ordering works too! - -# We *don't* unnecessarily copy `4` on each include, because it's static! -include foo(1) -include foo(2) -include foo(3) diff --git a/lang/interpret_test/TestAstFunc1/doubleinclude.graph b/lang/interpret_test/TestAstFunc1/doubleinclude.txtar similarity index 67% rename from lang/interpret_test/TestAstFunc1/doubleinclude.graph rename to lang/interpret_test/TestAstFunc1/doubleinclude.txtar index e813b273..7585f481 100644 --- a/lang/interpret_test/TestAstFunc1/doubleinclude.graph +++ b/lang/interpret_test/TestAstFunc1/doubleinclude.txtar @@ -1,3 +1,13 @@ +-- main.mcl -- +include c1("t1") +include c1("t2") +class c1($a) { + test $a { + stringptr => $foo, + } +} +$foo = "hey" +-- OUTPUT -- Edge: str("hey") -> var(foo) # var:foo Edge: str("hey") -> var(foo) # var:foo Edge: str("t1") -> var(a) # var:a diff --git a/lang/interpret_test/TestAstFunc1/doubleinclude/main.mcl b/lang/interpret_test/TestAstFunc1/doubleinclude/main.mcl deleted file mode 100644 index af51a446..00000000 --- a/lang/interpret_test/TestAstFunc1/doubleinclude/main.mcl +++ /dev/null @@ -1,8 +0,0 @@ -include c1("t1") -include c1("t2") -class c1($a) { - test $a { - stringptr => $foo, - } -} -$foo = "hey" diff --git a/lang/interpret_test/TestAstFunc1/duplicate_resource.graph b/lang/interpret_test/TestAstFunc1/duplicate_resource.graph deleted file mode 100644 index 39d1a657..00000000 --- a/lang/interpret_test/TestAstFunc1/duplicate_resource.graph +++ /dev/null @@ -1,10 +0,0 @@ -Edge: str("hello world") -> call:fmt.printf(str("hello world")) # format -Vertex: call:fmt.printf(str("hello world")) -Vertex: str("/tmp/foo") -Vertex: str("/tmp/foo") -Vertex: str("cowsay") -Vertex: str("cowsay") -Vertex: str("hello world") -Vertex: str("hello world") -Vertex: str("installed") -Vertex: str("newest") diff --git a/lang/interpret_test/TestAstFunc1/duplicate_resource/main.mcl b/lang/interpret_test/TestAstFunc1/duplicate_resource.txtar similarity index 50% rename from lang/interpret_test/TestAstFunc1/duplicate_resource/main.mcl rename to lang/interpret_test/TestAstFunc1/duplicate_resource.txtar index 6f15b578..ec9988dc 100644 --- a/lang/interpret_test/TestAstFunc1/duplicate_resource/main.mcl +++ b/lang/interpret_test/TestAstFunc1/duplicate_resource.txtar @@ -1,3 +1,4 @@ +-- main.mcl -- import "fmt" # these two resources are identical to each other, so we should allow it @@ -15,3 +16,14 @@ pkg "cowsay" { pkg "cowsay" { state => "newest", } +-- OUTPUT -- +Edge: str("hello world") -> call:fmt.printf(str("hello world")) # format +Vertex: call:fmt.printf(str("hello world")) +Vertex: str("/tmp/foo") +Vertex: str("/tmp/foo") +Vertex: str("cowsay") +Vertex: str("cowsay") +Vertex: str("hello world") +Vertex: str("hello world") +Vertex: str("installed") +Vertex: str("newest") diff --git a/lang/interpret_test/TestAstFunc1/efficient-lambda.graph b/lang/interpret_test/TestAstFunc1/efficient-lambda.txtar similarity index 85% rename from lang/interpret_test/TestAstFunc1/efficient-lambda.graph rename to lang/interpret_test/TestAstFunc1/efficient-lambda.txtar index a9ab33e0..63ced61a 100644 --- a/lang/interpret_test/TestAstFunc1/efficient-lambda.graph +++ b/lang/interpret_test/TestAstFunc1/efficient-lambda.txtar @@ -1,3 +1,15 @@ +-- main.mcl -- +# this should be a function as a value, iow a lambda +$prefixer = func($x) { + "hello" + $x # i'd only ever expect one "hello" string in the graph +} + +$out1 = $prefixer("a") +$out2 = $prefixer("b") + +test $out1 {} # helloa +test $out2 {} # hellob +-- OUTPUT -- Edge: call:_operator(str("+"), str("hello"), var(x)) -> func(x) { call:_operator(str("+"), str("hello"), var(x)) } # body Edge: call:_operator(str("+"), str("hello"), var(x)) -> func(x) { call:_operator(str("+"), str("hello"), var(x)) } # body Edge: call:prefixer(str("a")) -> var(out1) # var:out1 diff --git a/lang/interpret_test/TestAstFunc1/efficient-lambda/main.mcl b/lang/interpret_test/TestAstFunc1/efficient-lambda/main.mcl deleted file mode 100644 index beaa4d39..00000000 --- a/lang/interpret_test/TestAstFunc1/efficient-lambda/main.mcl +++ /dev/null @@ -1,10 +0,0 @@ -# this should be a function as a value, iow a lambda -$prefixer = func($x) { - "hello" + $x # i'd only ever expect one "hello" string in the graph -} - -$out1 = $prefixer("a") -$out2 = $prefixer("b") - -test $out1 {} # helloa -test $out2 {} # hellob diff --git a/lang/interpret_test/TestAstFunc1/empty-res-list-0.graph b/lang/interpret_test/TestAstFunc1/empty-res-list-0.graph deleted file mode 100644 index c040f8ca..00000000 --- a/lang/interpret_test/TestAstFunc1/empty-res-list-0.graph +++ /dev/null @@ -1 +0,0 @@ -# err: errUnify: only recursive solutions left diff --git a/lang/interpret_test/TestAstFunc1/empty-res-list-0/main.mcl b/lang/interpret_test/TestAstFunc1/empty-res-list-0.txtar similarity index 77% rename from lang/interpret_test/TestAstFunc1/empty-res-list-0/main.mcl rename to lang/interpret_test/TestAstFunc1/empty-res-list-0.txtar index af16329e..78dab297 100644 --- a/lang/interpret_test/TestAstFunc1/empty-res-list-0/main.mcl +++ b/lang/interpret_test/TestAstFunc1/empty-res-list-0.txtar @@ -1,5 +1,8 @@ +-- main.mcl -- # this is an empty list of test resources, iow test resources # this must pass type unification # this can only currently pass if we allow recursive unification solving # if we do, then the function graph is: `Vertex: list()` otherwise it's an error test [] {} +-- OUTPUT -- +# err: errUnify: only recursive solutions left diff --git a/lang/interpret_test/TestAstFunc1/empty-res-list-1.graph b/lang/interpret_test/TestAstFunc1/empty-res-list-1.txtar similarity index 64% rename from lang/interpret_test/TestAstFunc1/empty-res-list-1.graph rename to lang/interpret_test/TestAstFunc1/empty-res-list-1.txtar index cb0d1864..b8ddff70 100644 --- a/lang/interpret_test/TestAstFunc1/empty-res-list-1.graph +++ b/lang/interpret_test/TestAstFunc1/empty-res-list-1.txtar @@ -1,3 +1,14 @@ +-- main.mcl -- +# single resource +test "name" {} + +# single resource, defined by list variable +$names = ["hey",] +test $names {} + +# multiples resources, defined by list +test ["hello", "world",] {} +-- OUTPUT -- Edge: list(str("hey")) -> var(names) # var:names Edge: str("hello") -> list(str("hello"), str("world")) # 0 Edge: str("hey") -> list(str("hey")) # 0 diff --git a/lang/interpret_test/TestAstFunc1/empty-res-list-1/main.mcl b/lang/interpret_test/TestAstFunc1/empty-res-list-1/main.mcl deleted file mode 100644 index a17f142c..00000000 --- a/lang/interpret_test/TestAstFunc1/empty-res-list-1/main.mcl +++ /dev/null @@ -1,9 +0,0 @@ -# single resource -test "name" {} - -# single resource, defined by list variable -$names = ["hey",] -test $names {} - -# multiples resources, defined by list -test ["hello", "world",] {} diff --git a/lang/interpret_test/TestAstFunc1/fail1.graph b/lang/interpret_test/TestAstFunc1/fail1.graph deleted file mode 100644 index ee7584b6..00000000 --- a/lang/interpret_test/TestAstFunc1/fail1.graph +++ /dev/null @@ -1 +0,0 @@ -# err: errLexParse: parser: `syntax error: unexpected COLON` @2:8 diff --git a/lang/interpret_test/TestAstFunc1/fail1.txtar b/lang/interpret_test/TestAstFunc1/fail1.txtar new file mode 100644 index 00000000..e80aae29 --- /dev/null +++ b/lang/interpret_test/TestAstFunc1/fail1.txtar @@ -0,0 +1,7 @@ +-- main.mcl -- +# this is not valid mcl code, this is puppet! +file { "/tmp/foo": + ensure => present, +} +-- OUTPUT -- +# err: errLexParse: parser: `syntax error: unexpected COLON` @2:8 diff --git a/lang/interpret_test/TestAstFunc1/fail1/main.mcl b/lang/interpret_test/TestAstFunc1/fail1/main.mcl deleted file mode 100644 index 8dc1c4dc..00000000 --- a/lang/interpret_test/TestAstFunc1/fail1/main.mcl +++ /dev/null @@ -1,4 +0,0 @@ -# this is not valid mcl code, this is puppet! -file { "/tmp/foo": - ensure => present, -} diff --git a/lang/interpret_test/TestAstFunc1/fail2.graph b/lang/interpret_test/TestAstFunc1/fail2.graph deleted file mode 100644 index 117e77cb..00000000 --- a/lang/interpret_test/TestAstFunc1/fail2.graph +++ /dev/null @@ -1 +0,0 @@ -# err: errUnify: can't unify, invariant illogicality with equality: base kind does not match (Str != Int) diff --git a/lang/interpret_test/TestAstFunc1/fail2/main.mcl b/lang/interpret_test/TestAstFunc1/fail2.txtar similarity index 50% rename from lang/interpret_test/TestAstFunc1/fail2/main.mcl rename to lang/interpret_test/TestAstFunc1/fail2.txtar index 0ca8a2de..4fb30fee 100644 --- a/lang/interpret_test/TestAstFunc1/fail2/main.mcl +++ b/lang/interpret_test/TestAstFunc1/fail2.txtar @@ -1,3 +1,4 @@ +-- main.mcl -- import "fmt" $x str = if true { # should fail unification 42 @@ -7,3 +8,5 @@ $x str = if true { # should fail unification test "t1" { anotherstr => fmt.printf("hello %s", $x), } +-- OUTPUT -- +# err: errUnify: can't unify, invariant illogicality with equality: base kind does not match (Str != Int) diff --git a/lang/interpret_test/TestAstFunc1/hello0.graph b/lang/interpret_test/TestAstFunc1/hello0.txtar similarity index 72% rename from lang/interpret_test/TestAstFunc1/hello0.graph rename to lang/interpret_test/TestAstFunc1/hello0.txtar index 6c910e51..cf353196 100644 --- a/lang/interpret_test/TestAstFunc1/hello0.graph +++ b/lang/interpret_test/TestAstFunc1/hello0.txtar @@ -1,3 +1,12 @@ +-- main.mcl -- +import "fmt" + +$s = "world" + +test "greeting" { + anotherstr => fmt.printf("hello: %s", $s), +} +-- OUTPUT -- Edge: str("hello: %s") -> call:fmt.printf(str("hello: %s"), var(s)) # format Edge: str("world") -> var(s) # var:s Edge: var(s) -> call:fmt.printf(str("hello: %s"), var(s)) # a diff --git a/lang/interpret_test/TestAstFunc1/hello0/main.mcl b/lang/interpret_test/TestAstFunc1/hello0/main.mcl deleted file mode 100644 index 327ccd0c..00000000 --- a/lang/interpret_test/TestAstFunc1/hello0/main.mcl +++ /dev/null @@ -1,7 +0,0 @@ -import "fmt" - -$s = "world" - -test "greeting" { - anotherstr => fmt.printf("hello: %s", $s), -} diff --git a/lang/interpret_test/TestAstFunc1/importscope2.graph b/lang/interpret_test/TestAstFunc1/importscope0.txtar similarity index 63% rename from lang/interpret_test/TestAstFunc1/importscope2.graph rename to lang/interpret_test/TestAstFunc1/importscope0.txtar index 4891fc78..f3edfbc3 100644 --- a/lang/interpret_test/TestAstFunc1/importscope2.graph +++ b/lang/interpret_test/TestAstFunc1/importscope0.txtar @@ -1,3 +1,21 @@ +-- main.mcl -- +import "second.mcl" + +include second.xclass +-- second.mcl -- +import "os" +import "fmt" + +class xclass { + #import "os" # this should not be required, top-level should be enough + + $aaa = if os.is_debian() { "bbb" } else { "ccc" } + + print "${aaa}" { + msg => "hello", + } +} +-- OUTPUT -- Edge: call:os.is_debian() -> if( call:os.is_debian() ) { str("bbb") } else { str("ccc") } # c Edge: if( call:os.is_debian() ) { str("bbb") } else { str("ccc") } -> var(aaa) # var:aaa Edge: str("bbb") -> if( call:os.is_debian() ) { str("bbb") } else { str("ccc") } # a diff --git a/lang/interpret_test/TestAstFunc1/importscope0/main.mcl b/lang/interpret_test/TestAstFunc1/importscope0/main.mcl deleted file mode 100644 index 3d43fe44..00000000 --- a/lang/interpret_test/TestAstFunc1/importscope0/main.mcl +++ /dev/null @@ -1,3 +0,0 @@ -import "second.mcl" - -include second.xclass diff --git a/lang/interpret_test/TestAstFunc1/importscope0/second.mcl b/lang/interpret_test/TestAstFunc1/importscope0/second.mcl deleted file mode 100644 index 1aa594f0..00000000 --- a/lang/interpret_test/TestAstFunc1/importscope0/second.mcl +++ /dev/null @@ -1,12 +0,0 @@ -import "os" -import "fmt" - -class xclass { - #import "os" # this should not be required, top-level should be enough - - $aaa = if os.is_debian() { "bbb" } else { "ccc" } - - print "${aaa}" { - msg => "hello", - } -} diff --git a/lang/interpret_test/TestAstFunc1/importscope1.graph b/lang/interpret_test/TestAstFunc1/importscope1.graph deleted file mode 100644 index d64103f1..00000000 --- a/lang/interpret_test/TestAstFunc1/importscope1.graph +++ /dev/null @@ -1 +0,0 @@ -# err: errSetScope: import scope `second.mcl` failed: local import of `second.mcl` failed: could not set scope from import: func `os.is_debian` does not exist in this scope diff --git a/lang/interpret_test/TestAstFunc1/importscope1.txtar b/lang/interpret_test/TestAstFunc1/importscope1.txtar new file mode 100644 index 00000000..99fbd285 --- /dev/null +++ b/lang/interpret_test/TestAstFunc1/importscope1.txtar @@ -0,0 +1,19 @@ +-- main.mcl -- +import "second.mcl" + +import "os" # this fixes it but the wrong way + +include second.xclass +-- second.mcl -- +import "fmt" + +class xclass { + # note that `os` is not imported here + $aaa = if os.is_debian() { "bbb" } else { "ccc" } + + print "${aaa}" { + msg => "hello", + } +} +-- OUTPUT -- +# err: errSetScope: import scope `second.mcl` failed: local import of `second.mcl` failed: could not set scope from import: func `os.is_debian` does not exist in this scope diff --git a/lang/interpret_test/TestAstFunc1/importscope1/main.mcl b/lang/interpret_test/TestAstFunc1/importscope1/main.mcl deleted file mode 100644 index 6623616f..00000000 --- a/lang/interpret_test/TestAstFunc1/importscope1/main.mcl +++ /dev/null @@ -1,5 +0,0 @@ -import "second.mcl" - -import "os" # this fixes it but the wrong way - -include second.xclass diff --git a/lang/interpret_test/TestAstFunc1/importscope1/second.mcl b/lang/interpret_test/TestAstFunc1/importscope1/second.mcl deleted file mode 100644 index 71373c5a..00000000 --- a/lang/interpret_test/TestAstFunc1/importscope1/second.mcl +++ /dev/null @@ -1,10 +0,0 @@ -import "fmt" - -class xclass { - # note that `os` is not imported here - $aaa = if os.is_debian() { "bbb" } else { "ccc" } - - print "${aaa}" { - msg => "hello", - } -} diff --git a/lang/interpret_test/TestAstFunc1/importscope0.graph b/lang/interpret_test/TestAstFunc1/importscope2.txtar similarity index 66% rename from lang/interpret_test/TestAstFunc1/importscope0.graph rename to lang/interpret_test/TestAstFunc1/importscope2.txtar index 4891fc78..9985611e 100644 --- a/lang/interpret_test/TestAstFunc1/importscope0.graph +++ b/lang/interpret_test/TestAstFunc1/importscope2.txtar @@ -1,3 +1,20 @@ +-- main.mcl -- +import "second.mcl" + +include second.xclass +-- second.mcl -- +import "fmt" + +class xclass { + import "os" # we can also use a scoped local import + + $aaa = if os.is_debian() { "bbb" } else { "ccc" } + + print "${aaa}" { + msg => "hello", + } +} +-- OUTPUT -- Edge: call:os.is_debian() -> if( call:os.is_debian() ) { str("bbb") } else { str("ccc") } # c Edge: if( call:os.is_debian() ) { str("bbb") } else { str("ccc") } -> var(aaa) # var:aaa Edge: str("bbb") -> if( call:os.is_debian() ) { str("bbb") } else { str("ccc") } # a diff --git a/lang/interpret_test/TestAstFunc1/importscope2/main.mcl b/lang/interpret_test/TestAstFunc1/importscope2/main.mcl deleted file mode 100644 index 3d43fe44..00000000 --- a/lang/interpret_test/TestAstFunc1/importscope2/main.mcl +++ /dev/null @@ -1,3 +0,0 @@ -import "second.mcl" - -include second.xclass diff --git a/lang/interpret_test/TestAstFunc1/importscope2/second.mcl b/lang/interpret_test/TestAstFunc1/importscope2/second.mcl deleted file mode 100644 index a64a1cf4..00000000 --- a/lang/interpret_test/TestAstFunc1/importscope2/second.mcl +++ /dev/null @@ -1,11 +0,0 @@ -import "fmt" - -class xclass { - import "os" # we can also use a scoped local import - - $aaa = if os.is_debian() { "bbb" } else { "ccc" } - - print "${aaa}" { - msg => "hello", - } -} diff --git a/lang/interpret_test/TestAstFunc1/lambda-chained.graph b/lang/interpret_test/TestAstFunc1/lambda-chained.txtar similarity index 91% rename from lang/interpret_test/TestAstFunc1/lambda-chained.graph rename to lang/interpret_test/TestAstFunc1/lambda-chained.txtar index 4b0bbd91..df91e05d 100644 --- a/lang/interpret_test/TestAstFunc1/lambda-chained.graph +++ b/lang/interpret_test/TestAstFunc1/lambda-chained.txtar @@ -1,3 +1,17 @@ +-- main.mcl -- +$prefix = "hello" + +# this should be a function as a value, iow a lambda +$prefixer = func($x) { + $prefix + ":" + $x # i'd only ever expect one ":" in the graph +} + +$out1 = $prefixer("world") +$out2 = $prefixer($out1) + +test $out1 {} +test $out2 {} +-- OUTPUT -- Edge: call:_operator(str("+"), call:_operator(str("+"), var(prefix), str(":")), var(x)) -> func(x) { call:_operator(str("+"), call:_operator(str("+"), var(prefix), str(":")), var(x)) } # body Edge: call:_operator(str("+"), call:_operator(str("+"), var(prefix), str(":")), var(x)) -> func(x) { call:_operator(str("+"), call:_operator(str("+"), var(prefix), str(":")), var(x)) } # body Edge: call:_operator(str("+"), var(prefix), str(":")) -> call:_operator(str("+"), call:_operator(str("+"), var(prefix), str(":")), var(x)) # a diff --git a/lang/interpret_test/TestAstFunc1/lambda-chained/main.mcl b/lang/interpret_test/TestAstFunc1/lambda-chained/main.mcl deleted file mode 100644 index e0e4cce6..00000000 --- a/lang/interpret_test/TestAstFunc1/lambda-chained/main.mcl +++ /dev/null @@ -1,12 +0,0 @@ -$prefix = "hello" - -# this should be a function as a value, iow a lambda -$prefixer = func($x) { - $prefix + ":" + $x # i'd only ever expect one ":" in the graph -} - -$out1 = $prefixer("world") -$out2 = $prefixer($out1) - -test $out1 {} -test $out2 {} diff --git a/lang/interpret_test/TestAstFunc1/recursive_module1.graph b/lang/interpret_test/TestAstFunc1/module_search1.txtar similarity index 67% rename from lang/interpret_test/TestAstFunc1/recursive_module1.graph rename to lang/interpret_test/TestAstFunc1/module_search1.txtar index a7f0eda5..8edd9b5a 100644 --- a/lang/interpret_test/TestAstFunc1/recursive_module1.graph +++ b/lang/interpret_test/TestAstFunc1/module_search1.txtar @@ -1,3 +1,67 @@ +-- metadata.yaml -- +main: "main/hello.mcl" # this is not the default, the default is "main.mcl" +files: "files/" # these are some extra files we can use (is the default) +path: "path/" # where to look for modules, defaults to using a global +-- main/h2g2.mcl -- +import "third.mcl" + +$answer = 42 + $third.three +-- main/hello.mcl -- +import "fmt" +import "h2g2.mcl" +import "mod1/" + +# imports as example1 +import "git://github.com/purpleidea/mgmt-example1/" +import "git://github.com/purpleidea/mgmt-example2/" + +$answer = $h2g2.answer + +test "hello" { + anotherstr => fmt.printf("the answer is: %d", $answer), +} +test "hello2" { + anotherstr => fmt.printf("i imported local: %s", $mod1.name), +} +test "hello3" { + anotherstr => fmt.printf("i imported remote: %s and %s", $example1.name, $example2.ex1), +} +-- main/third.mcl -- +$three = 3 +-- main/mod1/metadata.yaml -- +# empty metadata file (use defaults) +-- main/mod1/main.mcl -- +import "mod1/" # the nested version, not us + +$name = "this is module mod1 which contains: " + $mod1.name +-- main/mod1/mod1/metadata.yaml -- +# empty metadata file (use defaults) +-- main/mod1/mod1/main.mcl -- +$name = "this is the nested local module mod1" +-- path/github.com/purpleidea/mgmt-example1/metadata.yaml -- +main: "main.mcl" +files: "files/" # these are some extra files we can use (is the default) +-- path/github.com/purpleidea/mgmt-example1/main.mcl -- +# this is a pretty lame module! +import "mod1/" # yet another similarly named "mod1" import + +$name = "i am github.com/purpleidea/mgmt-example1/ and i contain: " + $mod1.name +-- path/github.com/purpleidea/mgmt-example1/mod1/metadata.yaml -- +# empty metadata file (use defaults) +-- path/github.com/purpleidea/mgmt-example1/mod1/main.mcl -- +$name = "this is the nested git module mod1" +-- path/github.com/purpleidea/mgmt-example2/metadata.yaml -- +main: "main.mcl" +files: "files/" # these are some extra files we can use (is the default) +path: "path/" # specify this, even though we already imported in parent +parentpathblock: false +-- path/github.com/purpleidea/mgmt-example2/main.mcl -- +# this is a pretty lame module! +import "git://github.com/purpleidea/mgmt-example1/" # import another module +$ex1 = $example1.name + +$name = "i am github.com/purpleidea/mgmt-example2/ and i contain: " + $ex1 +-- OUTPUT -- Edge: call:_operator(str("+"), int(42), var(third.three)) -> var(h2g2.answer) # var:h2g2.answer Edge: call:_operator(str("+"), str("i am github.com/purpleidea/mgmt-example1/ and i contain: "), var(mod1.name)) -> var(example1.name) # var:example1.name Edge: call:_operator(str("+"), str("i am github.com/purpleidea/mgmt-example1/ and i contain: "), var(mod1.name)) -> var(example1.name) # var:example1.name diff --git a/lang/interpret_test/TestAstFunc1/module_search1/main/h2g2.mcl b/lang/interpret_test/TestAstFunc1/module_search1/main/h2g2.mcl deleted file mode 100644 index 54871870..00000000 --- a/lang/interpret_test/TestAstFunc1/module_search1/main/h2g2.mcl +++ /dev/null @@ -1,3 +0,0 @@ -import "third.mcl" - -$answer = 42 + $third.three diff --git a/lang/interpret_test/TestAstFunc1/module_search1/main/hello.mcl b/lang/interpret_test/TestAstFunc1/module_search1/main/hello.mcl deleted file mode 100644 index 9948de6b..00000000 --- a/lang/interpret_test/TestAstFunc1/module_search1/main/hello.mcl +++ /dev/null @@ -1,19 +0,0 @@ -import "fmt" -import "h2g2.mcl" -import "mod1/" - -# imports as example1 -import "git://github.com/purpleidea/mgmt-example1/" -import "git://github.com/purpleidea/mgmt-example2/" - -$answer = $h2g2.answer - -test "hello" { - anotherstr => fmt.printf("the answer is: %d", $answer), -} -test "hello2" { - anotherstr => fmt.printf("i imported local: %s", $mod1.name), -} -test "hello3" { - anotherstr => fmt.printf("i imported remote: %s and %s", $example1.name, $example2.ex1), -} diff --git a/lang/interpret_test/TestAstFunc1/module_search1/main/mod1/main.mcl b/lang/interpret_test/TestAstFunc1/module_search1/main/mod1/main.mcl deleted file mode 100644 index edbf7cce..00000000 --- a/lang/interpret_test/TestAstFunc1/module_search1/main/mod1/main.mcl +++ /dev/null @@ -1,3 +0,0 @@ -import "mod1/" # the nested version, not us - -$name = "this is module mod1 which contains: " + $mod1.name diff --git a/lang/interpret_test/TestAstFunc1/module_search1/main/mod1/metadata.yaml b/lang/interpret_test/TestAstFunc1/module_search1/main/mod1/metadata.yaml deleted file mode 100644 index 3f1449fb..00000000 --- a/lang/interpret_test/TestAstFunc1/module_search1/main/mod1/metadata.yaml +++ /dev/null @@ -1 +0,0 @@ -# empty metadata file (use defaults) diff --git a/lang/interpret_test/TestAstFunc1/module_search1/main/mod1/mod1/main.mcl b/lang/interpret_test/TestAstFunc1/module_search1/main/mod1/mod1/main.mcl deleted file mode 100644 index 28c20712..00000000 --- a/lang/interpret_test/TestAstFunc1/module_search1/main/mod1/mod1/main.mcl +++ /dev/null @@ -1 +0,0 @@ -$name = "this is the nested local module mod1" diff --git a/lang/interpret_test/TestAstFunc1/module_search1/main/mod1/mod1/metadata.yaml b/lang/interpret_test/TestAstFunc1/module_search1/main/mod1/mod1/metadata.yaml deleted file mode 100644 index 3f1449fb..00000000 --- a/lang/interpret_test/TestAstFunc1/module_search1/main/mod1/mod1/metadata.yaml +++ /dev/null @@ -1 +0,0 @@ -# empty metadata file (use defaults) diff --git a/lang/interpret_test/TestAstFunc1/module_search1/main/third.mcl b/lang/interpret_test/TestAstFunc1/module_search1/main/third.mcl deleted file mode 100644 index 2a030aa1..00000000 --- a/lang/interpret_test/TestAstFunc1/module_search1/main/third.mcl +++ /dev/null @@ -1 +0,0 @@ -$three = 3 diff --git a/lang/interpret_test/TestAstFunc1/module_search1/metadata.yaml b/lang/interpret_test/TestAstFunc1/module_search1/metadata.yaml deleted file mode 100644 index ee4d4a34..00000000 --- a/lang/interpret_test/TestAstFunc1/module_search1/metadata.yaml +++ /dev/null @@ -1,3 +0,0 @@ -main: "main/hello.mcl" # this is not the default, the default is "main.mcl" -files: "files/" # these are some extra files we can use (is the default) -path: "path/" # where to look for modules, defaults to using a global diff --git a/lang/interpret_test/TestAstFunc1/module_search1/path/github.com/purpleidea/mgmt-example1/main.mcl b/lang/interpret_test/TestAstFunc1/module_search1/path/github.com/purpleidea/mgmt-example1/main.mcl deleted file mode 100644 index aaf20828..00000000 --- a/lang/interpret_test/TestAstFunc1/module_search1/path/github.com/purpleidea/mgmt-example1/main.mcl +++ /dev/null @@ -1,4 +0,0 @@ -# this is a pretty lame module! -import "mod1/" # yet another similarly named "mod1" import - -$name = "i am github.com/purpleidea/mgmt-example1/ and i contain: " + $mod1.name diff --git a/lang/interpret_test/TestAstFunc1/module_search1/path/github.com/purpleidea/mgmt-example1/metadata.yaml b/lang/interpret_test/TestAstFunc1/module_search1/path/github.com/purpleidea/mgmt-example1/metadata.yaml deleted file mode 100644 index 8415d27c..00000000 --- a/lang/interpret_test/TestAstFunc1/module_search1/path/github.com/purpleidea/mgmt-example1/metadata.yaml +++ /dev/null @@ -1,2 +0,0 @@ -main: "main.mcl" -files: "files/" # these are some extra files we can use (is the default) diff --git a/lang/interpret_test/TestAstFunc1/module_search1/path/github.com/purpleidea/mgmt-example1/mod1/main.mcl b/lang/interpret_test/TestAstFunc1/module_search1/path/github.com/purpleidea/mgmt-example1/mod1/main.mcl deleted file mode 100644 index 708a2f34..00000000 --- a/lang/interpret_test/TestAstFunc1/module_search1/path/github.com/purpleidea/mgmt-example1/mod1/main.mcl +++ /dev/null @@ -1 +0,0 @@ -$name = "this is the nested git module mod1" diff --git a/lang/interpret_test/TestAstFunc1/module_search1/path/github.com/purpleidea/mgmt-example1/mod1/metadata.yaml b/lang/interpret_test/TestAstFunc1/module_search1/path/github.com/purpleidea/mgmt-example1/mod1/metadata.yaml deleted file mode 100644 index 3f1449fb..00000000 --- a/lang/interpret_test/TestAstFunc1/module_search1/path/github.com/purpleidea/mgmt-example1/mod1/metadata.yaml +++ /dev/null @@ -1 +0,0 @@ -# empty metadata file (use defaults) diff --git a/lang/interpret_test/TestAstFunc1/module_search1/path/github.com/purpleidea/mgmt-example2/main.mcl b/lang/interpret_test/TestAstFunc1/module_search1/path/github.com/purpleidea/mgmt-example2/main.mcl deleted file mode 100644 index 5bd9c7db..00000000 --- a/lang/interpret_test/TestAstFunc1/module_search1/path/github.com/purpleidea/mgmt-example2/main.mcl +++ /dev/null @@ -1,5 +0,0 @@ -# this is a pretty lame module! -import "git://github.com/purpleidea/mgmt-example1/" # import another module -$ex1 = $example1.name - -$name = "i am github.com/purpleidea/mgmt-example2/ and i contain: " + $ex1 diff --git a/lang/interpret_test/TestAstFunc1/module_search1/path/github.com/purpleidea/mgmt-example2/metadata.yaml b/lang/interpret_test/TestAstFunc1/module_search1/path/github.com/purpleidea/mgmt-example2/metadata.yaml deleted file mode 100644 index 0e995ba8..00000000 --- a/lang/interpret_test/TestAstFunc1/module_search1/path/github.com/purpleidea/mgmt-example2/metadata.yaml +++ /dev/null @@ -1,4 +0,0 @@ -main: "main.mcl" -files: "files/" # these are some extra files we can use (is the default) -path: "path/" # specify this, even though we already imported in parent -parentpathblock: false diff --git a/lang/interpret_test/TestAstFunc1/polydoubleinclude.graph b/lang/interpret_test/TestAstFunc1/polydoubleinclude.txtar similarity index 82% rename from lang/interpret_test/TestAstFunc1/polydoubleinclude.graph rename to lang/interpret_test/TestAstFunc1/polydoubleinclude.txtar index 4c5f369a..364141b6 100644 --- a/lang/interpret_test/TestAstFunc1/polydoubleinclude.graph +++ b/lang/interpret_test/TestAstFunc1/polydoubleinclude.txtar @@ -1,3 +1,15 @@ +-- main.mcl -- +import "fmt" + +# note that the class can have two separate types for $b +include c1("t1", "hello") # len is 5 +include c1("t2", [13, 42, 0, -37,]) # len is 4 +class c1($a, $b) { + test $a { + anotherstr => fmt.printf("len is: %d", len($b)), + } +} +-- OUTPUT -- Edge: call:len(var(b)) -> call:fmt.printf(str("len is: %d"), call:len(var(b))) # a Edge: call:len(var(b)) -> call:fmt.printf(str("len is: %d"), call:len(var(b))) # a Edge: int(-37) -> list(int(13), int(42), int(0), int(-37)) # 3 diff --git a/lang/interpret_test/TestAstFunc1/polydoubleinclude/main.mcl b/lang/interpret_test/TestAstFunc1/polydoubleinclude/main.mcl deleted file mode 100644 index c314e262..00000000 --- a/lang/interpret_test/TestAstFunc1/polydoubleinclude/main.mcl +++ /dev/null @@ -1,10 +0,0 @@ -import "fmt" - -# note that the class can have two separate types for $b -include c1("t1", "hello") # len is 5 -include c1("t2", [13, 42, 0, -37,]) # len is 4 -class c1($a, $b) { - test $a { - anotherstr => fmt.printf("len is: %d", len($b)), - } -} diff --git a/lang/interpret_test/TestAstFunc1/polydoubleincludewithtype.graph b/lang/interpret_test/TestAstFunc1/polydoubleincludewithtype.graph deleted file mode 100644 index 34a6fd18..00000000 --- a/lang/interpret_test/TestAstFunc1/polydoubleincludewithtype.graph +++ /dev/null @@ -1 +0,0 @@ -# err: errUnify: can't unify, invariant illogicality with equals: base kind does not match (Str != List) diff --git a/lang/interpret_test/TestAstFunc1/polydoubleincludewithtype/main.mcl b/lang/interpret_test/TestAstFunc1/polydoubleincludewithtype.txtar similarity index 71% rename from lang/interpret_test/TestAstFunc1/polydoubleincludewithtype/main.mcl rename to lang/interpret_test/TestAstFunc1/polydoubleincludewithtype.txtar index dbc67bf6..3b902b44 100644 --- a/lang/interpret_test/TestAstFunc1/polydoubleincludewithtype/main.mcl +++ b/lang/interpret_test/TestAstFunc1/polydoubleincludewithtype.txtar @@ -1,3 +1,4 @@ +-- main.mcl -- import "fmt" # note that the class can have two separate types for $b @@ -10,3 +11,5 @@ class c1($a, $b []str) { anotherstr => fmt.printf("len is: %d", len($b)), } } +-- OUTPUT -- +# err: errUnify: can't unify, invariant illogicality with equals: base kind does not match (Str != List) diff --git a/lang/interpret_test/TestAstFunc1/recursive_class1.graph b/lang/interpret_test/TestAstFunc1/recursive_class1.graph deleted file mode 100644 index 879ea314..00000000 --- a/lang/interpret_test/TestAstFunc1/recursive_class1.graph +++ /dev/null @@ -1 +0,0 @@ -# err: errSetScope: recursive reference while setting scope: not a dag diff --git a/lang/interpret_test/TestAstFunc1/recursive_class1/main.mcl b/lang/interpret_test/TestAstFunc1/recursive_class1.txtar similarity index 70% rename from lang/interpret_test/TestAstFunc1/recursive_class1/main.mcl rename to lang/interpret_test/TestAstFunc1/recursive_class1.txtar index b3cff2c6..3196b120 100644 --- a/lang/interpret_test/TestAstFunc1/recursive_class1/main.mcl +++ b/lang/interpret_test/TestAstFunc1/recursive_class1.txtar @@ -1,3 +1,4 @@ +-- main.mcl -- import "fmt" $max = 3 include c1(0) # start at zero @@ -10,3 +11,5 @@ class c1($count) { include c1($count + 1) # recursion not supported atm } } +-- OUTPUT -- +# err: errSetScope: recursive reference while setting scope: not a dag diff --git a/lang/interpret_test/TestAstFunc1/recursive_class2.graph b/lang/interpret_test/TestAstFunc1/recursive_class2.graph deleted file mode 100644 index 879ea314..00000000 --- a/lang/interpret_test/TestAstFunc1/recursive_class2.graph +++ /dev/null @@ -1 +0,0 @@ -# err: errSetScope: recursive reference while setting scope: not a dag diff --git a/lang/interpret_test/TestAstFunc1/recursive_class2/main.mcl b/lang/interpret_test/TestAstFunc1/recursive_class2.txtar similarity index 86% rename from lang/interpret_test/TestAstFunc1/recursive_class2/main.mcl rename to lang/interpret_test/TestAstFunc1/recursive_class2.txtar index fc652155..ac7e97cb 100644 --- a/lang/interpret_test/TestAstFunc1/recursive_class2/main.mcl +++ b/lang/interpret_test/TestAstFunc1/recursive_class2.txtar @@ -1,3 +1,4 @@ +-- main.mcl -- # this currently fails with: "class `c1` does not exist in this scope" # instead of: "recursive class `c1` found" or "recursive class `c2` found" # ideally, we'd consider allowing finite (static) recursion such as this... @@ -22,3 +23,5 @@ class c2($count) { include c1($count + 1) # recursion not supported atm } } +-- OUTPUT -- +# err: errSetScope: recursive reference while setting scope: not a dag diff --git a/lang/interpret_test/TestAstFunc1/module_search1.graph b/lang/interpret_test/TestAstFunc1/recursive_module1.txtar similarity index 68% rename from lang/interpret_test/TestAstFunc1/module_search1.graph rename to lang/interpret_test/TestAstFunc1/recursive_module1.txtar index a7f0eda5..4f67f9d9 100644 --- a/lang/interpret_test/TestAstFunc1/module_search1.graph +++ b/lang/interpret_test/TestAstFunc1/recursive_module1.txtar @@ -1,3 +1,65 @@ +-- metadata.yaml -- +main: "main/hello.mcl" # this is not the default, the default is "main.mcl" +files: "files/" # these are some extra files we can use (is the default) +path: "path/" # where to look for modules, defaults to using a global +-- main/h2g2.mcl -- +import "third.mcl" + +$answer = 42 + $third.three +-- main/hello.mcl -- +import "fmt" +import "h2g2.mcl" +import "mod1/" + +# imports as example1 +import "git://github.com/purpleidea/mgmt-example1/" +import "git://github.com/purpleidea/mgmt-example2/" + +$answer = $h2g2.answer + +test "hello" { + anotherstr => fmt.printf("the answer is: %d", $answer), +} +test "hello2" { + anotherstr => fmt.printf("i imported local: %s", $mod1.name), +} +test "hello3" { + anotherstr => fmt.printf("i imported remote: %s and %s", $example1.name, $example2.ex1), +} +-- main/third.mcl -- +$three = 3 +-- main/mod1/metadata.yaml -- +# empty metadata file (use defaults) +-- main/mod1/main.mcl -- +import "mod1/" # the nested version, not us + +$name = "this is module mod1 which contains: " + $mod1.name +-- main/mod1/mod1/metadata.yaml -- +# empty metadata file (use defaults) +-- main/mod1/mod1/main.mcl -- +$name = "this is the nested local module mod1" +-- path/github.com/purpleidea/mgmt-example1/metadata.yaml -- +main: "main.mcl" +files: "files/" # these are some extra files we can use (is the default) +-- path/github.com/purpleidea/mgmt-example1/main.mcl -- +# this is a pretty lame module! +import "mod1/" # yet another similarly named "mod1" import + +$name = "i am github.com/purpleidea/mgmt-example1/ and i contain: " + $mod1.name +-- path/github.com/purpleidea/mgmt-example1/mod1/metadata.yaml -- +# empty metadata file (use defaults) +-- path/github.com/purpleidea/mgmt-example1/mod1/main.mcl -- +$name = "this is the nested git module mod1" +-- path/github.com/purpleidea/mgmt-example2/metadata.yaml -- +main: "main.mcl" +files: "files/" # these are some extra files we can use (is the default) +-- path/github.com/purpleidea/mgmt-example2/main.mcl -- +# this is a pretty lame module! +import "git://github.com/purpleidea/mgmt-example1/" # import another module +$ex1 = $example1.name + +$name = "i am github.com/purpleidea/mgmt-example2/ and i contain: " + $ex1 +-- OUTPUT -- Edge: call:_operator(str("+"), int(42), var(third.three)) -> var(h2g2.answer) # var:h2g2.answer Edge: call:_operator(str("+"), str("i am github.com/purpleidea/mgmt-example1/ and i contain: "), var(mod1.name)) -> var(example1.name) # var:example1.name Edge: call:_operator(str("+"), str("i am github.com/purpleidea/mgmt-example1/ and i contain: "), var(mod1.name)) -> var(example1.name) # var:example1.name diff --git a/lang/interpret_test/TestAstFunc1/recursive_module1/main/h2g2.mcl b/lang/interpret_test/TestAstFunc1/recursive_module1/main/h2g2.mcl deleted file mode 100644 index 54871870..00000000 --- a/lang/interpret_test/TestAstFunc1/recursive_module1/main/h2g2.mcl +++ /dev/null @@ -1,3 +0,0 @@ -import "third.mcl" - -$answer = 42 + $third.three diff --git a/lang/interpret_test/TestAstFunc1/recursive_module1/main/hello.mcl b/lang/interpret_test/TestAstFunc1/recursive_module1/main/hello.mcl deleted file mode 100644 index 9948de6b..00000000 --- a/lang/interpret_test/TestAstFunc1/recursive_module1/main/hello.mcl +++ /dev/null @@ -1,19 +0,0 @@ -import "fmt" -import "h2g2.mcl" -import "mod1/" - -# imports as example1 -import "git://github.com/purpleidea/mgmt-example1/" -import "git://github.com/purpleidea/mgmt-example2/" - -$answer = $h2g2.answer - -test "hello" { - anotherstr => fmt.printf("the answer is: %d", $answer), -} -test "hello2" { - anotherstr => fmt.printf("i imported local: %s", $mod1.name), -} -test "hello3" { - anotherstr => fmt.printf("i imported remote: %s and %s", $example1.name, $example2.ex1), -} diff --git a/lang/interpret_test/TestAstFunc1/recursive_module1/main/mod1/main.mcl b/lang/interpret_test/TestAstFunc1/recursive_module1/main/mod1/main.mcl deleted file mode 100644 index edbf7cce..00000000 --- a/lang/interpret_test/TestAstFunc1/recursive_module1/main/mod1/main.mcl +++ /dev/null @@ -1,3 +0,0 @@ -import "mod1/" # the nested version, not us - -$name = "this is module mod1 which contains: " + $mod1.name diff --git a/lang/interpret_test/TestAstFunc1/recursive_module1/main/mod1/metadata.yaml b/lang/interpret_test/TestAstFunc1/recursive_module1/main/mod1/metadata.yaml deleted file mode 100644 index 3f1449fb..00000000 --- a/lang/interpret_test/TestAstFunc1/recursive_module1/main/mod1/metadata.yaml +++ /dev/null @@ -1 +0,0 @@ -# empty metadata file (use defaults) diff --git a/lang/interpret_test/TestAstFunc1/recursive_module1/main/mod1/mod1/main.mcl b/lang/interpret_test/TestAstFunc1/recursive_module1/main/mod1/mod1/main.mcl deleted file mode 100644 index 28c20712..00000000 --- a/lang/interpret_test/TestAstFunc1/recursive_module1/main/mod1/mod1/main.mcl +++ /dev/null @@ -1 +0,0 @@ -$name = "this is the nested local module mod1" diff --git a/lang/interpret_test/TestAstFunc1/recursive_module1/main/mod1/mod1/metadata.yaml b/lang/interpret_test/TestAstFunc1/recursive_module1/main/mod1/mod1/metadata.yaml deleted file mode 100644 index 3f1449fb..00000000 --- a/lang/interpret_test/TestAstFunc1/recursive_module1/main/mod1/mod1/metadata.yaml +++ /dev/null @@ -1 +0,0 @@ -# empty metadata file (use defaults) diff --git a/lang/interpret_test/TestAstFunc1/recursive_module1/main/third.mcl b/lang/interpret_test/TestAstFunc1/recursive_module1/main/third.mcl deleted file mode 100644 index 2a030aa1..00000000 --- a/lang/interpret_test/TestAstFunc1/recursive_module1/main/third.mcl +++ /dev/null @@ -1 +0,0 @@ -$three = 3 diff --git a/lang/interpret_test/TestAstFunc1/recursive_module1/metadata.yaml b/lang/interpret_test/TestAstFunc1/recursive_module1/metadata.yaml deleted file mode 100644 index ee4d4a34..00000000 --- a/lang/interpret_test/TestAstFunc1/recursive_module1/metadata.yaml +++ /dev/null @@ -1,3 +0,0 @@ -main: "main/hello.mcl" # this is not the default, the default is "main.mcl" -files: "files/" # these are some extra files we can use (is the default) -path: "path/" # where to look for modules, defaults to using a global diff --git a/lang/interpret_test/TestAstFunc1/recursive_module1/path/github.com/purpleidea/mgmt-example1/main.mcl b/lang/interpret_test/TestAstFunc1/recursive_module1/path/github.com/purpleidea/mgmt-example1/main.mcl deleted file mode 100644 index aaf20828..00000000 --- a/lang/interpret_test/TestAstFunc1/recursive_module1/path/github.com/purpleidea/mgmt-example1/main.mcl +++ /dev/null @@ -1,4 +0,0 @@ -# this is a pretty lame module! -import "mod1/" # yet another similarly named "mod1" import - -$name = "i am github.com/purpleidea/mgmt-example1/ and i contain: " + $mod1.name diff --git a/lang/interpret_test/TestAstFunc1/recursive_module1/path/github.com/purpleidea/mgmt-example1/metadata.yaml b/lang/interpret_test/TestAstFunc1/recursive_module1/path/github.com/purpleidea/mgmt-example1/metadata.yaml deleted file mode 100644 index 8415d27c..00000000 --- a/lang/interpret_test/TestAstFunc1/recursive_module1/path/github.com/purpleidea/mgmt-example1/metadata.yaml +++ /dev/null @@ -1,2 +0,0 @@ -main: "main.mcl" -files: "files/" # these are some extra files we can use (is the default) diff --git a/lang/interpret_test/TestAstFunc1/recursive_module1/path/github.com/purpleidea/mgmt-example1/mod1/main.mcl b/lang/interpret_test/TestAstFunc1/recursive_module1/path/github.com/purpleidea/mgmt-example1/mod1/main.mcl deleted file mode 100644 index 708a2f34..00000000 --- a/lang/interpret_test/TestAstFunc1/recursive_module1/path/github.com/purpleidea/mgmt-example1/mod1/main.mcl +++ /dev/null @@ -1 +0,0 @@ -$name = "this is the nested git module mod1" diff --git a/lang/interpret_test/TestAstFunc1/recursive_module1/path/github.com/purpleidea/mgmt-example1/mod1/metadata.yaml b/lang/interpret_test/TestAstFunc1/recursive_module1/path/github.com/purpleidea/mgmt-example1/mod1/metadata.yaml deleted file mode 100644 index 3f1449fb..00000000 --- a/lang/interpret_test/TestAstFunc1/recursive_module1/path/github.com/purpleidea/mgmt-example1/mod1/metadata.yaml +++ /dev/null @@ -1 +0,0 @@ -# empty metadata file (use defaults) diff --git a/lang/interpret_test/TestAstFunc1/recursive_module1/path/github.com/purpleidea/mgmt-example2/main.mcl b/lang/interpret_test/TestAstFunc1/recursive_module1/path/github.com/purpleidea/mgmt-example2/main.mcl deleted file mode 100644 index 5bd9c7db..00000000 --- a/lang/interpret_test/TestAstFunc1/recursive_module1/path/github.com/purpleidea/mgmt-example2/main.mcl +++ /dev/null @@ -1,5 +0,0 @@ -# this is a pretty lame module! -import "git://github.com/purpleidea/mgmt-example1/" # import another module -$ex1 = $example1.name - -$name = "i am github.com/purpleidea/mgmt-example2/ and i contain: " + $ex1 diff --git a/lang/interpret_test/TestAstFunc1/recursive_module1/path/github.com/purpleidea/mgmt-example2/metadata.yaml b/lang/interpret_test/TestAstFunc1/recursive_module1/path/github.com/purpleidea/mgmt-example2/metadata.yaml deleted file mode 100644 index 8415d27c..00000000 --- a/lang/interpret_test/TestAstFunc1/recursive_module1/path/github.com/purpleidea/mgmt-example2/metadata.yaml +++ /dev/null @@ -1,2 +0,0 @@ -main: "main.mcl" -files: "files/" # these are some extra files we can use (is the default) diff --git a/lang/interpret_test/TestAstFunc1/resdupefields0.graph b/lang/interpret_test/TestAstFunc1/resdupefields0.graph deleted file mode 100644 index c2721d85..00000000 --- a/lang/interpret_test/TestAstFunc1/resdupefields0.graph +++ /dev/null @@ -1 +0,0 @@ -# err: errGraph: resource has duplicate meta entry of: noop diff --git a/lang/interpret_test/TestAstFunc1/resdupefields0/main.mcl b/lang/interpret_test/TestAstFunc1/resdupefields0.txtar similarity index 81% rename from lang/interpret_test/TestAstFunc1/resdupefields0/main.mcl rename to lang/interpret_test/TestAstFunc1/resdupefields0.txtar index 552c77b0..14388ddb 100644 --- a/lang/interpret_test/TestAstFunc1/resdupefields0/main.mcl +++ b/lang/interpret_test/TestAstFunc1/resdupefields0.txtar @@ -1,3 +1,4 @@ +-- main.mcl -- test "test" { anotherstr => "test", @@ -20,3 +21,5 @@ test "test" { #Meta:autoedge => true, #Meta:autogroup => false, } +-- OUTPUT -- +# err: errGraph: resource has duplicate meta entry of: noop diff --git a/lang/interpret_test/TestAstFunc1/resdupefields1.graph b/lang/interpret_test/TestAstFunc1/resdupefields1.graph deleted file mode 100644 index 3f2b7980..00000000 --- a/lang/interpret_test/TestAstFunc1/resdupefields1.graph +++ /dev/null @@ -1 +0,0 @@ -# err: errInit: resource has duplicate field of: anotherstr diff --git a/lang/interpret_test/TestAstFunc1/resdupefields1/main.mcl b/lang/interpret_test/TestAstFunc1/resdupefields1.txtar similarity index 53% rename from lang/interpret_test/TestAstFunc1/resdupefields1/main.mcl rename to lang/interpret_test/TestAstFunc1/resdupefields1.txtar index 2897afa4..5b579d40 100644 --- a/lang/interpret_test/TestAstFunc1/resdupefields1/main.mcl +++ b/lang/interpret_test/TestAstFunc1/resdupefields1.txtar @@ -1,4 +1,7 @@ +-- main.mcl -- test "test" { anotherstr => "hello", anotherstr => "hello", # values aren't checked in dupe checks } +-- OUTPUT -- +# err: errInit: resource has duplicate field of: anotherstr diff --git a/lang/interpret_test/TestAstFunc1/resdupefields2.graph b/lang/interpret_test/TestAstFunc1/resdupefields2.graph deleted file mode 100644 index 3f2b7980..00000000 --- a/lang/interpret_test/TestAstFunc1/resdupefields2.graph +++ /dev/null @@ -1 +0,0 @@ -# err: errInit: resource has duplicate field of: anotherstr diff --git a/lang/interpret_test/TestAstFunc1/resdupefields2/main.mcl b/lang/interpret_test/TestAstFunc1/resdupefields2.txtar similarity index 55% rename from lang/interpret_test/TestAstFunc1/resdupefields2/main.mcl rename to lang/interpret_test/TestAstFunc1/resdupefields2.txtar index 7bbd3f4b..920cfa18 100644 --- a/lang/interpret_test/TestAstFunc1/resdupefields2/main.mcl +++ b/lang/interpret_test/TestAstFunc1/resdupefields2.txtar @@ -1,4 +1,7 @@ +-- main.mcl -- test "test" { anotherstr => "hello", anotherstr => "hello world", # values aren't checked in dupe checks } +-- OUTPUT -- +# err: errInit: resource has duplicate field of: anotherstr diff --git a/lang/interpret_test/TestAstFunc1/resdupefields3.graph b/lang/interpret_test/TestAstFunc1/resdupefields3.graph deleted file mode 100644 index 4f0478cc..00000000 --- a/lang/interpret_test/TestAstFunc1/resdupefields3.graph +++ /dev/null @@ -1 +0,0 @@ -# err: errInit: resource has duplicate meta entry of: noop diff --git a/lang/interpret_test/TestAstFunc1/resdupefields3.txtar b/lang/interpret_test/TestAstFunc1/resdupefields3.txtar new file mode 100644 index 00000000..6c71aa6e --- /dev/null +++ b/lang/interpret_test/TestAstFunc1/resdupefields3.txtar @@ -0,0 +1,8 @@ +-- main.mcl -- +test "test" { + anotherstr => "test", + Meta:noop => false, + Meta:noop => false, +} +-- OUTPUT -- +# err: errInit: resource has duplicate meta entry of: noop diff --git a/lang/interpret_test/TestAstFunc1/resdupefields3/main.mcl b/lang/interpret_test/TestAstFunc1/resdupefields3/main.mcl deleted file mode 100644 index 968f9da4..00000000 --- a/lang/interpret_test/TestAstFunc1/resdupefields3/main.mcl +++ /dev/null @@ -1,5 +0,0 @@ -test "test" { - anotherstr => "test", - Meta:noop => false, - Meta:noop => false, -} diff --git a/lang/interpret_test/TestAstFunc1/resdupefields4.graph b/lang/interpret_test/TestAstFunc1/resdupefields4.graph deleted file mode 100644 index 4f0478cc..00000000 --- a/lang/interpret_test/TestAstFunc1/resdupefields4.graph +++ /dev/null @@ -1 +0,0 @@ -# err: errInit: resource has duplicate meta entry of: noop diff --git a/lang/interpret_test/TestAstFunc1/resdupefields4.txtar b/lang/interpret_test/TestAstFunc1/resdupefields4.txtar new file mode 100644 index 00000000..9cb9ce4b --- /dev/null +++ b/lang/interpret_test/TestAstFunc1/resdupefields4.txtar @@ -0,0 +1,8 @@ +-- main.mcl -- +test "test" { + anotherstr => "test", + Meta:noop => false, + Meta:noop => true, +} +-- OUTPUT -- +# err: errInit: resource has duplicate meta entry of: noop diff --git a/lang/interpret_test/TestAstFunc1/resdupefields4/main.mcl b/lang/interpret_test/TestAstFunc1/resdupefields4/main.mcl deleted file mode 100644 index 24035500..00000000 --- a/lang/interpret_test/TestAstFunc1/resdupefields4/main.mcl +++ /dev/null @@ -1,5 +0,0 @@ -test "test" { - anotherstr => "test", - Meta:noop => false, - Meta:noop => true, -} diff --git a/lang/interpret_test/TestAstFunc1/resdupefields5.graph b/lang/interpret_test/TestAstFunc1/resdupefields5.graph deleted file mode 100644 index e69de29b..00000000 diff --git a/lang/interpret_test/TestAstFunc1/resdupefields5/main.mcl b/lang/interpret_test/TestAstFunc1/resdupefields5.txtar similarity index 93% rename from lang/interpret_test/TestAstFunc1/resdupefields5/main.mcl rename to lang/interpret_test/TestAstFunc1/resdupefields5.txtar index 371a9a72..16d65106 100644 --- a/lang/interpret_test/TestAstFunc1/resdupefields5/main.mcl +++ b/lang/interpret_test/TestAstFunc1/resdupefields5.txtar @@ -1,3 +1,4 @@ +-- main.mcl -- # XXX: should error at graph unification, but we have a type unification bug #test "test" { # anotherstr => "test", @@ -20,3 +21,4 @@ # noop => false, # }, #} +-- OUTPUT -- diff --git a/lang/interpret_test/TestAstFunc1/resdupefields6.graph b/lang/interpret_test/TestAstFunc1/resdupefields6.graph deleted file mode 100644 index e69de29b..00000000 diff --git a/lang/interpret_test/TestAstFunc1/resdupefields6/main.mcl b/lang/interpret_test/TestAstFunc1/resdupefields6.txtar similarity index 93% rename from lang/interpret_test/TestAstFunc1/resdupefields6/main.mcl rename to lang/interpret_test/TestAstFunc1/resdupefields6.txtar index 42121f17..7a8a3b5f 100644 --- a/lang/interpret_test/TestAstFunc1/resdupefields6/main.mcl +++ b/lang/interpret_test/TestAstFunc1/resdupefields6.txtar @@ -1,3 +1,4 @@ +-- main.mcl -- # XXX: should work, but we have a type unification bug #test "test" { # anotherstr => "test", @@ -19,3 +20,4 @@ # Meta:noop => true, # Meta:autoedge => true, #} +-- OUTPUT -- diff --git a/lang/interpret_test/TestAstFunc1/returned-func.graph b/lang/interpret_test/TestAstFunc1/returned-func.txtar similarity index 71% rename from lang/interpret_test/TestAstFunc1/returned-func.graph rename to lang/interpret_test/TestAstFunc1/returned-func.txtar index 48d9983e..305c45dc 100644 --- a/lang/interpret_test/TestAstFunc1/returned-func.graph +++ b/lang/interpret_test/TestAstFunc1/returned-func.txtar @@ -1,3 +1,16 @@ +-- main.mcl -- +# simple function definition containing function to be returned +func funcgen() { + func() { + "hello" + } +} + +$fn = funcgen() +$out = $fn() + +test $out {} +-- OUTPUT -- Edge: call:fn() -> var(out) # var:out Edge: call:funcgen() -> call:fn() # call:fn Edge: func() { func() { str("hello") } } -> call:funcgen() # call:funcgen diff --git a/lang/interpret_test/TestAstFunc1/returned-func/main.mcl b/lang/interpret_test/TestAstFunc1/returned-func/main.mcl deleted file mode 100644 index 19e13a93..00000000 --- a/lang/interpret_test/TestAstFunc1/returned-func/main.mcl +++ /dev/null @@ -1,11 +0,0 @@ -# simple function definition containing function to be returned -func funcgen() { - func() { - "hello" - } -} - -$fn = funcgen() -$out = $fn() - -test $out {} diff --git a/lang/interpret_test/TestAstFunc1/returned-lambda.graph b/lang/interpret_test/TestAstFunc1/returned-lambda.txtar similarity index 78% rename from lang/interpret_test/TestAstFunc1/returned-lambda.graph rename to lang/interpret_test/TestAstFunc1/returned-lambda.txtar index 48d9983e..a5654107 100644 --- a/lang/interpret_test/TestAstFunc1/returned-lambda.graph +++ b/lang/interpret_test/TestAstFunc1/returned-lambda.txtar @@ -1,3 +1,15 @@ +-- main.mcl -- +$funcgen = func() { + func() { + "hello" + } +} + +$fn = $funcgen() +$out = $fn() + +test $out {} +-- OUTPUT -- Edge: call:fn() -> var(out) # var:out Edge: call:funcgen() -> call:fn() # call:fn Edge: func() { func() { str("hello") } } -> call:funcgen() # call:funcgen diff --git a/lang/interpret_test/TestAstFunc1/returned-lambda/main.mcl b/lang/interpret_test/TestAstFunc1/returned-lambda/main.mcl deleted file mode 100644 index cdcf24b2..00000000 --- a/lang/interpret_test/TestAstFunc1/returned-lambda/main.mcl +++ /dev/null @@ -1,10 +0,0 @@ -$funcgen = func() { - func() { - "hello" - } -} - -$fn = $funcgen() -$out = $fn() - -test $out {} diff --git a/lang/interpret_test/TestAstFunc1/shadowing1.graph b/lang/interpret_test/TestAstFunc1/shadowing1.graph deleted file mode 100644 index a609c044..00000000 --- a/lang/interpret_test/TestAstFunc1/shadowing1.graph +++ /dev/null @@ -1,4 +0,0 @@ -Edge: str("hello") -> var(x) # var:x -Vertex: bool(true) -Vertex: str("hello") -Vertex: var(x) diff --git a/lang/interpret_test/TestAstFunc1/shadowing1.txtar b/lang/interpret_test/TestAstFunc1/shadowing1.txtar new file mode 100644 index 00000000..7ee95026 --- /dev/null +++ b/lang/interpret_test/TestAstFunc1/shadowing1.txtar @@ -0,0 +1,12 @@ +-- main.mcl -- +# this should be okay, because var is shadowed +$x = "hello" +if true { + $x = "world" # shadowed +} +test $x {} +-- OUTPUT -- +Edge: str("hello") -> var(x) # var:x +Vertex: bool(true) +Vertex: str("hello") +Vertex: var(x) diff --git a/lang/interpret_test/TestAstFunc1/shadowing1/main.mcl b/lang/interpret_test/TestAstFunc1/shadowing1/main.mcl deleted file mode 100644 index fee1876c..00000000 --- a/lang/interpret_test/TestAstFunc1/shadowing1/main.mcl +++ /dev/null @@ -1,6 +0,0 @@ -# this should be okay, because var is shadowed -$x = "hello" -if true { - $x = "world" # shadowed -} -test $x {} diff --git a/lang/interpret_test/TestAstFunc1/shadowing2.graph b/lang/interpret_test/TestAstFunc1/shadowing2.graph deleted file mode 100644 index a0bea21f..00000000 --- a/lang/interpret_test/TestAstFunc1/shadowing2.graph +++ /dev/null @@ -1,4 +0,0 @@ -Edge: str("world") -> var(x) # var:x -Vertex: bool(true) -Vertex: str("world") -Vertex: var(x) diff --git a/lang/interpret_test/TestAstFunc1/shadowing2.txtar b/lang/interpret_test/TestAstFunc1/shadowing2.txtar new file mode 100644 index 00000000..34f5dd9c --- /dev/null +++ b/lang/interpret_test/TestAstFunc1/shadowing2.txtar @@ -0,0 +1,12 @@ +-- main.mcl -- +# this should be okay, because var is shadowed +$x = "hello" +if true { + $x = "world" # shadowed + test $x {} +} +-- OUTPUT -- +Edge: str("world") -> var(x) # var:x +Vertex: bool(true) +Vertex: str("world") +Vertex: var(x) diff --git a/lang/interpret_test/TestAstFunc1/shadowing2/main.mcl b/lang/interpret_test/TestAstFunc1/shadowing2/main.mcl deleted file mode 100644 index 7569279f..00000000 --- a/lang/interpret_test/TestAstFunc1/shadowing2/main.mcl +++ /dev/null @@ -1,6 +0,0 @@ -# this should be okay, because var is shadowed -$x = "hello" -if true { - $x = "world" # shadowed - test $x {} -} diff --git a/lang/interpret_test/TestAstFunc1/simple-func1.graph b/lang/interpret_test/TestAstFunc1/simple-func1.txtar similarity index 75% rename from lang/interpret_test/TestAstFunc1/simple-func1.graph rename to lang/interpret_test/TestAstFunc1/simple-func1.txtar index 30387788..5cc59bc7 100644 --- a/lang/interpret_test/TestAstFunc1/simple-func1.graph +++ b/lang/interpret_test/TestAstFunc1/simple-func1.txtar @@ -1,3 +1,12 @@ +-- main.mcl -- +func answer() { + "the answer is 42" +} + +$out1 = answer() + +test $out1 {} +-- OUTPUT -- Edge: call:answer() -> var(out1) # var:out1 Edge: func() { str("the answer is 42") } -> call:answer() # call:answer Edge: str("the answer is 42") -> func() { str("the answer is 42") } # body diff --git a/lang/interpret_test/TestAstFunc1/simple-func1/main.mcl b/lang/interpret_test/TestAstFunc1/simple-func1/main.mcl deleted file mode 100644 index 778c7361..00000000 --- a/lang/interpret_test/TestAstFunc1/simple-func1/main.mcl +++ /dev/null @@ -1,7 +0,0 @@ -func answer() { - "the answer is 42" -} - -$out1 = answer() - -test $out1 {} diff --git a/lang/interpret_test/TestAstFunc1/simple-func2.graph b/lang/interpret_test/TestAstFunc1/simple-func2.txtar similarity index 85% rename from lang/interpret_test/TestAstFunc1/simple-func2.graph rename to lang/interpret_test/TestAstFunc1/simple-func2.txtar index 2887283c..d0c1976c 100644 --- a/lang/interpret_test/TestAstFunc1/simple-func2.graph +++ b/lang/interpret_test/TestAstFunc1/simple-func2.txtar @@ -1,3 +1,13 @@ +-- main.mcl -- +func answer() { + "the answer is 42" +} + +$out1 = answer() +$out2 = answer() + +test $out1 + $out2 {} +-- OUTPUT -- Edge: call:answer() -> var(out1) # var:out1 Edge: call:answer() -> var(out2) # var:out2 Edge: func() { str("the answer is 42") } -> call:answer() # call:answer diff --git a/lang/interpret_test/TestAstFunc1/simple-func2/main.mcl b/lang/interpret_test/TestAstFunc1/simple-func2/main.mcl deleted file mode 100644 index 250b85a4..00000000 --- a/lang/interpret_test/TestAstFunc1/simple-func2/main.mcl +++ /dev/null @@ -1,8 +0,0 @@ -func answer() { - "the answer is 42" -} - -$out1 = answer() -$out2 = answer() - -test $out1 + $out2 {} diff --git a/lang/interpret_test/TestAstFunc1/simple-lambda1.graph b/lang/interpret_test/TestAstFunc1/simple-lambda1.txtar similarity index 64% rename from lang/interpret_test/TestAstFunc1/simple-lambda1.graph rename to lang/interpret_test/TestAstFunc1/simple-lambda1.txtar index 0e8d3fc4..43176316 100644 --- a/lang/interpret_test/TestAstFunc1/simple-lambda1.graph +++ b/lang/interpret_test/TestAstFunc1/simple-lambda1.txtar @@ -1,3 +1,15 @@ +-- main.mcl -- +import "fmt" + +# this should be a function as a value, iow a lambda +$answer = func() { + "the answer is 42" +} + +$out = $answer() + +test $out {} +-- OUTPUT -- Edge: call:answer() -> var(out) # var:out Edge: func() { str("the answer is 42") } -> call:answer() # call:answer Edge: str("the answer is 42") -> func() { str("the answer is 42") } # body diff --git a/lang/interpret_test/TestAstFunc1/simple-lambda1/main.mcl b/lang/interpret_test/TestAstFunc1/simple-lambda1/main.mcl deleted file mode 100644 index 37d25bbe..00000000 --- a/lang/interpret_test/TestAstFunc1/simple-lambda1/main.mcl +++ /dev/null @@ -1,10 +0,0 @@ -import "fmt" - -# this should be a function as a value, iow a lambda -$answer = func() { - "the answer is 42" -} - -$out = $answer() - -test $out {} diff --git a/lang/interpret_test/TestAstFunc1/simple-lambda2.graph b/lang/interpret_test/TestAstFunc1/simple-lambda2.txtar similarity index 79% rename from lang/interpret_test/TestAstFunc1/simple-lambda2.graph rename to lang/interpret_test/TestAstFunc1/simple-lambda2.txtar index 2887283c..b879b30f 100644 --- a/lang/interpret_test/TestAstFunc1/simple-lambda2.graph +++ b/lang/interpret_test/TestAstFunc1/simple-lambda2.txtar @@ -1,3 +1,16 @@ +-- main.mcl -- +import "fmt" + +# this should be a function as a value, iow a lambda +$answer = func() { + "the answer is 42" +} + +$out1 = $answer() +$out2 = $answer() + +test $out1 + $out2 {} +-- OUTPUT -- Edge: call:answer() -> var(out1) # var:out1 Edge: call:answer() -> var(out2) # var:out2 Edge: func() { str("the answer is 42") } -> call:answer() # call:answer diff --git a/lang/interpret_test/TestAstFunc1/simple-lambda2/main.mcl b/lang/interpret_test/TestAstFunc1/simple-lambda2/main.mcl deleted file mode 100644 index 9be77fe9..00000000 --- a/lang/interpret_test/TestAstFunc1/simple-lambda2/main.mcl +++ /dev/null @@ -1,11 +0,0 @@ -import "fmt" - -# this should be a function as a value, iow a lambda -$answer = func() { - "the answer is 42" -} - -$out1 = $answer() -$out2 = $answer() - -test $out1 + $out2 {} diff --git a/lang/interpret_test/TestAstFunc1/slow_unification0.graph b/lang/interpret_test/TestAstFunc1/slow_unification0.txtar similarity index 82% rename from lang/interpret_test/TestAstFunc1/slow_unification0.graph rename to lang/interpret_test/TestAstFunc1/slow_unification0.txtar index 7f4ec4cc..e5203254 100644 --- a/lang/interpret_test/TestAstFunc1/slow_unification0.graph +++ b/lang/interpret_test/TestAstFunc1/slow_unification0.txtar @@ -1,3 +1,57 @@ +-- main.mcl -- +# state machine that previously experienced unusable slow type unification +import "world" + +$ns = "estate" +$exchanged = world.kvlookup($ns) +$state = maplookup($exchanged, $hostname, "default") + +if $state == "one" || $state == "default" { + + file "/tmp/mgmt/state" { + content => "state: one\n", + } + + exec "timer" { + cmd => "/usr/bin/sleep 1s", + } + kv "${ns}" { + key => $ns, + value => "two", + } + Exec["timer"] -> Kv["${ns}"] +} +if $state == "two" { + + file "/tmp/mgmt/state" { + content => "state: two\n", + } + + exec "timer" { + cmd => "/usr/bin/sleep 1s", + } + kv "${ns}" { + key => $ns, + value => "three", + } + Exec["timer"] -> Kv["${ns}"] +} +if $state == "three" { + + file "/tmp/mgmt/state" { + content => "state: three\n", + } + + exec "timer" { + cmd => "/usr/bin/sleep 1s", + } + kv "${ns}" { + key => $ns, + value => "one", + } + Exec["timer"] -> Kv["${ns}"] +} +-- OUTPUT -- Edge: call:_operator(str("=="), var(state), str("default")) -> call:_operator(str("||"), call:_operator(str("=="), var(state), str("one")), call:_operator(str("=="), var(state), str("default"))) # b Edge: call:_operator(str("=="), var(state), str("one")) -> call:_operator(str("||"), call:_operator(str("=="), var(state), str("one")), call:_operator(str("=="), var(state), str("default"))) # a Edge: call:maplookup(var(exchanged), var(hostname), str("default")) -> var(state) # var:state diff --git a/lang/interpret_test/TestAstFunc1/slow_unification0/main.mcl b/lang/interpret_test/TestAstFunc1/slow_unification0/main.mcl deleted file mode 100644 index 76aac188..00000000 --- a/lang/interpret_test/TestAstFunc1/slow_unification0/main.mcl +++ /dev/null @@ -1,52 +0,0 @@ -# state machine that previously experienced unusable slow type unification -import "world" - -$ns = "estate" -$exchanged = world.kvlookup($ns) -$state = maplookup($exchanged, $hostname, "default") - -if $state == "one" || $state == "default" { - - file "/tmp/mgmt/state" { - content => "state: one\n", - } - - exec "timer" { - cmd => "/usr/bin/sleep 1s", - } - kv "${ns}" { - key => $ns, - value => "two", - } - Exec["timer"] -> Kv["${ns}"] -} -if $state == "two" { - - file "/tmp/mgmt/state" { - content => "state: two\n", - } - - exec "timer" { - cmd => "/usr/bin/sleep 1s", - } - kv "${ns}" { - key => $ns, - value => "three", - } - Exec["timer"] -> Kv["${ns}"] -} -if $state == "three" { - - file "/tmp/mgmt/state" { - content => "state: three\n", - } - - exec "timer" { - cmd => "/usr/bin/sleep 1s", - } - kv "${ns}" { - key => $ns, - value => "one", - } - Exec["timer"] -> Kv["${ns}"] -} diff --git a/lang/interpret_test/TestAstFunc1/static-function0.graph b/lang/interpret_test/TestAstFunc1/static-function0.txtar similarity index 64% rename from lang/interpret_test/TestAstFunc1/static-function0.graph rename to lang/interpret_test/TestAstFunc1/static-function0.txtar index 7ba83bbf..4adeaeea 100644 --- a/lang/interpret_test/TestAstFunc1/static-function0.graph +++ b/lang/interpret_test/TestAstFunc1/static-function0.txtar @@ -1,3 +1,21 @@ +-- main.mcl -- +import "fmt" + +# we should only see one copy of $fn +$fn = func() { + "hello world" +} + +test "greeting1" { + anotherstr => $fn(), +} +test "greeting2" { + anotherstr => $fn(), +} +test "greeting3" { + anotherstr => $fn(), +} +-- OUTPUT -- Edge: func() { str("hello world") } -> call:fn() # call:fn Edge: func() { str("hello world") } -> call:fn() # call:fn Edge: func() { str("hello world") } -> call:fn() # call:fn diff --git a/lang/interpret_test/TestAstFunc1/static-function0/main.mcl b/lang/interpret_test/TestAstFunc1/static-function0/main.mcl deleted file mode 100644 index 7d2fa871..00000000 --- a/lang/interpret_test/TestAstFunc1/static-function0/main.mcl +++ /dev/null @@ -1,16 +0,0 @@ -import "fmt" - -# we should only see one copy of $fn -$fn = func() { - "hello world" -} - -test "greeting1" { - anotherstr => $fn(), -} -test "greeting2" { - anotherstr => $fn(), -} -test "greeting3" { - anotherstr => $fn(), -} diff --git a/lang/interpret_test/TestAstFunc1/static-function1.graph b/lang/interpret_test/TestAstFunc1/static-function1.txtar similarity index 93% rename from lang/interpret_test/TestAstFunc1/static-function1.graph rename to lang/interpret_test/TestAstFunc1/static-function1.txtar index facdbd3e..a2b2dc4d 100644 --- a/lang/interpret_test/TestAstFunc1/static-function1.graph +++ b/lang/interpret_test/TestAstFunc1/static-function1.txtar @@ -1,3 +1,23 @@ +-- main.mcl -- +import "fmt" + +# we should only see one copy of $s1, $s2 and $fn +$s1 = "hello" +$fn = func() { + $s1 + " " + $s2 +} +$s2 = "world" + +test "greeting1" { + anotherstr => $fn(), +} +test "greeting2" { + anotherstr => $fn(), +} +test "greeting3" { + anotherstr => $fn(), +} +-- OUTPUT -- Edge: call:_operator(str("+"), call:_operator(str("+"), var(s1), str(" ")), var(s2)) -> func() { call:_operator(str("+"), call:_operator(str("+"), var(s1), str(" ")), var(s2)) } # body Edge: call:_operator(str("+"), call:_operator(str("+"), var(s1), str(" ")), var(s2)) -> func() { call:_operator(str("+"), call:_operator(str("+"), var(s1), str(" ")), var(s2)) } # body Edge: call:_operator(str("+"), call:_operator(str("+"), var(s1), str(" ")), var(s2)) -> func() { call:_operator(str("+"), call:_operator(str("+"), var(s1), str(" ")), var(s2)) } # body diff --git a/lang/interpret_test/TestAstFunc1/static-function1/main.mcl b/lang/interpret_test/TestAstFunc1/static-function1/main.mcl deleted file mode 100644 index 05ff5b7c..00000000 --- a/lang/interpret_test/TestAstFunc1/static-function1/main.mcl +++ /dev/null @@ -1,18 +0,0 @@ -import "fmt" - -# we should only see one copy of $s1, $s2 and $fn -$s1 = "hello" -$fn = func() { - $s1 + " " + $s2 -} -$s2 = "world" - -test "greeting1" { - anotherstr => $fn(), -} -test "greeting2" { - anotherstr => $fn(), -} -test "greeting3" { - anotherstr => $fn(), -} diff --git a/lang/interpret_test/TestAstFunc1/unused1.graph b/lang/interpret_test/TestAstFunc1/unused1.graph deleted file mode 100644 index bc52c40b..00000000 --- a/lang/interpret_test/TestAstFunc1/unused1.graph +++ /dev/null @@ -1 +0,0 @@ -# err: errSetScope: import scope `something.mcl` failed: local import of `something.mcl` failed: module contains unused statements: found stmt: res(print) diff --git a/lang/interpret_test/TestAstFunc1/unused1.txtar b/lang/interpret_test/TestAstFunc1/unused1.txtar new file mode 100644 index 00000000..40ba1108 --- /dev/null +++ b/lang/interpret_test/TestAstFunc1/unused1.txtar @@ -0,0 +1,22 @@ +-- main.mcl -- +import "fmt" +import "something.mcl" + +include something.someclass +print "p1" { + msg => fmt.printf("someint: %d", $something.someint), +} +-- something.mcl -- +$someint = 42 +class someclass { + print "p2" { + msg => "i'm inside of someclass", + } +} + +# this should generate a compile error +print "unused" { + msg => "i'm unused because i'm inside an imported module", +} +-- OUTPUT -- +# err: errSetScope: import scope `something.mcl` failed: local import of `something.mcl` failed: module contains unused statements: found stmt: res(print) diff --git a/lang/interpret_test/TestAstFunc1/unused1/main.mcl b/lang/interpret_test/TestAstFunc1/unused1/main.mcl deleted file mode 100644 index c8d1fd1a..00000000 --- a/lang/interpret_test/TestAstFunc1/unused1/main.mcl +++ /dev/null @@ -1,7 +0,0 @@ -import "fmt" -import "something.mcl" - -include something.someclass -print "p1" { - msg => fmt.printf("someint: %d", $something.someint), -} diff --git a/lang/interpret_test/TestAstFunc1/unused1/something.mcl b/lang/interpret_test/TestAstFunc1/unused1/something.mcl deleted file mode 100644 index 6a9d5c64..00000000 --- a/lang/interpret_test/TestAstFunc1/unused1/something.mcl +++ /dev/null @@ -1,11 +0,0 @@ -$someint = 42 -class someclass { - print "p2" { - msg => "i'm inside of someclass", - } -} - -# this should generate a compile error -print "unused" { - msg => "i'm unused because i'm inside an imported module", -}