generated from hbenl/vscode-example-test-adapter
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed test executable detection using wildcards (#63)
* 1.3.4 * Refactored Settings to be testable * Updated npm packages * Wrote tests and fixed issue #55 * Fixed merge conflicts
- Loading branch information
Showing
15 changed files
with
1,110 additions
and
186 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
|
||
export interface IDebugConfiguration { | ||
target?: string; | ||
program?: string; | ||
args?: string[]; | ||
name: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
|
||
export interface IWorkspaceConfiguration { | ||
testExecutable: string | undefined; | ||
testExecutablePath: string | undefined; | ||
testLocationFetchMode: any; | ||
logfile: string | undefined; | ||
logpanel: boolean; | ||
debugLaunchConfigurationName: string | undefined; | ||
objDumpExecutable: string | undefined; | ||
preLaunchTask: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
export interface IWorkspaceFolder { | ||
readonly uri: any; | ||
readonly name: string; | ||
readonly index: number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { IDebugConfiguration } from "./IDebugConfiguration"; | ||
import { IWorkspaceConfiguration } from "./IWorkspaceConfiguration"; | ||
import { IWorkspaceFolder } from "./IWorkspaceFolder"; | ||
import { SettingsProvider } from "./SettingsProvider"; | ||
import { TestLocationFetchMode } from "./TestLocationFetchMode"; | ||
import { VscodeAdapter } from "./VscodeAdapter"; | ||
|
||
export { IDebugConfiguration }; | ||
export { TestLocationFetchMode }; | ||
export { SettingsProvider }; | ||
export { IWorkspaceConfiguration }; | ||
export { IWorkspaceFolder }; | ||
export { VscodeAdapter }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,90 @@ | ||
import { DebugConfiguration, WorkspaceFolder } from 'vscode'; | ||
import { Log } from 'vscode-test-adapter-util'; | ||
import { IWorkspaceFolder } from './IWorkspaceFolder'; | ||
import { IDebugConfiguration } from './IDebugConfiguration'; | ||
import { IWorkspaceConfiguration } from './IWorkspaceConfiguration'; | ||
import { TestLocationFetchMode } from './TestLocationFetchMode'; | ||
|
||
export enum TestLocationFetchMode { | ||
Auto, | ||
TestQuery, | ||
DebugDump, | ||
Disabled | ||
} | ||
export abstract class SettingsProvider { | ||
protected log: Log; | ||
protected config: IWorkspaceConfiguration; | ||
|
||
constructor(log: Log) { | ||
const configSection = "cpputestTestAdapter"; | ||
|
||
this.log = log; | ||
this.config = this.GetConfig(configSection); | ||
} | ||
|
||
protected abstract GetConfig(section: string): IWorkspaceConfiguration; | ||
public abstract GetObjDumpPath(): string; | ||
public abstract GetTestRunners(): string[]; | ||
public abstract GetTestPath(): string; | ||
public abstract GetPreLaunchTask(): string; | ||
public abstract GetDebugConfiguration(): (IDebugConfiguration | undefined); | ||
public abstract GetWorkspaceFolders(): readonly IWorkspaceFolder[] | undefined | ||
protected abstract GetCurrentFilename(): string | ||
protected abstract GetCurrentWorkspaceFolder(): string | ||
protected abstract GlobFiles(wildcardString: string): string[] | ||
|
||
public get TestLocationFetchMode(): TestLocationFetchMode { | ||
switch (this.config.testLocationFetchMode) { | ||
case 'test query': | ||
return TestLocationFetchMode.TestQuery; | ||
case 'debug dump': | ||
return TestLocationFetchMode.DebugDump; | ||
case 'auto': | ||
return TestLocationFetchMode.Auto; | ||
case 'disabled': | ||
default: | ||
return TestLocationFetchMode.Disabled; | ||
} | ||
} | ||
|
||
protected IsCCppDebugger(config: any) { | ||
const isWin = process.platform === "win32"; | ||
// This is my way of saying: If we are using windows check for a config that has an .exe program. | ||
const executionExtension: boolean = isWin ? config.program.endsWith(".exe") : true; | ||
return config.request == 'launch' && | ||
typeof config.type == 'string' && | ||
executionExtension && | ||
(config.type.startsWith('cpp') || | ||
config.type.startsWith('lldb') || | ||
config.type.startsWith('gdb')); | ||
} | ||
|
||
protected SplitRunners(executablesString: string | undefined): string[] { | ||
if (executablesString) { | ||
if (executablesString.indexOf(";") === -1) { | ||
return this.GlobFiles(this.ResolveSettingsVariable(executablesString)); | ||
} | ||
return executablesString | ||
.split(";") | ||
.map(r => this.ResolveSettingsVariable(r)) | ||
.map(r => this.GlobFiles(r)) | ||
.reduce((flatten, arr) => [...flatten, ...arr]); | ||
} else { | ||
return []; | ||
} | ||
} | ||
|
||
export interface SettingsProvider { | ||
GetObjDumpPath(): string; | ||
GetTestRunners(): string[]; | ||
GetTestPath(): string; | ||
GetPreLaunchTask(): string; | ||
get TestLocationFetchMode(): TestLocationFetchMode; | ||
GetDebugConfiguration(): (DebugConfiguration | string); | ||
GetWorkspaceFolders(): readonly WorkspaceFolder[] | undefined | ||
/** | ||
* This function converts some of the VSCode variables like workspaceFolder | ||
* into their correspoing values. This is a workaround for https://github.com/microsoft/vscode/issues/46471 | ||
* @param input Input string from settings.json | ||
*/ | ||
protected ResolveSettingsVariable(input: string | undefined): string { | ||
if (input) { | ||
const result: string[] | null = input.match(/\$\{(.*)\}/gmi); | ||
if (result && result.length > 0) { | ||
this.log.info(`replacing config variabe "${input}"`); | ||
input = input.replace(/(\$\{file\})/gmi, this.GetCurrentFilename()); | ||
input = input.replace(/(\$\{workspaceFolder\})/gmi, this.GetCurrentWorkspaceFolder()); | ||
this.log.info(`replaced variable is now "${input}"`); | ||
} | ||
return input; | ||
} | ||
else { | ||
return ""; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
|
||
export enum TestLocationFetchMode { | ||
Auto, | ||
TestQuery, | ||
DebugDump, | ||
Disabled | ||
} |
Oops, something went wrong.