Skip to content

Commit

Permalink
Fix for issue #67, right click on .env file and choosing build (#68)
Browse files Browse the repository at this point in the history
VectorCAST environment, deletes an existing environment
@Zbigor can you add a quick test for this.

---------

Co-authored-by: Igor Martinovic <igor.martinovic@vector.com>
  • Loading branch information
johnpaliotta and Zbigor authored Feb 14, 2024
1 parent fcb9dcb commit 31c703b
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 4 deletions.
19 changes: 16 additions & 3 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ import {

import {
executeClicastCommand,
getEnviroNameFromFile,
openTestScript,
vcastCommandtoUse,
} from "./vcastUtilities";
Expand All @@ -82,6 +83,7 @@ import {
import { updateExploreDecorations } from "./fileDecorator";

const spawn = require("child_process").spawn;
import fs = require("fs");
const path = require("path");
let messagePane: vscode.OutputChannel = vscode.window.createOutputChannel(
"VectorCAST Test Explorer"
Expand Down Expand Up @@ -441,9 +443,20 @@ function configureExtension(context: vscode.ExtensionContext) {
// arg is the URI of the .env file that was clicked
if (arg) {
const envFilepath = arg.fsPath;
const directory = path.dirname(envFilepath);
const enviroName = path.basename(envFilepath);
buildEnvironmentFromScript (directory, enviroName.split (".")[0]);
const buildDirectory = path.dirname(envFilepath);
const enviroFilename = path.basename(envFilepath);
const enviroName = getEnviroNameFromFile (envFilepath);
if (enviroName) {
if (!fs.existsSync (path.join (buildDirectory, enviroName))) {
buildEnvironmentFromScript (buildDirectory, enviroFilename.split(".")[0]);
}
else {
vscode.window.showErrorMessage (`Environment: ${enviroName} already exists`);
}
}
else {
vscode.window.showErrorMessage (`Unable to determine environment name from file: ${envFilepath}`);
}
}
});
context.subscriptions.push(buildEnviroVCASTCommand);
Expand Down
23 changes: 22 additions & 1 deletion src/vcastUtilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -504,4 +504,25 @@ export function executeClicastWithProgress (
}
);
});
}
}


export function getEnviroNameFromFile (filePath:string):string|undefined {
// This funciton will extract the enviro name from
// the ENVIRO.NAME: <name> line of the provided file

let enviroName: string|undefined = undefined;

// load the contents of filePath, find the ENVIRO.NAME: line
// and return the value after the colon
const fileContents = fs.readFileSync(filePath).toString();
const lines = fileContents.split("\n");
for (let line of lines) {
if (line.startsWith("ENVIRO.NAME:")) {
enviroName = line.split(":")[1].trim();
break;
}
}

return enviroName;
}
37 changes: 37 additions & 0 deletions tests/internal/e2e/test/specs/vcast_testgen_bugs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,43 @@ import {
// clearing all notifications
await (await $(".codicon-notifications-clear-all")).click();
});

it("should not delete existing VectorCAST environment when building from .env", async () => {
await updateTestID();
const workbench = await browser.getWorkbench();
const activityBar = workbench.getActivityBar();
await (await bottomBar.openOutputView()).clearText()

const explorerView = await activityBar.getViewControl("Explorer");
await explorerView?.openView();

const workspaceFolderSection = await expandWorkspaceFolderSectionInExplorer(
"vcastTutorial",
);

await workspaceFolderSection.expand()
const unitTestsFolder = await workspaceFolderSection.findItem("unitTests")
await unitTestsFolder.select()
const vceFile = await workspaceFolderSection.findItem("QUOTES_EXAMPLE.env");
const vceMenu = await vceFile.openContextMenu()
console.log("Executing env build for an existing environment");
await vceMenu.select("Build VectorCAST Environment")

// making sure notification is shown

const notifications = await workbench.getNotifications()
const expectedMessage = "Environment: QUOTES_EXAMPLE already exists"
let message = "";
for (const notif of notifications) {
message = await notif.getMessage()
if (message === expectedMessage)
break;
}
expect(message).toBe(expectedMessage)
console.log("Making sure existing environment folder is not deleted");
const envFolder = await workspaceFolderSection.findItem("QUOTES_EXAMPLE");
expect(envFolder).not.toBe(undefined)
});

it("should correctly generate all BASIS PATH tests for function", async () => {
await updateTestID();
Expand Down

0 comments on commit 31c703b

Please sign in to comment.