78 lines
2.5 KiB
Bash
Executable File
78 lines
2.5 KiB
Bash
Executable File
#!/bin/sh
|
|
. "$(dirname -- "$0")/test_context.sh"
|
|
|
|
cat > "$work/app.zi" <<'EOF'
|
|
#import "instance"
|
|
#import "tree"
|
|
|
|
#program_export
|
|
Answer :: () -> s32 {
|
|
partial: TreeCommitPlan = TreeCommitFor(true, 10, 9)
|
|
if !partial.keep_committed || partial.reconcile || partial.route_input {
|
|
return 0
|
|
}
|
|
complete: TreeCommitPlan = TreeCommitFor(true, 10, 10)
|
|
if complete.keep_committed || !complete.reconcile || !complete.route_input {
|
|
return 0
|
|
}
|
|
inactive: TreeCommitPlan = TreeCommitFor(false, 10, 0)
|
|
if inactive.keep_committed || !inactive.reconcile || !inactive.route_input {
|
|
return 0
|
|
}
|
|
empty: TreeCommitPlan = TreeCommitFor(true, 0, 0)
|
|
if empty.keep_committed || !empty.reconcile || !empty.route_input {
|
|
return 0
|
|
}
|
|
invalid: TreeCommitPlan = TreeCommitFor(true, 10, -1)
|
|
if invalid.keep_committed || !invalid.reconcile || !invalid.route_input {
|
|
return 0
|
|
}
|
|
if !InstanceExpired(-1) || InstanceExpired(0) ||
|
|
InstanceExpired(12) || !InstanceExpired(13) { return 0 }
|
|
return 42
|
|
}
|
|
EOF
|
|
|
|
"$ziran" ir --root "$work" $kryon_ui_args --module-path "$ziran_root/std" \
|
|
-o "$work/ir" "$work/app.zi"
|
|
"$ziran" bundle --root "$work" $kryon_ui_args --module-path "$ziran_root/std" \
|
|
--entry app:Answer -o "$work/source.zx" "$work/app.zi"
|
|
"$ziran" bundle --root "$work/ir" --module-path "$work/ir" \
|
|
--entry app:Answer -o "$work/saved.zx" "$work/ir/app.zir"
|
|
cmp "$work/source.zx" "$work/saved.zx"
|
|
test "$("$ziran" run "$work/source.zx")" = 42
|
|
test "$("$ziran" run "$work/saved.zx")" = 42
|
|
|
|
for input in source saved; do
|
|
if test "$input" = source; then
|
|
module=$work/app.zi
|
|
module_dir="$kryon_ui_args"
|
|
else
|
|
module=$work/ir/app.zir
|
|
module_dir="--module-path $work/ir"
|
|
fi
|
|
for target in c go; do
|
|
output=$work/$target-$input
|
|
"$ziran" build --target="$target" --root "$work" \
|
|
$module_dir --module-path "$ziran_root/std" -o "$output" "$module"
|
|
if test "$target" = c; then
|
|
cat > "$output/main.c" <<'C'
|
|
#include "app.h"
|
|
int main(void) { return Answer() == 42 ? 0 : 1; }
|
|
C
|
|
"${CC:-cc}" -std=c11 -I"$ziran_root/include" -I"$output" \
|
|
"$output"/*.c -o "$output/app"
|
|
"$output/app"
|
|
else
|
|
cat > "$output/tree_test.go" <<'GO'
|
|
package ziran
|
|
import "testing"
|
|
func TestTreeCommit(t *testing.T) {
|
|
if App_Answer() != 42 { t.Fatal("tree commit") }
|
|
}
|
|
GO
|
|
GO111MODULE=off go test "$output"/*.go
|
|
fi
|
|
done
|
|
done
|