examples: lang: Test that each of the mcl examples compiles
We let these rot, so fixup the issues and test them!
This commit is contained in:
@@ -10,7 +10,7 @@ class foo {
|
|||||||
$wow = "this is wow" # gets captured
|
$wow = "this is wow" # gets captured
|
||||||
|
|
||||||
class bar($a, $b) { # a parameterized class
|
class bar($a, $b) { # a parameterized class
|
||||||
print "bar-"+ $a {
|
print ["bar-"+ $a,] {
|
||||||
msg => fmt.printf("inside bar: %s", $b + "; " + $wow),
|
msg => fmt.printf("inside bar: %s", $b + "; " + $wow),
|
||||||
|
|
||||||
Meta:autogroup => false,
|
Meta:autogroup => false,
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
$home = getenv("HOME")
|
import "fmt"
|
||||||
|
import "sys"
|
||||||
|
|
||||||
|
$home = sys.getenv("HOME")
|
||||||
|
|
||||||
cron "purpleidea-oneshot" {
|
cron "purpleidea-oneshot" {
|
||||||
session => true,
|
session => true,
|
||||||
@@ -11,4 +14,4 @@ svc "purpleidea-oneshot" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# TODO: do we need a state => $const.res.file.state.exists specified here?
|
# TODO: do we need a state => $const.res.file.state.exists specified here?
|
||||||
file printf("%s/.config/systemd/user/purpleidea-oneshot.service", $home) {}
|
file [fmt.printf("%s/.config/systemd/user/purpleidea-oneshot.service", $home),] {}
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
$home = getenv("HOME")
|
import "fmt"
|
||||||
|
import "sys"
|
||||||
|
|
||||||
|
$home = sys.getenv("HOME")
|
||||||
|
|
||||||
cron "purpleidea-oneshot" {
|
cron "purpleidea-oneshot" {
|
||||||
state => "absent",
|
state => "absent",
|
||||||
@@ -12,6 +15,6 @@ svc "purpleidea-oneshot" {
|
|||||||
session => true,
|
session => true,
|
||||||
}
|
}
|
||||||
|
|
||||||
file printf("%s/.config/systemd/user/purpleidea-oneshot.service", $home) {
|
file [fmt.printf("%s/.config/systemd/user/purpleidea-oneshot.service", $home),] {
|
||||||
state => $const.res.file.state.absent,
|
state => $const.res.file.state.absent,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import "fmt"
|
import "fmt"
|
||||||
import "sys"
|
import "sys"
|
||||||
|
|
||||||
$x = sys.getenv("TEST", "321")
|
$x = sys.defaultenv("TEST", "321")
|
||||||
|
|
||||||
print "print1" {
|
print "print1" {
|
||||||
msg => fmt.printf("TEST is: %s", $x),
|
msg => fmt.printf("TEST is: %s", $x),
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ pkg "debootstrap" {
|
|||||||
|
|
||||||
$dir = $codename + "-" + "nspawn" # dir name
|
$dir = $codename + "-" + "nspawn" # dir name
|
||||||
$cmd = fmt.printf("debootstrap --include=systemd-container %s %s %s", $codename, $dir, $baserepo)
|
$cmd = fmt.printf("debootstrap --include=systemd-container %s %s %s", $codename, $dir, $baserepo)
|
||||||
exec "debootstrap-" + $codename {
|
exec ["debootstrap-" + $codename,] {
|
||||||
cwd => $rootpath,
|
cwd => $rootpath,
|
||||||
|
|
||||||
shell => "/bin/bash",
|
shell => "/bin/bash",
|
||||||
@@ -24,8 +24,8 @@ exec "debootstrap-" + $codename {
|
|||||||
Depend => Pkg["debootstrap"],
|
Depend => Pkg["debootstrap"],
|
||||||
}
|
}
|
||||||
|
|
||||||
nspawn $dir {
|
nspawn [$dir,] {
|
||||||
state => "running",
|
state => "running",
|
||||||
|
|
||||||
Depend => Exec["debootstrap-" + $codename],
|
Depend => Exec[["debootstrap-" + $codename,]],
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,19 +1,19 @@
|
|||||||
import "fmt"
|
import "fmt"
|
||||||
|
|
||||||
$add = func($x) {
|
func add($x) { # if this was a lambda, type unification would fail! (not allowed)
|
||||||
$x + $x
|
$x + $x
|
||||||
}
|
}
|
||||||
|
|
||||||
$num = 2
|
$num = 2
|
||||||
$out1 = $add($num) # 4
|
$out1 = add($num) # 4
|
||||||
|
|
||||||
print fmt.printf("%d + %d is %d", $num, $num, $out1) { # simple math
|
print [fmt.printf("%d + %d is %d", $num, $num, $out1),] { # simple math
|
||||||
Meta:autogroup => false,
|
Meta:autogroup => false,
|
||||||
}
|
}
|
||||||
|
|
||||||
$val = "hello"
|
$val = "hello"
|
||||||
$out2 = $add($val) # hellohello
|
$out2 = add($val) # hellohello
|
||||||
|
|
||||||
print fmt.printf("%s + %s is %s", $val, $val, $out2) { # simple concat
|
print [fmt.printf("%s + %s is %s", $val, $val, $out2),] { # simple concat
|
||||||
Meta:autogroup => false,
|
Meta:autogroup => false,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ exec "exec0" {
|
|||||||
kv "kv0" {
|
kv "kv0" {
|
||||||
key => $ns,
|
key => $ns,
|
||||||
#value => "two",
|
#value => "two",
|
||||||
mapped = true,
|
#mapped => true,
|
||||||
}
|
}
|
||||||
|
|
||||||
Exec["exec0"].output -> Kv["kv0"].value
|
Exec["exec0"].output -> Kv["kv0"].value
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ if $state == "one" or $state == "default" {
|
|||||||
kv "${ns}" {
|
kv "${ns}" {
|
||||||
key => $ns,
|
key => $ns,
|
||||||
value => "two",
|
value => "two",
|
||||||
mapped = true,
|
#mapped => true,
|
||||||
}
|
}
|
||||||
Exec["timer"] -> Kv["${ns}"]
|
Exec["timer"] -> Kv["${ns}"]
|
||||||
}
|
}
|
||||||
@@ -34,7 +34,7 @@ if $state == "two" {
|
|||||||
kv "${ns}" {
|
kv "${ns}" {
|
||||||
key => $ns,
|
key => $ns,
|
||||||
value => "three",
|
value => "three",
|
||||||
mapped = true,
|
#mapped => true,
|
||||||
}
|
}
|
||||||
Exec["timer"] -> Kv["${ns}"]
|
Exec["timer"] -> Kv["${ns}"]
|
||||||
}
|
}
|
||||||
@@ -51,7 +51,7 @@ if $state == "three" {
|
|||||||
kv "${ns}" {
|
kv "${ns}" {
|
||||||
key => $ns,
|
key => $ns,
|
||||||
value => "one",
|
value => "one",
|
||||||
mapped = true,
|
#mapped => true,
|
||||||
}
|
}
|
||||||
Exec["timer"] -> Kv["${ns}"]
|
Exec["timer"] -> Kv["${ns}"]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,16 @@ cd "${ROOT}"
|
|||||||
|
|
||||||
failures=''
|
failures=''
|
||||||
|
|
||||||
# TODO: test examples/lang/ directory to see if the .mcl files compile correctly
|
# Test examples/lang/ directory to see if the .mcl files compile correctly.
|
||||||
|
|
||||||
|
find_mcl_examples() {
|
||||||
|
git ls-files | grep '\.mcl$' | grep '^examples/lang/' | grep -v 'modules/'
|
||||||
|
}
|
||||||
|
|
||||||
|
for file in $(find_mcl_examples); do
|
||||||
|
#echo "mcl: $file"
|
||||||
|
run-test ./mgmt run --tmp-prefix lang --only-unify "$file" &> /dev/null || fail_test "could not compile: $file"
|
||||||
|
done
|
||||||
|
|
||||||
buildout='test-examples.out'
|
buildout='test-examples.out'
|
||||||
# make symlink to outside of package
|
# make symlink to outside of package
|
||||||
|
|||||||
Reference in New Issue
Block a user