diff --git a/challenge.yaml b/challenge.yaml index fe3825d..4f1718e 100644 --- a/challenge.yaml +++ b/challenge.yaml @@ -47,23 +47,22 @@ configuration: # validate: # Here is a task that compiles the code - - name: "Compile the code" - cmd: echo Compiling... + - name: "Compiling code" + cmd: echo Compiling code... # The command to run the verification, this can be running tests # And it needs to produce a file called with a junit test format - - name: "Run the tests" - cmd: | - echo Running some testing command... - echo '<?xml version="1.0" encoding="UTF-8"?> - <!-- This is a basic JUnit-style XML example to highlight the basis structure. --> + - task: createFile + file: output.xml + contents: | + <?xml version="1.0" encoding="UTF-8" ?> <testsuites time="15.682687"> <testsuite name="Tests.DevMatchTestCases" time="6.605871"> <testcase name="TEST_1" classname="Tests.simpleSum" time="2.111" /> <testcase name="TEST_2" classname="Tests.simpleSum" time="1.051" /> <testcase name="TEST_3" classname="Tests.simpleSum" time="3.441" /> </testsuite> - </testsuites>' > output.xml + </testsuites> # The location and filename of the results results: output.xml diff --git a/validator/src/execute.ts b/validator/src/execute.ts index dae2992..79c94c1 100644 --- a/validator/src/execute.ts +++ b/validator/src/execute.ts @@ -11,7 +11,10 @@ export function execute(command, printOutput = false, cwd = "") { } const [cmd, ...args] = command.split(" "); - const child = spawn(cmd, args, { cwd: cwd }); + const child = spawn(cmd, args, { + cwd: cwd, + shell: true, + }); let stdout = ""; let stderr = ""; diff --git a/validator/src/index.ts b/validator/src/index.ts index 5f6a433..63424c4 100644 --- a/validator/src/index.ts +++ b/validator/src/index.ts @@ -56,19 +56,19 @@ program ); let problemConfiguration = await problemCode.getProblemConfiguration(); console.table([ - [ "inputType", problemConfiguration.inputType ], - [ "desktopEnabled", problemConfiguration.desktopEnabled ], - [ "ideEnabled", problemConfiguration.ideEnabled ], - [ "vsliteEnabled", problemConfiguration.vsliteEnabled ], - [ "agentPool", problemConfiguration.agentPool ], - [ "agentImage", problemConfiguration.agentImage ] + ["inputType", problemConfiguration.inputType], + ["desktopEnabled", problemConfiguration.desktopEnabled], + ["ideEnabled", problemConfiguration.ideEnabled], + ["vsliteEnabled", problemConfiguration.vsliteEnabled], + ["agentPool", problemConfiguration.agentPool], + ["agentImage", problemConfiguration.agentImage] ]) const worskpaceFolder = path.join(process.cwd(), "..", "workspace"); console.log("Current working directory", worskpaceFolder) const validationSteps = parsedYaml.validate; - let buildTestResultFileNames : string[] = []; + let buildTestResultFileNames: string[] = []; console.log(` `) console.log(` _____ _______ _____ _______ `) @@ -83,44 +83,61 @@ program process.env.WAIT_ON_TIMEOUT = '60000'; try { - for (const validationStep of validationSteps) - { - // Start from the path to the workspace or if the Yaml specificies a working directory, then use that - // Whatever is specified, will be after the parent of the workspace directory. - const workingDirectory = validationStep.workingDirectory ? - path.normalize(path.join(process.cwd(), "..", validationStep.workingDirectory)) : worskpaceFolder; - - console.log(`/=======================================================`); - console.log(`| name : ${validationStep.name}`); - console.log(`| workingDirectory: ${workingDirectory}`); - console.log(`| cmd : ${validationStep.cmd}`); - console.log(`\\=======================================================`); - - // - // Run the command - // - try { - - await execute(validationStep.cmd, true, workingDirectory); - } catch (innerError) { - console.error("Command failed. But continuing still..."); - } - - // - // Collect the result if instructed - // - if (validationStep.results !== undefined) - { - const resultPath = path.join(workingDirectory, validationStep.results); - buildTestResultFileNames.push(resultPath) - } - - console.log(``); + for (const validationStep of validationSteps) { + // Start from the path to the workspace or if the Yaml specificies a working directory, then use that + // Whatever is specified, will be after the parent of the workspace directory. + const workingDirectory = validationStep.workingDirectory ? + path.normalize(path.join(process.cwd(), "..", validationStep.workingDirectory)) : worskpaceFolder; + + if (validationStep?.task === "createFile") { + const fileFullName = path.join(workingDirectory, validationStep.file); + + console.log(`/=======================================================`); + console.log(`| task : ${validationStep.task}`); + console.log(`| workingDirectory: ${workingDirectory}`); + console.log(`| file name : ${fileFullName}`); + console.log(`\\=======================================================`); + + // create a file to disk + fs.writeFileSync(fileFullName, validationStep.contents); + console.log(`Created file: ${fileFullName}`); + + } else { + console.log(`/=======================================================`); + console.log(`| name : ${validationStep.name}`); + console.log(`| workingDirectory: ${workingDirectory}`); + console.log(`| cmd : ${validationStep.cmd}`); + console.log(`\\=======================================================`); + + // + // Run the command + // + try { + //await execute(validationStep.cmd, true, workingDirectory); + await execute(validationStep.cmd, true); + + } catch (innerError) { + console.error("Command failed. But continuing still..."); + + } } + + + // + // Collect the result if instructed + // + if (validationStep.results !== undefined) { + const resultPath = path.join(workingDirectory, validationStep.results); + buildTestResultFileNames.push(resultPath) + } + + console.log(``); + + } } catch (e) { - console.error("Caught exception while executing."); - console.error(e) + console.error("Caught exception while executing."); + console.error(e) } console.log(` ______ _ _ _____ `) @@ -144,46 +161,46 @@ program // const extractTestCasesFromJunit = async (fileName) => { - const resultsContents = await getFileContents(fileName); - if (resultsContents === false) { - console.log( - `The test run did not produce an output at: ${fileName}` - ); - return []; - } + const resultsContents = await getFileContents(fileName); + if (resultsContents === false) { + console.log( + `The test run did not produce an output at: ${fileName}` + ); + return []; + } - // - // Read build test cases: Parse the JUnit test result file - // - console.log(`Found the output file: ${fileName}`); - let buildParsedJunitContents : any = null; - try { - buildParsedJunitContents = await parseJunitXml(resultsContents); - } catch (e) { - console.log(`Unable to parse output: ${fileName}`); - throw e; - return; - } - if (!buildParsedJunitContents) { - console.log(`Unable to parse output: ${fileName}`); - throw Error(); - } + // + // Read build test cases: Parse the JUnit test result file + // + console.log(`Found the output file: ${fileName}`); + let buildParsedJunitContents: any = null; + try { + buildParsedJunitContents = await parseJunitXml(resultsContents); + } catch (e) { + console.log(`Unable to parse output: ${fileName}`); + throw e; + return; + } + if (!buildParsedJunitContents) { + console.log(`Unable to parse output: ${fileName}`); + throw Error(); + } - const buildTestSuites = (buildParsedJunitContents as TestSuites).testsuite || []; - - // Flatten the tree and just extract all the test cases from the build - let buildTestCases : any [] = []; - for (const suites of buildTestSuites) { - if (suites?.testcase === undefined) { - continue; - } - for (const testCase of suites?.testcase) { - buildTestCases.push(testCase); - console.log(`Found test case from the build : '${testCase.name}'`) - } + const buildTestSuites = (buildParsedJunitContents as TestSuites).testsuite || []; + + // Flatten the tree and just extract all the test cases from the build + let buildTestCases: any[] = []; + for (const suites of buildTestSuites) { + if (suites?.testcase === undefined) { + continue; + } + for (const testCase of suites?.testcase) { + buildTestCases.push(testCase); + console.log(`Found test case from the build : '${testCase.name}'`) } + } - return buildTestCases; + return buildTestCases; } console.log(``); @@ -191,14 +208,14 @@ program // NOW we need to merge the result files... and // just get the various test cases from as many // test files we have in buildTestResultFileNames - let buildTestCases : any [] = []; + let buildTestCases: any[] = []; for (const resultFile of buildTestResultFileNames) { - console.log(`Result file : ${resultFile}`); - try { - buildTestCases = buildTestCases.concat(await extractTestCasesFromJunit(resultFile)); - } catch (e) { - console.log(`Unable to parse test case from ${resultFile}: ${e}.`); - } + console.log(`Result file : ${resultFile}`); + try { + buildTestCases = buildTestCases.concat(await extractTestCasesFromJunit(resultFile)); + } catch (e) { + console.log(`Unable to parse test case from ${resultFile}: ${e}.`); + } } // Read the test cases from the YAML file, and start the comparison with the @@ -233,18 +250,18 @@ program // Find this result on build test cases const foundBuildTestCase = buildTestCases?.find((c) => c?.name?.trim() === yamlTestCase.id); - if (foundBuildTestCase) { - const failure = foundBuildTestCase.failure !== undefined; - console.log(`Found mapping ${yamlTestCase.id}. Failure = ${failure}`); - - if (!failure) { - yamlTestCase.actualPoints = yamlTestCase.maxPoints; - yamlTestCase.solved = true; - } + if (foundBuildTestCase) { + const failure = foundBuildTestCase.failure !== undefined; + console.log(`Found mapping ${yamlTestCase.id}. Failure = ${failure}`); - } else { - console.log(`Test case mapping ${yamlTestCase.id} *NOT* found. Build did not produce this test case.`); + if (!failure) { + yamlTestCase.actualPoints = yamlTestCase.maxPoints; + yamlTestCase.solved = true; } + + } else { + console.log(`Test case mapping ${yamlTestCase.id} *NOT* found. Build did not produce this test case.`); + } } //