Skip to content

Commit

Permalink
add rudimentary test -> test source lookup
Browse files Browse the repository at this point in the history
Signed-off-by: Jannik Glückert <jannik.glueckert@gmail.com>
  • Loading branch information
Jannik2099 committed Sep 21, 2024
1 parent 4ce57c8 commit 1523925
Showing 1 changed file with 32 additions and 3 deletions.
35 changes: 32 additions & 3 deletions src/tests.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,40 @@
import * as os from "os";
import * as vscode from "vscode";
import { ExecResult, exec, extensionConfiguration } from "./utils";
import { Tests, DebugEnvironmentConfiguration } from "./types";
import { Targets, Test, Tests, DebugEnvironmentConfiguration } from "./types";
import { getMesonTests, getMesonTargets } from "./introspection";
import { workspaceState } from "./extension";

// this is far from complete, but should suffice for the
// "test is made of a single executable is made of a single source file" usecase.
function findSourceOfTest(test: Test, targets: Targets) {
const test_exe = test.cmd.at(0);
if (!test_exe) {
return undefined;
}

// the meson target such that it is of meson type executable()
// and produces the binary that the test() executes.
const testDependencyTarget = targets.find((target) => {
const depend = test.depends.find((depend) => {
return depend == target.id && depend.endsWith("@exe");
});
return depend && test_exe == target.filename.at(0);
});

// the first source file belonging to the target.
const path = testDependencyTarget?.target_sources
?.find((elem) => {
return elem.sources;
})
?.sources?.at(0);
return path ? vscode.Uri.file(path) : undefined;
}

export async function rebuildTests(controller: vscode.TestController) {
let tests = await getMesonTests(workspaceState.get<string>("mesonbuild.buildDir")!);
const buildDir = workspaceState.get<string>("mesonbuild.buildDir")!;
const tests = await getMesonTests(buildDir);
const targets = await getMesonTargets(buildDir);

controller.items.forEach((item) => {
if (!tests.some((test) => item.id == test.name)) {
Expand All @@ -15,7 +43,8 @@ export async function rebuildTests(controller: vscode.TestController) {
});

for (let testDescr of tests) {
let testItem = controller.createTestItem(testDescr.name, testDescr.name);
const testSourceFile = findSourceOfTest(testDescr, targets);
const testItem = controller.createTestItem(testDescr.name, testDescr.name, testSourceFile);
controller.items.add(testItem);
}
}
Expand Down

0 comments on commit 1523925

Please sign in to comment.