Skip to content

Commit

Permalink
codegen: Fix running tests
Browse files Browse the repository at this point in the history
  • Loading branch information
delasy committed Feb 3, 2025
1 parent f6fb102 commit 29c6b04
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
4 changes: 2 additions & 2 deletions packages/codegen/scripts/update-codegen-tests
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ main {

loop i := 0; i < files.len; i++ {
name := files[i].slice(0, -4)
print("updating:", name)
print("updating:", name, to: "stderr")

filePath := TESTS_DIR + "/" + name + ".txt"
fileSections := retrieveFileSections(filePath)
Expand Down Expand Up @@ -57,5 +57,5 @@ main {
fs_writeFileSync(filePath, newContent.toBuffer())
}

print("run successful")
print("run successful", to: "stderr")
}
22 changes: 13 additions & 9 deletions packages/codegen/test/codegen-test
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@
import * as Analyzer from "the/analyzer"
import * as Parser from "the/parser"
import Codegen from "../src/codegen"
import applyRegexTemplate, matchRegex, retrieveFileSections from "./utils"
import
applyRegexTemplate,
matchRegex,
retrieveFileSections
from "./utils"

fn TEST_EXPECT_EQ (test: str, a: str, b: str) {
fn Codegen_EXPECT_EQ (test: str, a: str, b: str) {
EXPECT_EQ(test + os_EOL + a, test + os_EOL + b)
}

fn TEST_EXPECT_REGEX (test: str, a: str, b: str) {
fn Codegen_EXPECT_REGEX (test: str, a: str, b: str) {
EXPECT_EQ(test + os_EOL + a, test + os_EOL + applyRegexTemplate(b, a))
}

Expand Down Expand Up @@ -44,7 +48,7 @@ export fn TEST_Codegen () {
fileSections := retrieveFileSections("./test/codegen/" + name + ".txt")
executablePath := "./build/" + name + ".out"
codePath := "./build/" + name + ".c"
print(name)
print(name, to: "stderr")

mut analyzer := Analyzer.Analyzer{}

Expand All @@ -61,7 +65,7 @@ export fn TEST_Codegen () {
file.analyze(ref file.f.program.body)

if !analyzer.errors.empty {
TEST_EXPECT_EQ(name, analyzer.errors.join(os_EOL), "")
Codegen_EXPECT_EQ(name, analyzer.errors.join(os_EOL), "")
continue
}

Expand All @@ -77,14 +81,14 @@ export fn TEST_Codegen () {
}

if !generationError.empty {
TEST_EXPECT_EQ(name, generationError, "")
Codegen_EXPECT_EQ(name, generationError, "")
continue
}

generatedCode := generator.stringify()

if fileSections.code != generatedCode {
TEST_EXPECT_EQ(name, fileSections.code, generatedCode)
Codegen_EXPECT_EQ(name, fileSections.code, generatedCode)
continue
}

Expand All @@ -100,7 +104,7 @@ export fn TEST_Codegen () {
fs_rmSync(codePath)

if !errorMessage.empty {
TEST_EXPECT_EQ(name, errorMessage, "")
Codegen_EXPECT_EQ(name, errorMessage, "")
continue
}

Expand All @@ -122,7 +126,7 @@ export fn TEST_Codegen () {
fs_rmSync(executablePath)

if actualOutput != fileSections.output {
TEST_EXPECT_REGEX(name, actualOutput, fileSections.output)
Codegen_EXPECT_REGEX(name, actualOutput, fileSections.output)
}
}
}

0 comments on commit 29c6b04

Please sign in to comment.