From 97e282d3caa6c4cdda9fbf40f646fbfd9f5bb2cd Mon Sep 17 00:00:00 2001 From: undefined Date: Mon, 20 Dec 2021 13:29:25 +0800 Subject: [PATCH] judge: testlib builtin checkers --- packages/hydrojudge/package.json | 2 +- packages/utils/lib/cases.ts | 9 +++++++-- packages/utils/lib/utils.ts | 4 ++-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/packages/hydrojudge/package.json b/packages/hydrojudge/package.json index 0111003d6..687a8b8fb 100644 --- a/packages/hydrojudge/package.json +++ b/packages/hydrojudge/package.json @@ -1,7 +1,7 @@ { "name": "@hydrooj/hydrojudge", "bin": "bin/hydrojudge.js", - "version": "2.12.11", + "version": "2.12.12", "main": "package.json", "author": "undefined ", "repository": "https://github.com/hydro-dev/Hydro.git", diff --git a/packages/utils/lib/cases.ts b/packages/utils/lib/cases.ts index f6708ec5f..e357b1b3a 100644 --- a/packages/utils/lib/cases.ts +++ b/packages/utils/lib/cases.ts @@ -1,4 +1,4 @@ -import { parseMemoryMB, parseTimeMS } from './utils'; +import { findFileSync, parseMemoryMB, parseTimeMS } from './utils'; // eslint-disable-next-line @typescript-eslint/no-unused-vars export default async function readYamlCases(cfg: Record = {}, checkFile = (s: string, errMsg: string) => s) { @@ -10,7 +10,12 @@ export default async function readYamlCases(cfg: Record = {}, check user_extra_files: [], }; config.checker_type = cfg.checker_type || 'default'; - if (cfg.checker) config.checker = checkFile(cfg.checker, 'Cannot find checker {0}.'); + if (cfg.checker) { + if (!cfg.checker.includes('.')) { + config.checker = findFileSync(`@hydrojudge/vendor/testlib/checkers/${cfg.checker}.cpp`, false); + } + if (!config.checker) config.checker = checkFile(cfg.checker, 'Cannot find checker {0}.'); + } if (cfg.interactor) config.interactor = checkFile(cfg.interactor, 'Cannot find interactor {0}.'); if (cfg.judge_extra_files) { if (typeof cfg.judge_extra_files === 'string') { diff --git a/packages/utils/lib/utils.ts b/packages/utils/lib/utils.ts index b68728bc0..5933486e1 100644 --- a/packages/utils/lib/utils.ts +++ b/packages/utils/lib/utils.ts @@ -344,7 +344,7 @@ export async function findFile(pathname: string, doThrow = true) { return null; } -export function findFileSync(pathname: string, doThrow = true) { +export function findFileSync(pathname: string, doThrow: boolean | Error = true) { if (fs.pathExistsSync(path.resolve(pathname))) return path.resolve(pathname); if (fs.pathExistsSync(path.resolve(process.cwd(), pathname))) return path.resolve(process.cwd(), pathname); if (fs.pathExistsSync(path.resolve(__dirname, pathname))) return path.resolve(__dirname, pathname); @@ -364,7 +364,7 @@ export function findFileSync(pathname: string, doThrow = true) { if (fs.pathExistsSync(path.resolve(os.homedir(), pathname))) return path.resolve(os.homedir(), pathname); if (fs.pathExistsSync(path.resolve(os.homedir(), '.hydro', pathname))) return path.resolve(os.homedir(), '.hydro', pathname); if (fs.pathExistsSync(path.resolve(os.homedir(), '.config', 'hydro', pathname))) return path.resolve(os.homedir(), '.config', 'hydro', pathname); - if (doThrow) throw new Error(`File ${pathname} not found`); + if (doThrow) throw (typeof doThrow !== 'boolean' ? doThrow : new Error(`File ${pathname} not found`)); return null; }