aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorGravatar zinc <zinc@downsta.ir> 2026-10-14 10:06:27 +0000
committerGravatar zinc <zinc@downsta.ir> 2026-10-14 10:06:27 +0000
commitc2270cc944424579e4577e67ed17a66512d856b4 (patch)
tree04fc1ede53e0cbf2c2562f724fd539836c450306 /tests
parenttodo: tick the spec; list the bugs its appendix b found (diff)
parentsplit compiler.zc into files by phase (diff)
Merge the compiler split into phase files
also: ca_owners in the language server keeps the owner order in a fixed array instead of a heap list the analyzer rejected.
Diffstat (limited to 'tests')
-rw-r--r--tests/drivers/core_lsp_test.js4
-rw-r--r--tests/drivers/hover_surface_test.js3
-rw-r--r--tests/drivers/nav_test.js5
-rwxr-xr-xtests/test.sh12
-rw-r--r--tests/test_win.ps14
5 files changed, 19 insertions, 9 deletions
diff --git a/tests/drivers/core_lsp_test.js b/tests/drivers/core_lsp_test.js
index c3c01aa..5123537 100644
--- a/tests/drivers/core_lsp_test.js
+++ b/tests/drivers/core_lsp_test.js
@@ -6,6 +6,8 @@ const fs = require('fs');
const cp = require('child_process');
const path = require('path');
const target = process.argv[2];
+// the compiler is the files listed in src/compiler/parts; the server checks them as the one document they make
+const compilerSource = () => fs.readFileSync('src/compiler/parts', 'utf8').split(/\r?\n/).filter(Boolean).map(n => fs.readFileSync(path.join('src/compiler', n), 'utf8')).join('');
const files = ['src/core/core.zc', 'src/runtime/rt.zc', 'src/compiler/compiler.zc', 'src/runtime/run.zc', 'src/lib/std.zc', 'src/lib/icon.zc', 'src/lsp/server.zc', 'src/tools/build.zc'];
const frame = message => {
const body = Buffer.from(JSON.stringify(message));
@@ -13,7 +15,7 @@ const frame = message => {
};
for (const file of files) {
const uri = 'file://' + path.resolve(file);
- const text = fs.readFileSync(file, 'utf8');
+ const text = file === 'src/compiler/compiler.zc' ? compilerSource() : fs.readFileSync(file, 'utf8');
const messages = [
{ jsonrpc: '2.0', id: 1, method: 'initialize', params: {} },
{ jsonrpc: '2.0', method: 'initialized', params: {} },
diff --git a/tests/drivers/hover_surface_test.js b/tests/drivers/hover_surface_test.js
index 688aca6..47056f6 100644
--- a/tests/drivers/hover_surface_test.js
+++ b/tests/drivers/hover_surface_test.js
@@ -17,7 +17,8 @@ function doc(uri, text) {
return rid;
};
}
-const compiler = fs.readFileSync('src/compiler/compiler.zc', 'utf8');
+// the compiler is the files listed in src/compiler/parts, joined: the one document the server embeds
+const compiler = fs.readFileSync('src/compiler/parts', 'utf8').split(/\r?\n/).filter(Boolean).map(n => fs.readFileSync('src/compiler/' + n, 'utf8')).join('');
const ask = doc('tinyvm:/compiler.zc', compiler);
checks.push([ask('ifrcap = NIF', 9), /const int NIF = 431/, /431/]);
checks.push([ask('capture_width = NCAP', 16), /const int NCAP = 32/, /initial capture capacity/, /32/]);
diff --git a/tests/drivers/nav_test.js b/tests/drivers/nav_test.js
index 8f0d8fd..deff6f3 100644
--- a/tests/drivers/nav_test.js
+++ b/tests/drivers/nav_test.js
@@ -68,7 +68,10 @@ assert.strictEqual(slice(source('/std.zc'), loc[0]), 'atoi', 'a method goes to i
loc = bdef('now(');
assert.strictEqual(slice(source('/std.zc'), loc[0]), 'now');
assert.strictEqual(source('/std.zc'), fs.readFileSync(path.join(root, 'src', 'lib', 'std.zc'), 'utf8'), 'the embedded std is the file');
-assert.strictEqual(source('/compiler.zc'), fs.readFileSync(path.join(root, 'src', 'compiler', 'compiler.zc'), 'utf8'), 'the embedded compiler is the file');
+const parts = fs.readFileSync(path.join(root, 'src', 'compiler', 'parts'), 'utf8').split(/\r?\n/).filter(Boolean);
+assert.strictEqual(source('/compiler.zc'), parts.map(n => fs.readFileSync(path.join(root, 'src', 'compiler', n), 'utf8')).join(''), 'the embedded compiler is its parts, joined in order');
+const embedded = [...fs.readFileSync(path.join(root, 'src', 'lsp', 'server.zc'), 'utf8').matchAll(/^embed "src\/compiler\/([^"]+)" as bstr/gm)].map(m => m[1]);
+assert.deepStrictEqual(embedded, parts, 'src/lsp/server.zc embeds the files of src/compiler/parts, in order');
assert.strictEqual(source('/server.zc'), fs.readFileSync(path.join(root, 'src', 'lsp', 'server.zc'), 'utf8'), 'the embedded server is the file');
loc = bdef('s_to_n(');
assert.ok(loc && loc.length === 1 && loc[0].uri === 'tinyvm:/rt.zc', 's_to_n opens the runtime source: ' + JSON.stringify(loc));
diff --git a/tests/test.sh b/tests/test.sh
index 223c9aa..298c356 100755
--- a/tests/test.sh
+++ b/tests/test.sh
@@ -25,7 +25,9 @@
cd "$(dirname "$0")/.."; T=$(mktemp -d); trap 'rm -rf $T' EXIT
ok=0; bad=0
chk(){ if [ "$1" = "$2" ]; then echo "ok $3"; ok=$((ok+1)); else echo "FAIL $3: got [$1]"; bad=$((bad+1)); fi; }
-src(){ cat src/runtime/rt.zc src/core/core.zc src/compiler/compiler.zc; }
+# the compiler is the files listed in src/compiler/parts, in that order
+ccparts(){ tr -d '\r' < src/compiler/parts | sed 's|^|src/compiler/|'; }
+src(){ cat src/runtime/rt.zc src/core/core.zc $(ccparts); }
# -j N runs N sections at a time: j is how many cores to use. each section
# writes its own log, so the output still reads in the order it always did.
JOBS=1; QUICK=0; SELECT=""
@@ -64,7 +66,7 @@ mkdir -p build && $CC -shared -fPIC -w tests/data/sbv.c -o build/sbv.so || exit
selfc(){ (cat src/tools/build.zc; printf '`'; src) | $1 > $2; }
-# bootstrap: zc0 (c) -> g0, g0 compiles compiler.zc -> g1, g1 compiles it -> g2.
+# bootstrap: zc0 (c) -> g0, g0 compiles the compiler -> g1, g1 compiles it -> g2.
# each stage's core embeds the image in its own directory
mkdir $T/s0 $T/s1
src | $T/zc0 > $T/s0/g0.bin && $T/mkg < $T/s0/g0.bin > $T/s0/genome.bin || exit 1
@@ -227,7 +229,7 @@ s_interp() {
grep -v '^ok' $T/arrays.out
chk $r 0 "native array receiver, algorithm and ownership contracts"
# actors are a library: nothing the compiler compiles or reads by default mentions them
- chk "$(grep -il actor src/compiler/compiler.zc src/runtime/rt.zc src/core/core.zc src/lib/std.zc src/lib/icon.zc src/tools/build.zc | wc -l)" "0" "no actor code in the compiler or anything it reads by default"
+ chk "$(grep -il actor $(ccparts) src/runtime/rt.zc src/core/core.zc src/lib/std.zc src/lib/icon.zc src/tools/build.zc | wc -l)" "0" "no actor code in the compiler or anything it reads by default"
python3 tests/drivers/actor_test.py $T/zy > $T/actor.out 2>&1; r=$?
grep -v '^ok' $T/actor.out
chk $r 0 "native isolated actor acceptance, rejection and regression fixtures"
@@ -527,7 +529,9 @@ s_lsp() {
done
chk "$($lsp < examples/struct_closure_opt.zc | grep -c error)" "0" "lsp: methods and closures check clean"
# a file of a larger build checks on its own: its bodyless declarations are not errors in check mode
- for f in src/runtime/rt.zc src/runtime/run.zc src/compiler/compiler.zc src/lsp/server.zc; do chk "$($lsp < $f | grep -c ': error:')" "0" "lsp: $f checks alone"; done
+ for f in src/runtime/rt.zc src/runtime/run.zc src/lsp/server.zc; do chk "$($lsp < $f | grep -c ': error:')" "0" "lsp: $f checks alone"; done
+ # the compiler is several files that only make sense together: check them as one document
+ chk "$(cat $(ccparts) | $lsp | grep -c ': error:')" "0" "lsp: the compiler (src/compiler/parts) checks alone"
chk "$($lsp < tests/programs/decl_undefined.zc)" "no errors" "lsp: a bodyless declaration is not an error in check mode"
chk "$($lsp < tests/programs/undefined_call.zc | grep -c ': error:')" "1" "lsp: a call to a name nothing defines is still an error"
chk "$($lsp --annotate < tests/programs/annotate.zc | md5sum)" "$(md5sum < tests/programs/annotate.expected)" "lsp --annotate writes the types the compiler can see into a program"
diff --git a/tests/test_win.ps1 b/tests/test_win.ps1
index 953e875..cb64f0b 100644
--- a/tests/test_win.ps1
+++ b/tests/test_win.ps1
@@ -57,14 +57,14 @@ try {
& $cc -fwrapv -O1 -w src\tools\zc0.c -Isrc/core "-I$map" -o "$tempDir\zc0.exe"
& $cc -fwrapv -O1 -w src\tools\mkgenome.c "-I$map" -o "$tempDir\mkgenome.exe"
- cmd.exe /c "(type src\runtime\rt.zc & type src\core\core.zc & type src\compiler\compiler.zc) | `"$tempDir\zc0.exe`" > `"$tempDir\s0\g0.bin`""
+ cmd.exe /c "(type src\runtime\rt.zc & type src\core\core.zc & for /f %f in (src\compiler\parts) do @type src\compiler\%f) | `"$tempDir\zc0.exe`" > `"$tempDir\s0\g0.bin`""
cmd.exe /c "`"$tempDir\mkgenome.exe`" < `"$tempDir\s0\g0.bin`" > `"$tempDir\s0\genome.bin`""
& $cc -fwrapv -O2 -w -DJTYPE=int src\core\core.c src\core\io_win.c -Isrc/core "-I$map" "--embed-dir=$tempDir\s0" -o "$tempDir\zy0.exe"
$bzc = [IO.File]::ReadAllText("src\tools\build.zc")
$rt = [IO.File]::ReadAllText("src\runtime\rt.zc")
$core = [IO.File]::ReadAllText("src\core\core.zc")
- $cp = [IO.File]::ReadAllText("src\compiler\compiler.zc")
+ $cp = (Get-Content "src\compiler\parts" | Where-Object { $_.Trim() } | ForEach-Object { [IO.File]::ReadAllText("src\compiler\$($_.Trim())") }) -join ""
$combined = $bzc + [char]96 + $rt + $core + $cp
[IO.File]::WriteAllBytes("$tempDir\in.tmp", [Text.Encoding]::ASCII.GetBytes($combined))