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

Add support to specify java executable to use for test #1602

Merged
merged 3 commits into from
Sep 4, 2023
Merged
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
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ module.exports = {
],
'root': true,
'ignorePatterns': [
'**/*.d.ts'
'**/*.d.ts',
'**/*.test.ts'
],
'rules': {
'@typescript-eslint/no-inferrable-types': 'off',
Expand Down
10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,11 @@
"description": "%configuration.java.test.config.modulePaths.description%",
"default": []
},
"javaExec": {
"type": "string",
"markdownDescription": "%configuration.java.test.config.javaExec.description%",
"default": ""
},
"vmArgs": {
"type": "array",
"items": {
Expand Down Expand Up @@ -381,6 +386,11 @@
"description": "%configuration.java.test.config.modulePaths.description%",
"default": []
},
"javaExec": {
"type": "string",
"markdownDescription": "%configuration.java.test.config.javaExec.description%",
"default": ""
},
"vmargs": {
"type": "array",
"items": {
Expand Down
1 change: 1 addition & 0 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"configuration.java.test.config.testKind.description": "Specify the targeting test framework for this test configuration. Supported values are `junit`, `testng`.",
"configuration.java.test.config.filters.description": "Specify the test filters.",
"configuration.java.test.config.filters.tags.description": "Specify the tags to be included or excluded. \n\nTags having `!` as the prefix will be **excluded**. \n\nNote: This setting **only** takes effect when `testKind` is set to `junit`.",
"configuration.java.test.config.javaExec.description": "The path to java executable to use. For example: `C:\\Program Files\\jdk\\bin\\java.exe`. If unset project JDK's java executable is used.",
"contributes.viewsWelcome.inLightWeightMode": "No test cases are listed because the Java Language Server is currently running in [LightWeight Mode](https://aka.ms/vscode-java-lightweight). To show test cases, click on the button to switch to Standard Mode.\n[Switch to Standard Mode](command:java.server.mode.switch?%5B%22Standard%22,true%5D)",
"contributes.viewsWelcome.enableTests": "Click below button to configure a test framework for your project.\n[Enable Java Tests](command:_java.test.enableTests)"
}
17 changes: 16 additions & 1 deletion src/controller/testController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ export const runTests: (request: TestRunRequest, option: IRunOption) => any = in
}
try {
await runner.setup();
const resolvedConfiguration: DebugConfiguration = option.launchConfiguration ?? await resolveLaunchConfigurationForRunner(runner, testContext, config);
const resolvedConfiguration: DebugConfiguration = mergeConfigurations(option.launchConfiguration, config) ?? await resolveLaunchConfigurationForRunner(runner, testContext, config);
jdneo marked this conversation as resolved.
Show resolved Hide resolved
resolvedConfiguration.__progressId = option.progressReporter?.getId();
delegatedToDebugger = true;
await runner.run(resolvedConfiguration, token, option.progressReporter);
Expand All @@ -245,6 +245,21 @@ export const runTests: (request: TestRunRequest, option: IRunOption) => any = in
}
});

function mergeConfigurations(launchConfiguration: DebugConfiguration | undefined, config: any): DebugConfiguration | undefined {
if (!launchConfiguration) {
return undefined;
}

const entryKeys: string[] = Object.keys(config);
for (const configKey of entryKeys) {
// for now we merge launcher properties which doesn't have a value.
if (!launchConfiguration[configKey]) {
launchConfiguration[configKey] = config[configKey];
}
}
return launchConfiguration;
}

/**
* Set all the test item to queued state
*/
Expand Down
6 changes: 6 additions & 0 deletions src/runConfigs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ export interface IExecutionConfig {
*/
args?: any[];

/**
* The path to java executable to use. If undefined project JDK's java executable is used.
* @since 0.40.0
*/
javaExec?: string;

/**
* the extra options and system properties for the JVM.
* It's deprecated, we should align with the debug launch configuration, which is 'vmArgs'.
Expand Down
2 changes: 2 additions & 0 deletions src/utils/launchUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export async function resolveLaunchConfigurationForRunner(runner: BaseRunner, te
sourcePaths: config?.sourcePaths,
preLaunchTask: config?.preLaunchTask,
postDebugTask: config?.postDebugTask,
javaExec: config?.javaExec,
};
}

Expand Down Expand Up @@ -76,6 +77,7 @@ export async function resolveLaunchConfigurationForRunner(runner: BaseRunner, te
sourcePaths: config?.sourcePaths,
preLaunchTask: config?.preLaunchTask,
postDebugTask: config?.postDebugTask,
javaExec: config?.javaExec,
};
}

Expand Down
14 changes: 8 additions & 6 deletions test/suite/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,19 @@ suite('JUnit Runner Analyzer Tests', () => {
"/a/b/c.jar",
"/foo/bar.jar"
],
modulePaths: [
"/test/module.jar",
],
env: {
test: "test",
},
envFile: "${workspaceFolder}/.env",
sourcePaths: [
"/a/b/c.jar"
javaExec: "/usr/bin/java",
modulePaths: [
"/test/module.jar",
],
postDebugTask: "test",
preLaunchTask: "test",
postDebugTask: "test"
sourcePaths: [
"/a/b/c.jar"
]
});
assert.strictEqual(configuration.env.test, "test");
assert.strictEqual(configuration.envFile, "${workspaceFolder}/.env");
Expand All @@ -67,5 +68,6 @@ suite('JUnit Runner Analyzer Tests', () => {
assert.strictEqual(configuration.modulePaths[0], "/test/module.jar");
assert.strictEqual(configuration.classPaths[0], "/a/b/c.jar");
assert.strictEqual(configuration.classPaths[1], "/foo/bar.jar");
assert.strictEqual(configuration.javaExec, "/usr/bin/java");
});
});