Skip to content

Commit

Permalink
Refactor tests runner to use dynamic input and output binaries
Browse files Browse the repository at this point in the history
  • Loading branch information
delasy committed Feb 11, 2025
1 parent 56dbbcd commit 64c3118
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/main
Original file line number Diff line number Diff line change
Expand Up @@ -368,15 +368,17 @@ main {
}
} elif action == "test" {
mut tester := Tester_init(actionArgument, excludePaths)
qs += "&m=__the__main__"
qs += "&m=" + tester.inputFile
command(compiler, "compile", tester.outputDir, tester.outputPath, platform, arch, qs)

mut cmd := tester.outputPath
mut cmd := "cd \"" + tester.outputDir + "\" && ./" + tester.outputBinary

if filter != nil {
cmd += " --filter=\"" + filter + "\""
}

cmd += " 1>&2"

stdout := process_runSync(cmd)
print(stdout.str(), terminator: "")

Expand Down
8 changes: 6 additions & 2 deletions src/tester
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ export obj Tester {
cwd: str
targetPath: str
exclude: str[]
mut inputFile: str
mut inputPath: str
mut outputBinary: str
mut outputDir: str
mut outputPath: str

Expand All @@ -24,7 +26,8 @@ export obj Tester {
}

self.outputDir = path_tempDirectory()
self.inputPath = self.outputDir + path_SEP + "__the__main__"
self.inputFile = "__the_tests_main__"
self.inputPath = self.outputDir + path_SEP + self.inputFile
allFiles := fs_isDirectorySync(realFullPath) ? scandirDeepSync(realFullPath) : [realFullPath]
files := excludePaths(collectUsedPaths(allFiles), self.exclude)
mut mainFileImports := "import Tests from \"the/testing\"" + os_EOL
Expand Down Expand Up @@ -62,7 +65,8 @@ export obj Tester {
mainFile += "}" + os_EOL

mainContent := mainFileImports + os_EOL + mainFile
self.outputPath = self.outputDir + path_SEP + "a." + (os_NAME == "Windows" ? "exe" : "out")
self.outputBinary = "a." + (os_NAME == "Windows" ? "exe" : "out")
self.outputPath = self.outputDir + path_SEP + self.outputBinary
fs_writeFileSync(self.inputPath, mainContent.toBuffer())

packageYamlPath := self.cwd + path_SEP + "package.yml"
Expand Down

0 comments on commit 64c3118

Please sign in to comment.