Skip to content

Commit

Permalink
[Test] CompiledCodeRunner: switch to project-based compiler backend (…
Browse files Browse the repository at this point in the history
…WIP, C# only)
  • Loading branch information
koczkatamas committed Feb 18, 2020
1 parent 71e2548 commit 5937bd8
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 15 deletions.
1 change: 1 addition & 0 deletions langs/csharp.yaml
@@ -1,5 +1,6 @@
name: csharp
extension: cs
mainFilename: Program.cs
casing: # based on https://msdn.microsoft.com/en-us/library/x2dbyw72(v=vs.71).aspx
class: pascal_case
method: pascal_case
Expand Down
1 change: 1 addition & 0 deletions src/Generator/LangFileSchema.ts
Expand Up @@ -51,6 +51,7 @@ export namespace LangFileSchema {
name: string;
extension: string;
main?: string;
mainFilename: string;
classes: { [name: string]: Class };
operators: { [name: string]: Operator };
casing: CasingOptions;
Expand Down
44 changes: 29 additions & 15 deletions test/src/testSuites/CompiledCodeRunner.ts
Expand Up @@ -4,8 +4,9 @@ import { PackageManager } from '@one/StdLib/PackageManager';
import { PackagesFolderSource } from '@one/StdLib/PackagesFolderSource';

//const filter: RegExp = /cpp:(ArrayTest|HelloWorld|HelloWorldRaw)/;
const filter: RegExp = /StrLenInferIssue:cpp/;
const todoFilter: RegExp = /BigInteger:cpp/;
//const filter: RegExp = /:(cpp|csharp|java|javascript|python|ruby)$/;
const filter: RegExp = /:csharp$/;
const todoFilter: RegExp = /(BigInteger:cpp|JsonParseTest:cpp|:perl)$/;

const backendUrl = "http://127.0.0.1:11111";
const expectedResults: { [prgName: string]: string } = getYamlTestSuite("CompiledCodeRunner");
Expand All @@ -27,46 +28,59 @@ for (const prg of prgs) {
it(lang.name, async function() {
this.timeout(5000);
const sourceCode = readFile(`test/artifacts/CompilationTest/${prg}/results/${prg}.${lang.extension}`);
const nativeImpl = pacMan.getLangNativeImpls(lang.name);
const packageSources = nativeImpl.map(x => ({ packageName: `${x.pkgVendor}-${x.pkgName}-v${x.pkgVersion}`, fileName: x.fileName, code: x.code }));
const request: CompileRequest = { lang: lang.name, code: sourceCode, packageSources, className: mainClass, methodName: mainMethod };
console.log(request.code.split('\n\n')[0], request.packageSources.map(x => `${x.packageName}:${x.fileName}`));

const files = { [lang.mainFilename]: sourceCode };
for (const f of pacMan.getLangNativeImpls(lang.name))
files[`${f.pkgVendor}-${f.pkgName}-v${f.pkgVersion}/${f.fileName}`] = f.code;

const request: CompileRequest = { lang: lang.name, name: prg, files, mode: "native" };
//console.log(request.code.split('\n\n')[0], request.packageSources.map(x => `${x.packageName}:${x.fileName}`));
let res = await jsonRequest<CompileResult>(`${backendUrl}/compile?useCache`, request);

if (res.exceptionText && res.fromCache)

//console.log(JSON.stringify(res, null, 4));
if (!res.success || res.error)
throw new Error(`[${res.tmpDir||res.cacheId}]: ${res.error}`);

//console.log(JSON.stringify(res));
if (!res.success && res.fromCache)
res = await jsonRequest<CompileResult>(`${backendUrl}/compile`, request);

if (res.exceptionText)
throw new Error(`Compilation failed (${res.tmpDir||res.cacheId}): ${res.exceptionText}\nOutput: ${res.result}`);
if (!res.success)
throw new Error(`[${res.tmpDir||res.cacheId}]: ${res.error}`);

const expected = expectedResults[`${prg}-${lang.name}`] || expectedResults[prg];
if (typeof expected === "undefined") {
if (lang.name === "javascript")
console.error(`Expected result was not set for program "${prg}", current result is ${JSON.stringify(res.result)}`);
console.error(`Expected result was not set for program "${prg}", current result is ${JSON.stringify(res.run.stdout)}`);
} else
assert.equal(res.result, expected, `Result was incorrect (${res.tmpDir||res.cacheId})`);
assert.equal(res.run.stdout, expected, `Result was incorrect (${res.tmpDir||res.cacheId})`);
})
}
})
}

interface CompileRequest {
lang?: string;
code: string;
code?: string;
name: string;
mode?: "auto"|"jsonRepl"|"server"|"native";
packageSources?: {
packageName: string;
fileName: string;
code: string;
}[];
files: { [name: string]: string };
className?: string;
methodName?: string;
}

interface CompileResult {
result?: string;
elapsedMs?: number;
exceptionText?: string;
fromCache: boolean;
cacheId: string;
tmpDir: string;
error: string;
success: boolean;
compilation: { stdout: string; stderr: string; exitCode: number; success: boolean };
run: { stdout: string; stderr: string; exitCode: number; success: boolean };
}

0 comments on commit 5937bd8

Please sign in to comment.