Skip to content

Commit

Permalink
wip: merge with stable main
Browse files Browse the repository at this point in the history
  • Loading branch information
Zbigor committed May 15, 2024
1 parent 12a2e3a commit 1f620d5
Show file tree
Hide file tree
Showing 14 changed files with 243 additions and 190 deletions.
1 change: 1 addition & 0 deletions .github/workflows/run-tests-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- main
- gha_integration
- gh_actions_for_tests # TODO
pull_request:
release:
Expand Down
115 changes: 50 additions & 65 deletions python/vTestInterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,10 @@ def setupArgs():
help="Test Explorer Mode",
)

kindChoices = ["vcast", "codebased"]
parser.add_argument(
"--kind",
choices=kindChoices,
required=True,
help="Environment Kind",
)

parser.add_argument("--clicast", required=True, help="Path to clicast to use")
parser.add_argument("--clicast", help="Path to clicast to use")

parser.add_argument(
"--path",
required=True,
help="Path to Environment Directory",
)

Expand Down Expand Up @@ -152,6 +143,7 @@ def generateTestInfo(test):
"""
testInfo = dict()
testInfo["testName"] = test.name

testInfo["notes"] = test.notes
# stored as 0 or 1
testInfo["compoundOnly"] = test.for_compound_only
Expand Down Expand Up @@ -245,8 +237,11 @@ def getTestDataVCAST(enviroPath):
if test.is_csv_map:
pass
else:
# A coded test file might have been renamed or deleted,
# in which case generateTestInfo() will return None
testInfo = generateTestInfo(test)
functionNode["tests"].append(testInfo)
if testInfo:
functionNode["tests"].append(testInfo)

unitNode["functions"].append(functionNode)

Expand Down Expand Up @@ -285,33 +280,32 @@ def printCoverageListing(enviroPath):
capi.close()


def getUnitData(enviroPath, kind):
def getUnitData(enviroPath):
"""
This function will return info about the units in an environment
"""
unitList = list()
if kind == "vcast":
try:
# this can throw an error of the coverDB is too old!
capi = CoverApi(enviroPath)
except Exception as err:
print(err)
raise UsageError()
try:
# this can throw an error of the coverDB is too old!
capi = CoverApi(enviroPath)
except Exception as err:
print(err)
raise UsageError()

# For testing/debugging
# printCoverageListing (enviroPath)

sourceObjects = capi.SourceFile.all()
for sourceObject in sourceObjects:
sourcePath = sourceObject.display_path
covered, uncovered, checksum = getCoverageData(sourceObject)
unitInfo = dict()
unitInfo["path"] = sourcePath
unitInfo["functionList"] = getFunctionData(sourceObject)
unitInfo["cmcChecksum"] = checksum
unitInfo["covered"] = covered
unitInfo["uncovered"] = uncovered
unitList.append(unitInfo)
# For testing/debugging
# printCoverageListing (enviroPath)

sourceObjects = capi.SourceFile.all()
for sourceObject in sourceObjects:
sourcePath = sourceObject.display_path
covered, uncovered, checksum = getCoverageData(sourceObject)
unitInfo = dict()
unitInfo["path"] = sourcePath
unitInfo["functionList"] = getFunctionData(sourceObject)
unitInfo["cmcChecksum"] = checksum
unitInfo["covered"] = covered
unitInfo["uncovered"] = uncovered
unitList.append(unitInfo)

capi.close()
return unitList
Expand Down Expand Up @@ -421,13 +415,14 @@ def getResults(enviroPath, testIDObject):

def getCodeBasedTestNames(filePath):
"""
testID looks like: EXAMPLE.CBT.mySuite.byPointer
So we just need to split the mySuite.byPointer part
off and pass that to the driver.
This function will use the same file parser that the vcast
uses to extract the test names from the CBT file. It will return
a list of dictionaries that contain the test name, the file path
and the starting line for he test
"""

with cd(enviroPath):
nameOfDriver = os.path.basename(enviroPath).lower()
returnObject = None
if os.path.isfile(filePath):

cbtParser = Parser()
with open(filePath, "r") as cbtFile:
Expand Down Expand Up @@ -498,20 +493,14 @@ def processCommand(mode, clicast, pathToUse, testString="", options="") -> dict:
it will return a dictionary with the results of the command
"""

argParser = setupArgs()
args, restOfArgs = argParser.parse_known_args()
returnCode = 0
returnObject = None

# no need to pass this all around
validateClicastCommand(clicast, mode)
clicastInterface.globalClicastCommand = clicast

# enviroPath is the full path to the vce file
enviroPath = os.path.abspath(args.path)

# See the comment in: executeVPythonScript()
print("ACTUAL-DATA")

if args.mode == "getEnviroData":
if mode == "getEnviroData":
topLevel = dict()
# it is important that getTetDataVCAST() is called first since it sets up
# the global list of tesable functoions that getUnitData() needs
Expand Down Expand Up @@ -551,25 +540,20 @@ def processCommand(mode, clicast, pathToUse, testString="", options="") -> dict:
jsonOptions = processOptions(options)
clicastInterface.rebuildEnvironment(pathToUse, jsonOptions)

json.dump(topLevel, sys.stdout, indent=4)
# only used for executeTest currently
return returnCode, returnObject

elif args.mode == "getCoverageData":
# need to call this function to set the global list of testable functions
getTestDataVCAST(enviroPath)
unitData = getUnitData(enviroPath, args.kind)
json.dump(unitData, sys.stdout, indent=4)

elif args.mode == "executeTest":
if args.kind == "vcast":
testIDObject = testID(enviroPath, args.test)
executeVCtest(enviroPath, testIDObject)
else:
executeCodeBasedTest(enviroPath, args.test)
def main():

argParser = setupArgs()
args, restOfArgs = argParser.parse_known_args()

elif args.mode == "results":
if args.kind == "vcast":
testIDObject = testID(enviroPath, args.test)
getResults(enviroPath, testIDObject)
# path is the path to the enviro directory or cbt file
pathToUse = os.path.abspath(args.path)

# See the comment in: executeVPythonScript()
print("ACTUAL-DATA")

returnCode, returnObject = processCommand(
args.mode, args.clicast, pathToUse, args.test, args.options
Expand All @@ -582,8 +566,8 @@ def processCommand(mode, clicast, pathToUse, testString="", options="") -> dict:
returnText = json.dumps(returnObject, indent=4)
print(returnText)

# Zero exit code
return 0
# only used for executeTest currently
return returnCode


if __name__ == "__main__":
Expand All @@ -604,3 +588,4 @@ def processCommand(mode, clicast, pathToUse, testString="", options="") -> dict:
returnCode = 1

sys.exit(returnCode)

4 changes: 0 additions & 4 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ export function activateLanguageServerClient(context: ExtensionContext) {
// Options to control the language client
let clientOptions: LanguageClientOptions = {
documentSelector: [{ scheme: "file", pattern: "**/*.tst" }],
synchronize: {
// Notify the server about file changes to '.clientrc files contained in the workspace
fileEvents: workspace.createFileSystemWatcher("**/.clientrc"),
},
};

// Create the language client and start the client.
Expand Down
12 changes: 11 additions & 1 deletion src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,5 +143,15 @@ export function getUnitTestLocationForPath(dirpath: string): string {
// By default the unit tests get created in the "unitTests" directory
// but this can be controlled with an option

let settings = vscode.workspace.getConfiguration("vectorcastTestExplorer");
let unitTestLocation: string = settings.get(
"unitTestLocation",
defaultUTlocation
);

if (unitTestLocation.startsWith(".")) {
unitTestLocation = path.join(dirpath, unitTestLocation);
}

}
return unitTestLocation;
}
57 changes: 37 additions & 20 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ import {
addExistingCodedTestFile,
newEnvironment,
newTestScript,
openCodedTest,
resetCoverageData,
} from "./vcastTestInterface";

Expand All @@ -102,12 +103,16 @@ export function getMessagePane(): vscode.OutputChannel {
return messagePane;
}
export async function activate(context: vscode.ExtensionContext) {
// activation gets called when vectorcastTestExplorer.configure is called
// currently from the ctrl-p menu,

// dummy command to be used for activation
// activation gets called when:
// -- VectorCAST environment exists in the workspace
// -- "Create VectorCAST Environment" is selected from the Explorer context menu
// -- "VectorCAST Test Explorer: Configure" is selected from the command palette (ctrl-shift-p)

// Handler for "VectorCAST Test Explorer: Configure"
// The first use of configure will trigger this activate function
// subsequent uses will trigger configureCommandCalled()
vscode.commands.registerCommand("vectorcastTestExplorer.configure", () => {
checkPrerequisites(context);
configureCommandCalled(context);
});
vscode.commands.registerCommand("vectorcastTestExplorer.toggleLog", () =>
toggleMessageLog()
Expand Down Expand Up @@ -138,7 +143,10 @@ function checkPrerequisites(context: vscode.ExtensionContext) {

if (!alreadyConfigured) {
// setup the location of vTestInterface.py and other utilities
initializeInstallerFiles(context);
if (!installationFilesInitialized) {
initializeInstallerFiles(context);
installationFilesInitialized = true;
}

if (checkIfInstallationIsOK()) {
activationLogic(context);
Expand Down Expand Up @@ -363,6 +371,18 @@ function configureExtension(context: vscode.ExtensionContext) {
);
context.subscriptions.push(editTestScriptCommand);

// Command: vectorcastTestExplorer.editCodedTest////////////////////////////////////////////////////////
let editCodedTestCommand = vscode.commands.registerCommand(
"vectorcastTestExplorer.editCodedTest",
(args: any) => {
if (args) {
const testNode: testNodeType = getTestNode(args.id);
openCodedTest(testNode);
}
}
);
context.subscriptions.push(editCodedTestCommand);

// Command: vectorcastTestExplorer.loadTestScript////////////////////////////////////////////////////////
let loadTestScriptCommand = vscode.commands.registerCommand(
"vectorcastTestExplorer.loadTestScript",
Expand All @@ -383,6 +403,17 @@ function configureExtension(context: vscode.ExtensionContext) {
);
context.subscriptions.push(debugEnviroPathCommand);

// Command: vectorcastTestExplorer.debugProgramPath ////////////////////////////////////////////////////////
// this command is used to return the path to the environment being debugged via
// the variable: vectorcastTestExplorer.debugProgramPath that is used in launch.json
let debugProgramPathCommand = vscode.commands.registerCommand(
"vectorcastTestExplorer.debugProgramPath",
() => {
return pathToProgramBeingDebugged;
}
);
context.subscriptions.push(debugProgramPathCommand);

// Command: vectorcastTestExplorer.showSettings
vscode.commands.registerCommand("vectorcastTestExplorer.showSettings", () =>
showSettings()
Expand Down Expand Up @@ -481,20 +512,6 @@ function configureExtension(context: vscode.ExtensionContext) {
);
context.subscriptions.push(openVCASTFromVce);

// Command: vectorcastTestExplorer.newEnviroVCAST ////////////////////////////////////////////////////////
let newEnviroVCASTCommand = vscode.commands.registerCommand(
"vectorcastTestExplorer.newEnviroVCAST",
(args: Uri, argList: Uri[]) => {
// arg is the actual item that the right click happened on, argList is the list
// of all items if this is a multi-select. Since argList is always valid, even for a single
// selection, we just use this here.
if (argList) {
newEnvironment(argList);
}
}
);
context.subscriptions.push(newEnviroVCASTCommand);

// Command: vectorcastTestExplorer.buildEnviroFromEnv ////////////////////////////////////////////////////////
let buildEnviroVCASTCommand = vscode.commands.registerCommand(
"vectorcastTestExplorer.buildEnviroFromEnv",
Expand Down
6 changes: 4 additions & 2 deletions src/messagePane.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function formattedLine(
return returnString;
}

function displayMessage(prefix: string, msg: string, level: errorLevel) {
async function displayMessage(prefix: string, msg: string, level: errorLevel) {
const messagePane = getMessagePane();
let stringList = msg.split("\n");
// for errorLevel.error, we show the first line of the msg in a popup
Expand All @@ -43,7 +43,9 @@ function displayMessage(prefix: string, msg: string, level: errorLevel) {

// duplicated from VTC ////////////////////////

export function vectorMessage(
// Note that this is an aysnc function so to if you are using to display
// a message before a long-running process, use await in the caller.
export async function vectorMessage(
msg: string,
level: errorLevel = errorLevel.info
) {
Expand Down
14 changes: 10 additions & 4 deletions src/reporting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ tr:hover {
overflow: scroll;
}
.danger {
background-color: var(--vscode-testing-iconFailed);
.danger, .bg-danger {
background-color: var(--vscode-minimap-errorHighlight);
color: black;
font-weight: bold
}
.danger:hover {
background-color: var(--vscode-testing-iconFailed) !important;
.danger:hover, .bg-danger:hover {
background-color: var(--vscode-minimap-errorHighlight) !important;
}
.success, .bg-success {
Expand All @@ -82,6 +82,12 @@ tr:hover {
.warning:hover, .bg-warning:hover {
background-color: var(--vscode-testing-iconQueued) !important;
}
pre {
border:1px solid var(--vscode-editorGroup-border);
background-color:var(--vscode-editorGroup-border);
color: var(--vscode-foreground);
}
</style>`;
returnText += line;
skipping = false;
Expand Down
Loading

0 comments on commit 1f620d5

Please sign in to comment.