Skip to content
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
6 changes: 3 additions & 3 deletions src/FolderContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import * as vscode from "vscode";
import * as path from "path";
import { LinuxMain } from "./LinuxMain";
import { PackageWatcher } from "./PackageWatcher";
import { SwiftPackage, Target } from "./SwiftPackage";
import { SwiftPackage, Target, TargetType } from "./SwiftPackage";
import { TestExplorer } from "./TestExplorer/TestExplorer";
import { WorkspaceContext, FolderEvent } from "./WorkspaceContext";
import { BackgroundCompilation } from "./BackgroundCompilation";
Expand Down Expand Up @@ -179,11 +179,11 @@ export class FolderContext implements vscode.Disposable {
* @param uri URI to find target for
* @returns Target
*/
getTestTarget(uri: vscode.Uri): Target | undefined {
getTestTarget(uri: vscode.Uri, type?: TargetType): Target | undefined {
if (!isPathInsidePath(uri.fsPath, this.folder.fsPath)) {
return undefined;
}
const testTargets = this.swiftPackage.getTargets("test");
const testTargets = this.swiftPackage.getTargets(type);
const target = testTargets.find(element => {
const relativeUri = path.relative(
path.join(this.folder.fsPath, element.path),
Expand Down
14 changes: 12 additions & 2 deletions src/SwiftPackage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,8 +363,12 @@ export class SwiftPackage implements PackageContents {
* @param type Type of target
* @returns Array of targets
*/
getTargets(type: "executable" | "library" | "test"): Target[] {
return this.targets.filter(target => target.type === type);
getTargets(type?: TargetType): Target[] {
if (type === undefined) {
return this.targets;
} else {
return this.targets.filter(target => target.type === type);
}
}

/**
Expand All @@ -375,3 +379,9 @@ export class SwiftPackage implements PackageContents {
return this.targets.find(target => isPathInsidePath(filePath, target.path));
}
}

export enum TargetType {
executable = "executable",
library = "library",
test = "test",
}
4 changes: 2 additions & 2 deletions src/SwiftTaskProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import * as vscode from "vscode";
import * as path from "path";
import { WorkspaceContext } from "./WorkspaceContext";
import { FolderContext } from "./FolderContext";
import { Product } from "./SwiftPackage";
import { Product, TargetType } from "./SwiftPackage";
import configuration from "./configuration";
import { swiftRuntimeEnv } from "./utilities/utilities";
import { Version } from "./utilities/version";
Expand Down Expand Up @@ -110,7 +110,7 @@ function getBuildRevealOption(): vscode.TaskRevealKind {
*/
export function createBuildAllTask(folderContext: FolderContext): vscode.Task {
let additionalArgs = buildOptions(folderContext.workspaceContext.toolchain);
if (folderContext.swiftPackage.getTargets("test").length > 0) {
if (folderContext.swiftPackage.getTargets(TargetType.test).length > 0) {
additionalArgs.push(...testDiscoveryFlag(folderContext));
}
let buildTaskName = SwiftTaskProvider.buildAllName;
Expand Down
3 changes: 2 additions & 1 deletion src/TestExplorer/TestDiscovery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import * as vscode from "vscode";
import { FolderContext } from "../FolderContext";
import { TargetType } from "../SwiftPackage";

/** Test function definition */
export interface TestFunction {
Expand Down Expand Up @@ -49,7 +50,7 @@ export function updateTestsFromClasses(folderContext: FolderContext, testClasses
if (!testExplorer) {
return;
}
const targets = folderContext.swiftPackage.getTargets("test").map(target => {
const targets = folderContext.swiftPackage.getTargets(TargetType.test).map(target => {
const classes = testClasses.filter(
testClass =>
testClass.location &&
Expand Down
8 changes: 5 additions & 3 deletions src/TestExplorer/TestExplorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import configuration from "../configuration";
import { buildOptions, getBuildAllTask } from "../SwiftTaskProvider";
import { SwiftExecOperation, TaskOperation } from "../TaskQueue";
import * as TestDiscovery from "./TestDiscovery";
import { TargetType } from "../SwiftPackage";

/** Build test explorer UI */
export class TestExplorer {
Expand Down Expand Up @@ -67,7 +68,7 @@ export class TestExplorer {
) {
this.testFileEdited = false;
// only run discover tests if the library has tests
if (this.folderContext.swiftPackage.getTargets("test").length > 0) {
if (this.folderContext.swiftPackage.getTargets(TargetType.test).length > 0) {
this.discoverTestsInWorkspace();
}
}
Expand Down Expand Up @@ -97,7 +98,7 @@ export class TestExplorer {
switch (event) {
case FolderEvent.add:
if (folder) {
if (folder.swiftPackage.getTargets("test").length > 0) {
if (folder.swiftPackage.getTargets(TargetType.test).length > 0) {
folder.addTestExplorer();
// discover tests in workspace but only if disableAutoResolve is not on.
// discover tests will kick off a resolve if required
Expand All @@ -109,7 +110,8 @@ export class TestExplorer {
break;
case FolderEvent.packageUpdated:
if (folder) {
const hasTestTargets = folder.swiftPackage.getTargets("test").length > 0;
const hasTestTargets =
folder.swiftPackage.getTargets(TargetType.test).length > 0;
if (hasTestTargets && !folder.hasTestExplorer()) {
folder.addTestExplorer();
// discover tests in workspace but only if disableAutoResolve is not on.
Expand Down
5 changes: 3 additions & 2 deletions src/debugger/launch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { FolderContext } from "../FolderContext";
import { BuildFlags } from "../toolchain/BuildFlags";
import { stringArrayInEnglish, swiftLibraryPathKey, swiftRuntimeEnv } from "../utilities/utilities";
import { DebugAdapter } from "./debugAdapter";
import { TargetType } from "../SwiftPackage";

/**
* Edit launch.json based on contents of Swift Package.
Expand Down Expand Up @@ -178,7 +179,7 @@ export function createTestConfiguration(
ctx: FolderContext,
expandEnvVariables = false
): vscode.DebugConfiguration | null {
if (ctx.swiftPackage.getTargets("test").length === 0) {
if (ctx.swiftPackage.getTargets(TargetType.test).length === 0) {
return null;
}

Expand Down Expand Up @@ -265,7 +266,7 @@ export function createDarwinTestConfiguration(
ctx: FolderContext,
args: string
): vscode.DebugConfiguration | null {
if (ctx.swiftPackage.getTargets("test").length === 0) {
if (ctx.swiftPackage.getTargets(TargetType.test).length === 0) {
return null;
}
if (process.platform !== "darwin") {
Expand Down