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:
James Shubin
2024-07-31 16:01:51 -04:00
parent 6de7d8b254
commit d0ed004b24
9 changed files with 34 additions and 19 deletions

View File

@@ -10,7 +10,7 @@ class foo {
$wow = "this is wow" # gets captured
class bar($a, $b) { # a parameterized class
print "bar-"+ $a {
print ["bar-"+ $a,] {
msg => fmt.printf("inside bar: %s", $b + "; " + $wow),
Meta:autogroup => false,

View File

@@ -1,4 +1,7 @@
$home = getenv("HOME")
import "fmt"
import "sys"
$home = sys.getenv("HOME")
cron "purpleidea-oneshot" {
session => true,
@@ -11,4 +14,4 @@ svc "purpleidea-oneshot" {
}
# 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),] {}

View File

@@ -1,4 +1,7 @@
$home = getenv("HOME")
import "fmt"
import "sys"
$home = sys.getenv("HOME")
cron "purpleidea-oneshot" {
state => "absent",
@@ -12,6 +15,6 @@ svc "purpleidea-oneshot" {
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,
}

View File

@@ -1,7 +1,7 @@
import "fmt"
import "sys"
$x = sys.getenv("TEST", "321")
$x = sys.defaultenv("TEST", "321")
print "print1" {
msg => fmt.printf("TEST is: %s", $x),

View File

@@ -12,7 +12,7 @@ pkg "debootstrap" {
$dir = $codename + "-" + "nspawn" # dir name
$cmd = fmt.printf("debootstrap --include=systemd-container %s %s %s", $codename, $dir, $baserepo)
exec "debootstrap-" + $codename {
exec ["debootstrap-" + $codename,] {
cwd => $rootpath,
shell => "/bin/bash",
@@ -24,8 +24,8 @@ exec "debootstrap-" + $codename {
Depend => Pkg["debootstrap"],
}
nspawn $dir {
nspawn [$dir,] {
state => "running",
Depend => Exec["debootstrap-" + $codename],
Depend => Exec[["debootstrap-" + $codename,]],
}

View File

@@ -1,19 +1,19 @@
import "fmt"
$add = func($x) {
func add($x) { # if this was a lambda, type unification would fail! (not allowed)
$x + $x
}
$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,
}
$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,
}

View File

@@ -13,7 +13,7 @@ exec "exec0" {
kv "kv0" {
key => $ns,
#value => "two",
mapped = true,
#mapped => true,
}
Exec["exec0"].output -> Kv["kv0"].value

View File

@@ -17,7 +17,7 @@ if $state == "one" or $state == "default" {
kv "${ns}" {
key => $ns,
value => "two",
mapped = true,
#mapped => true,
}
Exec["timer"] -> Kv["${ns}"]
}
@@ -34,7 +34,7 @@ if $state == "two" {
kv "${ns}" {
key => $ns,
value => "three",
mapped = true,
#mapped => true,
}
Exec["timer"] -> Kv["${ns}"]
}
@@ -51,7 +51,7 @@ if $state == "three" {
kv "${ns}" {
key => $ns,
value => "one",
mapped = true,
#mapped => true,
}
Exec["timer"] -> Kv["${ns}"]
}

View File

@@ -11,7 +11,16 @@ cd "${ROOT}"
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'
# make symlink to outside of package