summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.vscode/settings.json4
-rw-r--r--lib/extension.ts31
-rwxr-xr-xscripts/run_test.sh8
3 files changed, 27 insertions, 16 deletions
diff --git a/.vscode/settings.json b/.vscode/settings.json
index 1dca644..ed18637 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -17,8 +17,8 @@
"[java]": {
"editor.formatOnSave": true
},
- "java.testMethod": ["mvn", "test", "-Dtest=${class}#${method}"],
- "java.testClass": ["mvn", "test", "-Dtest=${class}"],
+ "java.testMethod": ["scripts/run_test.sh", "${class}", "${method}"],
+ "java.testClass": ["scripts/run_test.sh", "${class}"],
// "typescript.tsserver.trace": "verbose",
// "java.trace.server": "verbose",
} \ No newline at end of file
diff --git a/lib/extension.ts b/lib/extension.ts
index 4a2d394..3b1a867 100644
--- a/lib/extension.ts
+++ b/lib/extension.ts
@@ -114,26 +114,28 @@ function runFindReferences(uri: string, lineNumber: number, column: number) {
}
interface JavaTestTask extends TaskDefinition {
- enclosingClass: string
- method: string
+ className: string
+ methodName: string
}
-function runTest(sourceUri: string, enclosingClass: string, method: string): Thenable<TaskExecution> {
+function runTest(sourceUri: string, className: string, methodName: string): Thenable<TaskExecution> {
+ let file = Uri.parse(sourceUri).fsPath;
+ file = Path.relative(workspace.rootPath, file);
let kind: JavaTestTask = {
type: 'java.task.test',
- enclosingClass: enclosingClass,
- method: method,
+ className: className,
+ methodName: methodName,
}
var shell;
let config = workspace.getConfiguration('java')
// Run method or class
- if (method != null) {
+ if (methodName != null) {
let command = config.get('testMethod') as string[]
if (command.length == 0) {
window.showErrorMessage('Set "java.testMethod" in .vscode/settings.json')
shell = new ShellExecution('echo', ['Set "java.testMethod" in .vscode/settings.json, for example ["mvn", "test", "-Dtest=${class}#${method}"]'])
} else {
- shell = templateCommand(command, enclosingClass, method)
+ shell = templateCommand(command, file, className, methodName)
}
} else {
let command = config.get('testClass') as string[]
@@ -141,7 +143,7 @@ function runTest(sourceUri: string, enclosingClass: string, method: string): The
window.showErrorMessage('Set "java.testClass" in .vscode/settings.json')
shell = new ShellExecution('echo', ['Set "java.testClass" in .vscode/settings.json, for example ["mvn", "test", "-Dtest=${class}"]'])
} else {
- shell = templateCommand(command, enclosingClass, method)
+ shell = templateCommand(command, file, className, methodName)
}
}
let workspaceFolder = workspace.getWorkspaceFolder(Uri.parse(sourceUri))
@@ -149,17 +151,18 @@ function runTest(sourceUri: string, enclosingClass: string, method: string): The
return tasks.executeTask(task)
}
-function templateCommand(command: string[], enclosingClass: string, method: string) {
+function templateCommand(command: string[], file: string, className: string, methodName: string) {
// Replace template parameters
var replaced = []
for (var i = 0; i < command.length; i++) {
- replaced[i] = command[i].replace('${class}', enclosingClass).replace('${method}', method)
+ let c = command[i]
+ c = c.replace('${file}', file)
+ c = c.replace('${class}', className)
+ c = c.replace('${method}', methodName)
+ replaced[i] = c
}
// Populate env
- let env = {} as {[key: string]: string};
- let config = workspace.getConfiguration('java')
- if (config.has('home'))
- env['JAVA_HOME'] = config.get('home')
+ let env = {...process.env} as {[key: string]: string};
return new ShellExecution(replaced[0], replaced.slice(1), {env})
}
diff --git a/scripts/run_test.sh b/scripts/run_test.sh
new file mode 100755
index 0000000..896b250
--- /dev/null
+++ b/scripts/run_test.sh
@@ -0,0 +1,8 @@
+#!/bin/bash
+
+set -e
+
+# Needed if you have a java version other than 11 as default
+JAVA_HOME=$(/usr/libexec/java_home -v 11)
+
+mvn test -Dtest=$1#$2 \ No newline at end of file