Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding functionName under Flag to Keploy #83

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion scripts/utg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ testFilePath=$2
coverageReportPath=$3
command=$4
additional_prompts=$5

CodeLensefunctionName=$6
# Get the file extension
extension="${sourceFilePath##*.}"

Expand Down Expand Up @@ -77,6 +77,10 @@ if [ -n "$additional_prompts" ] && [ "$additional_prompts" != " " ]; then
keployCommand="$keployCommand --additional-prompt \"$additional_prompts\""
fi

if [ -n "$CodeLensefunctionName" ] && [ "$CodeLensefunctionName" != " " ]; then
keployCommand="$keployCommand --function-under-test \"$CodeLensefunctionName\""
fi

# Run the keploy command
# echo "Running: $keployCommand"
eval $keployCommand
2 changes: 1 addition & 1 deletion src/SidebarProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
console.log('Navigate to ' + value);
let sveltePageJs: vscode.Uri;
let sveltePageCss: vscode.Uri;
if(value == "KeployChatBot"){

Check warning on line 81 in src/SidebarProvider.ts

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Expected '===' and instead saw '=='

Check warning on line 81 in src/SidebarProvider.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Expected '===' and instead saw '=='

Check warning on line 81 in src/SidebarProvider.ts

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Expected '===' and instead saw '=='
sveltePageJs = webviewView.webview.asWebviewUri(
vscode.Uri.joinPath(this._extensionUri, "out", "compiled", "KeployChat.js")
);
Expand Down Expand Up @@ -435,11 +435,11 @@
console.log("additional prompts and uri: ", additional_prompts );
await vscode.commands.executeCommand('keploy.runAdditionalPrompts',additional_prompts);
}catch(error){
console.error("Error executing keploy.utg command:", error);
console.error("Error executing keploy.runAdditionalPrompts command:", error);
}
}
case "progressStatus":{
if(progressBarVisible == true && data.value == "false"){

Check warning on line 442 in src/SidebarProvider.ts

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Expected '===' and instead saw '=='

Check warning on line 442 in src/SidebarProvider.ts

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Expected '===' and instead saw '=='

Check warning on line 442 in src/SidebarProvider.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Expected '===' and instead saw '=='

Check warning on line 442 in src/SidebarProvider.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Expected '===' and instead saw '=='

Check warning on line 442 in src/SidebarProvider.ts

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Expected '===' and instead saw '=='

Check warning on line 442 in src/SidebarProvider.ts

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Expected '===' and instead saw '=='
console.log("progressbarVisible and data value: ",progressBarVisible,data.value);
await this._context.globalState.update("progressVisible", false);
}
Expand Down
8 changes: 6 additions & 2 deletions src/Utg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import axios, { AxiosResponse } from 'axios';


async function Utg(context: vscode.ExtensionContext , additional_prompts?:string,testFilesPath?: vscode.Uri[] | undefined) {
async function Utg(context: vscode.ExtensionContext , CodeLensefunctionName?:string, additional_prompts?:string,testFilesPath?: vscode.Uri[] | undefined ) {

try {
return new Promise<void>(async (resolve, reject) => {
Expand Down Expand Up @@ -150,7 +150,7 @@
const originalClassName = path.basename(sourceFilePath, '.java');
const testFileName = `${originalClassName}Tests.java`;
const testFilePath = path.join(fullTestDir, testFileName);
const JavaClassName = `${originalClassName}Tests`

Check warning on line 153 in src/Utg.ts

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Missing semicolon

Check warning on line 153 in src/Utg.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Missing semicolon

Check warning on line 153 in src/Utg.ts

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Missing semicolon

testFilePaths.push(testFilePath);

Expand Down Expand Up @@ -224,9 +224,13 @@
if(!additional_prompts){
additional_prompts = "";
}

if(!CodeLensefunctionName){
CodeLensefunctionName = ""

Check warning on line 229 in src/Utg.ts

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Missing semicolon

Check warning on line 229 in src/Utg.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Missing semicolon

Check warning on line 229 in src/Utg.ts

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Missing semicolon
}

// Adjust the terminal command to include the test file path
terminal.sendText(`sh "${scriptPath}" "${sourceFilePath}" "${testFilePaths[0]}" "${coverageReportPath}" "${command}" "${additional_prompts}";`);
terminal.sendText(`sh "${scriptPath}" "${sourceFilePath}" "${testFilePaths[0]}" "${coverageReportPath}" "${command}" "${additional_prompts}" "${CodeLensefunctionName}";`);

const delay = (ms: number) => new Promise(resolve => setTimeout(resolve, ms));

Expand Down
73 changes: 59 additions & 14 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,14 @@
console.log('🐰 Found function:', node.childForFieldName('name')?.text);
const functionName = node.childForFieldName('name')?.text || '';
codeLenses.push(new vscode.CodeLens(range, {
title: '🐰 Generate unit tests',
title: '🐰 Generate unit test for this function ',
command: 'keploy.utg',
arguments: [document.uri.fsPath, functionName, fileExtension]
arguments: [document.uri.fsPath, functionName, fileExtension,undefined,true]
}));
codeLenses.push(new vscode.CodeLens(range, {
title: '🐰 Generate unit test for entire file',
command: 'keploy.utg',
arguments: [document.uri.fsPath, functionName, fileExtension,undefined,false]
}));
codeLenses.push(new vscode.CodeLens(range, {
title: '🐰 Additional Prompts',
Expand All @@ -172,9 +177,15 @@
const line = document.positionAt(node.startIndex).line;
const range = new vscode.Range(line, 0, line, 0);
codeLenses.push(new vscode.CodeLens(range, {
title: '🐰 Generate unit tests',
title: '🐰 Generate unit test for this function ',
command: 'keploy.utg',
arguments: [document.uri.fsPath, functionName, fileExtension]
arguments: [document.uri.fsPath, functionName, fileExtension,undefined,true]
}));

codeLenses.push(new vscode.CodeLens(range, {
title: '🐰 Generate unit test for entire file',
command: 'keploy.utg',
arguments: [document.uri.fsPath, functionName, fileExtension,undefined,false]
}));

codeLenses.push(new vscode.CodeLens(range, {
Expand All @@ -191,9 +202,15 @@
const functionNameNode = node.childForFieldName('name');
const functionName = functionNameNode?.text || '';
codeLenses.push(new vscode.CodeLens(range, {
title: '🐰 Generate unit tests',
title: '🐰 Generate unit test for this function ',
command: 'keploy.utg',
arguments: [document.uri.fsPath, functionName, fileExtension]
arguments: [document.uri.fsPath, functionName, fileExtension,undefined,true]
}));

codeLenses.push(new vscode.CodeLens(range, {
title: '🐰 Generate unit test for entire file',
command: 'keploy.utg',
arguments: [document.uri.fsPath, functionName, fileExtension, undefined,false]
}));
codeLenses.push(new vscode.CodeLens(range, {
title: '🐰 Additional Prompts',
Expand All @@ -207,10 +224,17 @@
const functionName = functionNameNode?.text || '';
//just adding it for the sake of testing will change it later.
codeLenses.push(new vscode.CodeLens(range, {
title: '🐰 Generate unit tests',
title: '🐰 Generate unit test for this function ',
command: 'keploy.utg',
arguments: [document.uri.fsPath, functionName, fileExtension]
arguments: [document.uri.fsPath, functionName, fileExtension,undefined,true]
}));

codeLenses.push(new vscode.CodeLens(range, {
title: '🐰 Generate unit test for entire file',
command: 'keploy.utg',
arguments: [document.uri.fsPath, functionName, fileExtension,undefined,false]
}));

codeLenses.push(new vscode.CodeLens(range, {
title: '🐰 Additional Prompts',
command: 'keploy.showSidebar',
Expand All @@ -224,10 +248,17 @@
const functionName = functionNameNode?.text || '';

codeLenses.push(new vscode.CodeLens(range, {
title: '🐰 Generate unit tests',
title: '🐰 Generate unit test for this function ',
command: 'keploy.utg',
arguments: [document.uri.fsPath, functionName, fileExtension]
arguments: [document.uri.fsPath, functionName, fileExtension,undefined,true]
}));

codeLenses.push(new vscode.CodeLens(range, {
title: '🐰 Generate unit test for entire file',
command: 'keploy.utg',
arguments: [document.uri.fsPath, functionName, fileExtension,undefined,false]
}));

codeLenses.push(new vscode.CodeLens(range, {
title: '🐰 Additional Prompts',
command: 'keploy.showSidebar',
Expand Down Expand Up @@ -727,20 +758,20 @@
return;
}
vscode.commands.executeCommand('workbench.view.extension.Keploy-Sidebar');
sidebarProvider.postMessage("KeployChatBot")

Check warning on line 761 in src/extension.ts

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Missing semicolon

Check warning on line 761 in src/extension.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Missing semicolon

Check warning on line 761 in src/extension.ts

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Missing semicolon
});

context.subscriptions.push(showSidebarDisposable);

let runAdditionalPrompts = vscode.commands.registerCommand('keploy.runAdditionalPrompts', async (additionalPrompts: string) => {
console.log("value inside the function: ", functionName, ExtentionName, additionalPrompts);
await vscode.commands.executeCommand('keploy.utg', FunctionFilePath, functionName, ExtentionName, additionalPrompts);
await vscode.commands.executeCommand('keploy.utg', FunctionFilePath, functionName, ExtentionName, additionalPrompts , false);
})

Check warning on line 769 in src/extension.ts

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Missing semicolon

Check warning on line 769 in src/extension.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Missing semicolon

Check warning on line 769 in src/extension.ts

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Missing semicolon

context.subscriptions.push(runAdditionalPrompts);

// Register the command
let disposable = vscode.commands.registerCommand('keploy.utg', async (filePath: string, functionName: string, fileExtension: string, additional_prompts?: string) => {
let disposable = vscode.commands.registerCommand('keploy.utg', async (filePath: string, functionName: string, fileExtension: string, additional_prompts?: string , singleUtgTest?:boolean ) => {
// Check if the user is already signed in
const signedIn = await context.globalState.get('accessToken');
const signedInOthers = await context.globalState.get('SignedOthers');
Expand Down Expand Up @@ -811,11 +842,25 @@
console.log("No test files found for any functions in the file.");
}
}

switch(singleUtgTest){
case true:
console.log("Executing for the Single Function");
break;
case false:
console.log("Executing for the Whole Test File");
functionName = "";
break;
case undefined:
console.log("Executing with singleUnitTest parameter as undefined")

Check warning on line 854 in src/extension.ts

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Missing semicolon

Check warning on line 854 in src/extension.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Missing semicolon

Check warning on line 854 in src/extension.ts

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Missing semicolon
default:
console.log("Going the default in generating the Utg");
break;

}
// Ensure that Utg is called with the correct parameters
console.log("additional prompts inside the keploy.utg ", additional_prompts);
vscode.window.showInformationMessage('Welcome to Keploy!');
await Utg(context, additional_prompts, testFilesPath);
await Utg(context,functionName, additional_prompts, testFilesPath);
}
}
});
Expand Down
Loading