judge: testlib builtin checkers

This commit is contained in:
undefined committed 2021-12-20 13:29:25 +08:00
1 parent 79aca189d1
commit 97e282d3ca
3 files changed
+10 -5

No files matched your search

+7 -2
View File
@@ -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<string, any> = {}, checkFile = (s: string, errMsg: string) => s) {
@@ -10,7 +10,12 @@ export default async function readYamlCases(cfg: Record<string, any> = {}, 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') {
+2 -2
View File
@@ -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;
}