From 19cceb1b35c5ac21c712a3de46b629cfcb694500 Mon Sep 17 00:00:00 2001 From: Brett Broadhurst Date: Fri, 3 Apr 2026 12:22:22 -0600 Subject: [PATCH] chore: move all remaining llvm-lit tests into zig's test runner --- CMakeLists.txt | 5 --- src/Sema.zig | 8 +--- src/Story/runtime_tests.zig | 8 ++++ .../testdata/global-shadowing-2/input.txt | 0 .../testdata/global-shadowing-2/story.ink | 0 .../global-shadowing-2/transcript.txt | 1 + src/Story/testdata/global-shadowing/input.txt | 0 .../Story/testdata/global-shadowing/story.ink | 0 .../testdata/global-shadowing/transcript.txt | 1 + src/error_tests.zig | 37 ++++++++++++++++ testing/regression/CMakeLists.txt | 9 ---- testing/regression/lit.cfg.py | 14 ------ testing/regression/lit.site.cfg.py.in | 8 ---- .../semantics/global-shadowing-3.ink | 2 - .../syntax/conditional-logical-and.ink | 27 ------------ .../syntax/conditional-logical-or.ink | 27 ------------ .../syntax/conditional-simple-switch.ink | 43 ------------------- .../syntax/const-expected-expression.ink | 1 - .../syntax/content-substitution.ink | 23 ---------- testing/regression/syntax/function-simple.ink | 28 ------------ .../syntax/knot-expected-identifier.ink | 2 - .../syntax/knot-qualified-lookup.ink | 34 --------------- testing/regression/syntax/knot-stitches.ink | 31 ------------- .../syntax/var-expected-expression.ink | 1 - 24 files changed, 48 insertions(+), 262 deletions(-) delete mode 100644 CMakeLists.txt create mode 100644 src/Story/testdata/global-shadowing-2/input.txt rename testing/regression/semantics/global-shadowing-2.ink => src/Story/testdata/global-shadowing-2/story.ink (100%) create mode 100644 src/Story/testdata/global-shadowing-2/transcript.txt create mode 100644 src/Story/testdata/global-shadowing/input.txt rename testing/regression/semantics/global-shadowing.ink => src/Story/testdata/global-shadowing/story.ink (100%) create mode 100644 src/Story/testdata/global-shadowing/transcript.txt delete mode 100644 testing/regression/CMakeLists.txt delete mode 100644 testing/regression/lit.cfg.py delete mode 100644 testing/regression/lit.site.cfg.py.in delete mode 100644 testing/regression/semantics/global-shadowing-3.ink delete mode 100644 testing/regression/syntax/conditional-logical-and.ink delete mode 100644 testing/regression/syntax/conditional-logical-or.ink delete mode 100644 testing/regression/syntax/conditional-simple-switch.ink delete mode 100644 testing/regression/syntax/const-expected-expression.ink delete mode 100644 testing/regression/syntax/content-substitution.ink delete mode 100644 testing/regression/syntax/function-simple.ink delete mode 100644 testing/regression/syntax/knot-expected-identifier.ink delete mode 100644 testing/regression/syntax/knot-qualified-lookup.ink delete mode 100644 testing/regression/syntax/knot-stitches.ink delete mode 100644 testing/regression/syntax/var-expected-expression.ink diff --git a/CMakeLists.txt b/CMakeLists.txt deleted file mode 100644 index 0872fb9..0000000 --- a/CMakeLists.txt +++ /dev/null @@ -1,5 +0,0 @@ -cmake_minimum_required(VERSION 3.20) - -project(InkCompiler LANGUAGES NONE) - -add_subdirectory(testing/regression) diff --git a/src/Sema.zig b/src/Sema.zig index 51aec9f..63c208f 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -777,12 +777,6 @@ fn irBreak( return error.InvalidBreakTarget; } -fn irBreakInline(sema: *Sema, inst: Ir.Inst.Index) InnerError!ValueInfo { - const data = sema.ir.instructions[@intFromEnum(inst)].data.bin; - const rvalue_inst = sema.resolveInst(data.rhs); - return rvalue_inst; -} - fn irContentPush(sema: *Sema, builder: *Builder, inst: Ir.Inst.Index) InnerError!void { const data = sema.ir.instructions[@intFromEnum(inst)].data.un; const lhs = sema.resolveInst(data.lhs); @@ -981,7 +975,7 @@ fn irDivert( const arg_end = sema.ir.extra[extra.end + i]; defer arg_start = arg_end; const arg_body = body[arg_start..arg_end]; - const arg_value = try analyzeBodyInner(sema, builder, block, @ptrCast(arg_body), false); + const arg_value = try analyzeInlineBody(sema, builder, block, @ptrCast(arg_body)); if (arg_value != .none) try builder.ensureLoad(arg_value); } try builder.addConstOp(.divert, @intCast(args_len)); diff --git a/src/Story/runtime_tests.zig b/src/Story/runtime_tests.zig index c9ac936..117bf00 100644 --- a/src/Story/runtime_tests.zig +++ b/src/Story/runtime_tests.zig @@ -14,6 +14,14 @@ test "fixture - constant folding" { try testRuntimeFixture("constant-folding"); } +test "fixture - global variable shadowing" { + try testRuntimeFixture("global-shadowing"); +} + +test "fixture - global variable shadowing 2" { + try testRuntimeFixture("global-shadowing-2"); +} + test "fixture - simple conditional" { try testRuntimeFixture("simple-conditional"); } diff --git a/src/Story/testdata/global-shadowing-2/input.txt b/src/Story/testdata/global-shadowing-2/input.txt new file mode 100644 index 0000000..e69de29 diff --git a/testing/regression/semantics/global-shadowing-2.ink b/src/Story/testdata/global-shadowing-2/story.ink similarity index 100% rename from testing/regression/semantics/global-shadowing-2.ink rename to src/Story/testdata/global-shadowing-2/story.ink diff --git a/src/Story/testdata/global-shadowing-2/transcript.txt b/src/Story/testdata/global-shadowing-2/transcript.txt new file mode 100644 index 0000000..9c595a6 --- /dev/null +++ b/src/Story/testdata/global-shadowing-2/transcript.txt @@ -0,0 +1 @@ +temp diff --git a/src/Story/testdata/global-shadowing/input.txt b/src/Story/testdata/global-shadowing/input.txt new file mode 100644 index 0000000..e69de29 diff --git a/testing/regression/semantics/global-shadowing.ink b/src/Story/testdata/global-shadowing/story.ink similarity index 100% rename from testing/regression/semantics/global-shadowing.ink rename to src/Story/testdata/global-shadowing/story.ink diff --git a/src/Story/testdata/global-shadowing/transcript.txt b/src/Story/testdata/global-shadowing/transcript.txt new file mode 100644 index 0000000..9c595a6 --- /dev/null +++ b/src/Story/testdata/global-shadowing/transcript.txt @@ -0,0 +1 @@ +temp diff --git a/src/error_tests.zig b/src/error_tests.zig index 7886b82..b225a4a 100644 --- a/src/error_tests.zig +++ b/src/error_tests.zig @@ -2,6 +2,43 @@ const std = @import("std"); const compile = @import("compile.zig"); const Module = compile.Module; +test "compiler: VAR expected expression" { + try testEqual( + \\VAR foo = + , + \\:1:10: error: expected expression + \\1 | VAR foo = + \\ | ^ + \\ + , + ); +} + +test "compiler: CONST expected expression" { + try testEqual( + \\CONST foo = + , + \\:1:12: error: expected expression + \\1 | CONST foo = + \\ | ^ + \\ + , + ); +} + +test "compiler: knot expected identifier" { + try testEqual( + \\=== + \\Hello, world! + , + \\:1:4: error: expected identifier + \\1 | === + \\ | ^ + \\ + , + ); +} + test "compiler: unknown global variable" { try testEqual( \\{a} diff --git a/testing/regression/CMakeLists.txt b/testing/regression/CMakeLists.txt deleted file mode 100644 index 4e61a2a..0000000 --- a/testing/regression/CMakeLists.txt +++ /dev/null @@ -1,9 +0,0 @@ -set(LIT_CFG_DIR ${CMAKE_CURRENT_SOURCE_DIR}) - -configure_file(lit.site.cfg.py.in ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg.py @ONLY) - -find_program(LLVM_LIT_EXECUTABLE NAMES llvm-lit lit) - -add_custom_target(check - COMMAND ${LLVM_LIT_EXECUTABLE} -v "${CMAKE_CURRENT_BINARY_DIR}" -) diff --git a/testing/regression/lit.cfg.py b/testing/regression/lit.cfg.py deleted file mode 100644 index 6cdd27b..0000000 --- a/testing/regression/lit.cfg.py +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env python3 - -import os -import lit.formats - -config.name = "Ink Compiler Regression Tests" -config.suffixes = [".ink"] -config.tools = ["FileCheck"] -config.test_format = lit.formats.ShTest(execute_external=True) -config.test_source_root = os.path.dirname(__file__) -config.test_exec_root = os.path.join(config.project_build_root, "testing", "regression") -exe_path = os.path.join(config.project_zig_root, "bin", "inkc") - -config.substitutions.append(("%ink-compiler", exe_path)) diff --git a/testing/regression/lit.site.cfg.py.in b/testing/regression/lit.site.cfg.py.in deleted file mode 100644 index 8765729..0000000 --- a/testing/regression/lit.site.cfg.py.in +++ /dev/null @@ -1,8 +0,0 @@ -import os - -config.project_source_root = r"@CMAKE_SOURCE_DIR@" -config.project_build_root = r"@CMAKE_BINARY_DIR@" -config.project_zig_root = os.path.join(r"@CMAKE_SOURCE_DIR@", "zig-out") - -lit_config.load_config( - config, os.path.join(config.project_source_root, "testing", "regression", "lit.cfg.py")) diff --git a/testing/regression/semantics/global-shadowing-3.ink b/testing/regression/semantics/global-shadowing-3.ink deleted file mode 100644 index 3e0ea28..0000000 --- a/testing/regression/semantics/global-shadowing-3.ink +++ /dev/null @@ -1,2 +0,0 @@ -VAR foo = "Hello, world!" -VAR foo = "Hello, world!" diff --git a/testing/regression/syntax/conditional-logical-and.ink b/testing/regression/syntax/conditional-logical-and.ink deleted file mode 100644 index 6ab45b0..0000000 --- a/testing/regression/syntax/conditional-logical-and.ink +++ /dev/null @@ -1,27 +0,0 @@ -// RUN: %ink-compiler --stdin --compile-only --dump-ast < %s | FileCheck %s - -// CHECK: File "" -// CHECK-NEXT: `--BlockStmt -// CHECK-NEXT: |--TempDecl -// CHECK-NEXT: | |--Identifier `x` -// CHECK-NEXT: | `--NumberLiteral `2` -// CHECK-NEXT: `--ContentStmt -// CHECK-NEXT: `--Content -// CHECK-NEXT: `--IfStmt -// CHECK-NEXT: |--LogicalAndExpr -// CHECK-NEXT: | |--LogicalGreaterThanOrEqualExpr -// CHECK-NEXT: | | |--Identifier `x` -// CHECK-NEXT: | | `--NumberLiteral `1` -// CHECK-NEXT: | `--LogicalLesserThanOrEqualExpr -// CHECK-NEXT: | |--Identifier `x` -// CHECK-NEXT: | `--NumberLiteral `10` -// CHECK-NEXT: `--BlockStmt -// CHECK-NEXT: `--ContentStmt -// CHECK-NEXT: `--Content -// CHECK-NEXT: `--StringLiteral `Between one and ten!` - -~ temp x = 2 - -{x >= 1 and x <= 10: - Between one and ten! -} diff --git a/testing/regression/syntax/conditional-logical-or.ink b/testing/regression/syntax/conditional-logical-or.ink deleted file mode 100644 index 3e05548..0000000 --- a/testing/regression/syntax/conditional-logical-or.ink +++ /dev/null @@ -1,27 +0,0 @@ -// RUN: %ink-compiler --stdin --compile-only --dump-ast < %s | FileCheck %s - -// CHECK: File "" -// CHECK-NEXT: `--BlockStmt -// CHECK-NEXT: |--TempDecl -// CHECK-NEXT: | |--Identifier `x` -// CHECK-NEXT: | `--NumberLiteral `2` -// CHECK-NEXT: `--ContentStmt -// CHECK-NEXT: `--Content -// CHECK-NEXT: `--IfStmt -// CHECK-NEXT: |--LogicalOrExpr -// CHECK-NEXT: | |--LogicalGreaterThanOrEqualExpr -// CHECK-NEXT: | | |--Identifier `x` -// CHECK-NEXT: | | `--NumberLiteral `1` -// CHECK-NEXT: | `--LogicalEqualityExpr -// CHECK-NEXT: | |--Identifier `x` -// CHECK-NEXT: | `--FalseLiteral -// CHECK-NEXT: `--BlockStmt -// CHECK-NEXT: `--ContentStmt -// CHECK-NEXT: `--Content -// CHECK-NEXT: `--StringLiteral `Greater than one or false!` - -~ temp x = 2 - -{x >= 1 or x == false: - Greater than one or false! -} diff --git a/testing/regression/syntax/conditional-simple-switch.ink b/testing/regression/syntax/conditional-simple-switch.ink deleted file mode 100644 index 2bfcaa8..0000000 --- a/testing/regression/syntax/conditional-simple-switch.ink +++ /dev/null @@ -1,43 +0,0 @@ -// RUN: %ink-compiler --stdin --compile-only --dump-ast < %s | FileCheck %s - -// CHECK: File "" -// CHECK-NEXT: `--BlockStmt -// CHECK-NEXT: |--TempDecl -// CHECK-NEXT: | |--Identifier `x` -// CHECK-NEXT: | `--NumberLiteral `3` -// CHECK-NEXT: `--ContentStmt -// CHECK-NEXT: `--Content -// CHECK-NEXT: `--SwitchStmt -// CHECK-NEXT: |--Identifier `x` -// CHECK-NEXT: |--SwitchCase -// CHECK-NEXT: | |--NumberLiteral `0` -// CHECK-NEXT: | `--BlockStmt -// CHECK-NEXT: | `--ContentStmt -// CHECK-NEXT: | `--Content -// CHECK-NEXT: | `--StringLiteral `zero` -// CHECK-NEXT: |--SwitchCase -// CHECK-NEXT: | |--NumberLiteral `1` -// CHECK-NEXT: | `--BlockStmt -// CHECK-NEXT: | `--ContentStmt -// CHECK-NEXT: | `--Content -// CHECK-NEXT: | `--StringLiteral `one` -// CHECK-NEXT: |--SwitchCase -// CHECK-NEXT: | |--NumberLiteral `2` -// CHECK-NEXT: | `--BlockStmt -// CHECK-NEXT: | `--ContentStmt -// CHECK-NEXT: | `--Content -// CHECK-NEXT: | `--StringLiteral `two` -// CHECK-NEXT: `--ElseBranch -// CHECK-NEXT: `--BlockStmt -// CHECK-NEXT: `--ContentStmt -// CHECK-NEXT: `--Content -// CHECK-NEXT: `--StringLiteral `lots` - -~ temp x = 3 - -{ x: -- 0: zero -- 1: one -- 2: two -- else: lots -} diff --git a/testing/regression/syntax/const-expected-expression.ink b/testing/regression/syntax/const-expected-expression.ink deleted file mode 100644 index 03f8805..0000000 --- a/testing/regression/syntax/const-expected-expression.ink +++ /dev/null @@ -1 +0,0 @@ -CONST foo = diff --git a/testing/regression/syntax/content-substitution.ink b/testing/regression/syntax/content-substitution.ink deleted file mode 100644 index 2dc97a6..0000000 --- a/testing/regression/syntax/content-substitution.ink +++ /dev/null @@ -1,23 +0,0 @@ -// RUN: %ink-compiler --stdin --compile-only --dump-ast < %s | FileCheck %s - -// CHECK: File "" -// CHECK-NEXT: `--BlockStmt -// CHECK-NEXT: |--VarDecl -// CHECK-NEXT: | |--Identifier `x` -// CHECK-NEXT: | `--StringExpr `"Hello world 1"` -// CHECK-NEXT: | `--StringLiteral `Hello world 1` -// CHECK-NEXT: |--ContentStmt -// CHECK-NEXT: | `--Content -// CHECK-NEXT: | `--InlineLogicExpr -// CHECK-NEXT: | `--Identifier `x` -// CHECK-NEXT: `--ContentStmt -// CHECK-NEXT: `--Content -// CHECK-NEXT: |--StringLiteral `Hello ` -// CHECK-NEXT: |--InlineLogicExpr -// CHECK-NEXT: | `--StringExpr `"world"` -// CHECK-NEXT: | `--StringLiteral `world` -// CHECK-NEXT: `--StringLiteral ` 2.` - -VAR x = "Hello world 1" -{x} -Hello {"world"} 2. diff --git a/testing/regression/syntax/function-simple.ink b/testing/regression/syntax/function-simple.ink deleted file mode 100644 index 7464678..0000000 --- a/testing/regression/syntax/function-simple.ink +++ /dev/null @@ -1,28 +0,0 @@ -// RUN: %ink-compiler --stdin --compile-only --dump-ast < %s | FileCheck %s - -// CHECK: File "" -// CHECK-NEXT: |--BlockStmt -// CHECK-NEXT: | `--ContentStmt -// CHECK-NEXT: | `--Content -// CHECK-NEXT: | `--InlineLogicExpr -// CHECK-NEXT: | `--CallExpr -// CHECK-NEXT: | |--Identifier `func` -// CHECK-NEXT: | `--ArgumentList -// CHECK-NEXT: | |--NumberLiteral `1` -// CHECK-NEXT: | `--NumberLiteral `2` -// CHECK-NEXT: `--FunctionDecl -// CHECK-NEXT: |--FunctionProto -// CHECK-NEXT: | |--Identifier `func` -// CHECK-NEXT: | `--ParamList -// CHECK-NEXT: | |--ParamDecl `a` -// CHECK-NEXT: | `--ParamDecl `b` -// CHECK-NEXT: `--BlockStmt -// CHECK-NEXT: `--ReturnStmt -// CHECK-NEXT: `--AddExpr -// CHECK-NEXT: |--Identifier `a` -// CHECK-NEXT: `--Identifier `b` - -{func(1, 2)} - -== function func(a, b) -~ return a + b diff --git a/testing/regression/syntax/knot-expected-identifier.ink b/testing/regression/syntax/knot-expected-identifier.ink deleted file mode 100644 index 7ebb478..0000000 --- a/testing/regression/syntax/knot-expected-identifier.ink +++ /dev/null @@ -1,2 +0,0 @@ -=== -Hello, world! diff --git a/testing/regression/syntax/knot-qualified-lookup.ink b/testing/regression/syntax/knot-qualified-lookup.ink deleted file mode 100644 index 2f3b86d..0000000 --- a/testing/regression/syntax/knot-qualified-lookup.ink +++ /dev/null @@ -1,34 +0,0 @@ -// RUN: %ink-compiler --stdin --compile-only --dump-ast < %s | FileCheck %s - -// CHECK: File "" -// CHECK-NEXT: |--BlockStmt -// CHECK-NEXT: | `--DivertStmt -// CHECK-NEXT: | `--Divert -// CHECK-NEXT: | `--CallExpr -// CHECK-NEXT: | |--SelectorExpr -// CHECK-NEXT: | | |--Identifier `a` -// CHECK-NEXT: | | `--Identifier `b` -// CHECK-NEXT: | `--ArgumentList -// CHECK-NEXT: | `--StringExpr `"Brett"` -// CHECK-NEXT: | `--StringLiteral `Brett` -// CHECK-NEXT: `--KnotDecl -// CHECK-NEXT: |--KnotProto -// CHECK-NEXT: | `--Identifier `a` -// CHECK-NEXT: `--StitchDecl -// CHECK-NEXT: |--StitchProto -// CHECK-NEXT: | |--Identifier `b` -// CHECK-NEXT: | `--ParamList -// CHECK-NEXT: | `--ParamDecl `name` -// CHECK-NEXT: `--BlockStmt -// CHECK-NEXT: `--ContentStmt -// CHECK-NEXT: `--Content -// CHECK-NEXT: |--StringLiteral `Hello, ` -// CHECK-NEXT: |--InlineLogicExpr -// CHECK-NEXT: | `--Identifier `name` -// CHECK-NEXT: `--StringLiteral `!` - --> a.b("Brett") - -== a -= b(name) -Hello, {name}! diff --git a/testing/regression/syntax/knot-stitches.ink b/testing/regression/syntax/knot-stitches.ink deleted file mode 100644 index 8caa5be..0000000 --- a/testing/regression/syntax/knot-stitches.ink +++ /dev/null @@ -1,31 +0,0 @@ -// RUN: %ink-compiler --stdin --compile-only --dump-ast < %s | FileCheck %s - -// CHECK: File "" -// CHECK-NEXT: `--KnotDecl -// CHECK-NEXT: |--KnotProto -// CHECK-NEXT: | `--Identifier `knot` -// CHECK-NEXT: |--BlockStmt -// CHECK-NEXT: | `--ContentStmt -// CHECK-NEXT: | `--Content -// CHECK-NEXT: | `--StringLiteral `Hello from `knot`!` -// CHECK-NEXT: |--StitchDecl -// CHECK-NEXT: | |--StitchProto -// CHECK-NEXT: | | `--Identifier `a` -// CHECK-NEXT: | `--BlockStmt -// CHECK-NEXT: | `--ContentStmt -// CHECK-NEXT: | `--Content -// CHECK-NEXT: | `--StringLiteral `Hello from `knot.a`!` -// CHECK-NEXT: `--StitchDecl -// CHECK-NEXT: |--StitchProto -// CHECK-NEXT: | `--Identifier `b` -// CHECK-NEXT: `--BlockStmt -// CHECK-NEXT: `--ContentStmt -// CHECK-NEXT: `--Content -// CHECK-NEXT: `--StringLiteral `Hello from `knot.b`!` - -=== knot === -Hello from `knot`! -= a -Hello from `knot.a`! -= b -Hello from `knot.b`! diff --git a/testing/regression/syntax/var-expected-expression.ink b/testing/regression/syntax/var-expected-expression.ink deleted file mode 100644 index e7afc0c..0000000 --- a/testing/regression/syntax/var-expected-expression.ink +++ /dev/null @@ -1 +0,0 @@ -VAR foo =