Skip to content

Commit

Permalink
Execution-Time added
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakob Jungreuthmayer committed Nov 15, 2023
1 parent 708149c commit 50116dd
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 20 deletions.
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@
"type": "string",
"default": ""
},
"vunit-by-hgb.showExecutionTime": {
"description": "Display Execution-Time for every testcase ",
"type": "boolean",
"default": true
},
"vunit-by-hgb.matchProblems": {
"description": "Display Errors and Warnings from VUnit as Problems",
"type": "boolean",
Expand Down
52 changes: 32 additions & 20 deletions src/VUnit/VUnitTestController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { ChildProcess } from "child_process";

//TestBench-Status-Matcher
const cVunitTestEnd : RegExp = /(pass|fail) \(.*\) (.*) \(.*\)/;
const cVunitTimedTestEnd : RegExp = /(pass|fail) \(.*\) (.*) \((\d+(?:\.\d+)?) seconds\)/;
const cVunitTestStart : RegExp = /Starting (.*)/;
const cVunitStopped : RegExp = /Stopped at ([^\s]+) line (\d+)/;

Expand Down Expand Up @@ -320,12 +321,17 @@ export class VUnitTestController {
//Command-Line-Arguments for VUnit
let options = [testCaseWildCard, '--no-color', '--exit-0'];

// read configuration from vscode-settings
const vunitOptions = vscode.workspace
.getConfiguration()
.get('vunit-by-hgb.shellOptions');
if (vunitOptions) {
options.push(vunitOptions as string);
}
}

const showExecutionTime = vscode.workspace
.getConfiguration()
.get('vunit-by-hgb.showExecutionTime') as boolean;

//variable for referencing output from vunit-process to analyse its output
let vunitProcess : any;
Expand Down Expand Up @@ -361,7 +367,7 @@ export class VUnitTestController {
.on('line', (line: string) => {

//check for success/failure of VUnit-TestCase
this.MatchTestCaseStatus(line, node, run, runPyPath);
this.MatchTestCaseStatus(line, node, run, runPyPath, showExecutionTime);

//match VUnit-Errors
if(vscode.workspace.getConfiguration().get('vunit-by-hgb.matchProblems'))
Expand Down Expand Up @@ -434,34 +440,40 @@ export class VUnitTestController {

}

private MatchTestCaseStatus(line : string, node : vscode.TestItem, run : vscode.TestRun, runPyPath : string) : void
private MatchTestCaseStatus(line : string, node : vscode.TestItem, run : vscode.TestRun, runPyPath : string, showExecutionTime : boolean) : void
{

let testCaseMatcher : RegExp = cVunitTestEnd;
if (showExecutionTime)
{
testCaseMatcher = cVunitTimedTestEnd;
}

let result = testCaseMatcher.exec(line);

//check for pass or fail
const result = cVunitTestEnd.exec(line);
if (result) {

const testCaseItemId : string = getTestCaseItemId(runPyPath, result[2]);
const status = result[1];
const name = result[2];
const time = showExecutionTime ? (parseFloat(result[3]) * 1000) : undefined;

const testCaseItemId : string = getTestCaseItemId(runPyPath, name);
//get related test-item
const item = this.findNode(testCaseItemId, node);

if(!item)
{
return;
}

//evaluate result
if(result[1] === 'pass')
if(status === 'pass')
{
//get related test-item
const item = this.findNode(testCaseItemId, node);
if(item)
{
run.passed(item);
}
run.passed(item, time);
}
else
{
//get related test-item
const item = this.findNode(testCaseItemId, node);
if(item)
{
run.failed(item, new vscode.TestMessage(result[2] + " failed!"));
}

run.failed(item, new vscode.TestMessage(result[2] + " failed!"), time);
}
}

Expand Down

0 comments on commit 50116dd

Please sign in to comment.