对齐c层与cj层错误码,修改测试以配合c层更新

This commit is contained in:
2026-03-25 14:52:36 +08:00
parent c16de88385
commit c3109ddad4
2 changed files with 20 additions and 16 deletions

View File

@ -1,21 +1,23 @@
package luarunner
import std.unittest.*
import std.fs.*
import std.unittest.* // cjlint-ignore G.PKG.01
import std.fs.* // cjlint-ignore G.PKG.01
let scriptsDir = "./test/scripts"
let generatedScriptsDir = "./test/generated_scripts"
// cjlint-ignore G.NAM.05
let SCRIPTS_DIR = "./test/scripts"
// cjlint-ignore G.NAM.05
let GENERATED_SCRIPTS_DIR = "./test/generated_scripts"
func scriptPath(name: String): String {
scriptsDir + "/" + name
SCRIPTS_DIR + "/" + name
}
func generatedScriptPath(name: String): String {
generatedScriptsDir + "/" + name
GENERATED_SCRIPTS_DIR + "/" + name
}
func ensureGeneratedScriptsDir(): Unit {
let dir = Path(generatedScriptsDir)
let dir = Path(GENERATED_SCRIPTS_DIR)
if (!exists(dir)) {
Directory.create(dir, recursive: true)
}
@ -53,7 +55,7 @@ func testRunScriptSyntaxError(): Unit {
runner.runScript(path, "")
fail("Should throw syntax error")
} catch (e: LuaError) {
@Expect(e.code, 5010)
@Expect(e.code, 5003)
}
}
@ -203,16 +205,16 @@ func testLoadLibOverflow(): Unit {
@Test
func testPackagePathConfig(): Unit {
let runner = LuaRunner(pkgpath: scriptsDir + "/pkgmods/?.lua")
let runner = LuaRunner(pkgpath: SCRIPTS_DIR + "/pkgmods/?.lua")
let res = runner.runScript(scriptPath("pkgpath_require_mylib.lua"), "")
@Expect(res, "LoadedViaPkgPath")
@Expect(res, SCRIPTS_DIR + "/pkgmods/mylib.lua")
}
@Test
func testPackagePathInitLuaPattern(): Unit {
let runner = LuaRunner(pkgpath: scriptsDir + "/pkgmods_init/?/init.lua")
let runner = LuaRunner(pkgpath: SCRIPTS_DIR + "/pkgmods_init/?/init.lua")
let res = runner.runScript(scriptPath("pkgpath_require_nested.lua"), "")
@Expect(res, "LoadedViaInit")
@Expect(res, SCRIPTS_DIR + "/pkgmods_init/nestedpkg/init.lua")
}
// ====================
@ -259,7 +261,9 @@ func testRedirectIoRead(): Unit {
func testErrorCodesMapping(): Unit {
@Expect(LuaError.getErrorMessage(5001), "JSON file load failed")
@Expect(LuaError.getErrorMessage(5002), "Memory allocation failed")
@Expect(LuaError.getErrorMessage(5003), "File load error (path, permission, or compile-time syntax issue)")
@Expect(LuaError.getErrorMessage(5010), "Script internal error, check result for details")
@Expect(LuaError.getErrorMessage(5022), "No callable chunk found")
@Expect(LuaError.getErrorMessage(9999), "Unknown error")
}