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

Coverage API behaves oddly with coverage-only runs #208112

Closed
connor4312 opened this issue Mar 19, 2024 · 5 comments · Fixed by #208113
Closed

Coverage API behaves oddly with coverage-only runs #208112

connor4312 opened this issue Mar 19, 2024 · 5 comments · Fixed by #208113
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug testing Built-in testing support verified Verification succeeded
Milestone

Comments

@connor4312
Copy link
Member

          I think I ran into a bug, trying to use the coverage API to integrate coverage data loaded from a file. I am trying to follow the instructions which were previously [provided up-thread](https://github.com/microsoft/vscode/issues/123713#issuecomment-840908164)

Scenario

I am creating two test runs. Those test runs have no test cases attached, they only contain a name, some output (appendOutput) and the coverage data.

Minimal repro
import * as vscode from "vscode";

class BazelCoverageProvider implements vscode.TestCoverageProvider {
  provideFileCoverage(
    token: vscode.CancellationToken,
  ): vscode.ProviderResult<vscode.FileCoverage[]> {
    const detailedCoverage = [
      new vscode.DeclarationCoverage(
        "test_func",
        12,
        new vscode.Position(1, 12),
      ),
      new vscode.DeclarationCoverage(
        "test_func2",
        0,
        new vscode.Position(10, 0),
      ),
      new vscode.StatementCoverage(true, new vscode.Position(15, 3)),
      new vscode.StatementCoverage(false, new vscode.Position(16, 0)),
    ];
    return [
      vscode.FileCoverage.fromDetails(
        vscode.Uri.file("/Users/avogelsgesang/hyper/hyper-db/hyper/ir/IR.cpp"),
        detailedCoverage,
      ),
    ];
  }

  // Already fully resolved. Noting to resolve
  resolveFileCoverage?(
    coverage: vscode.FileCoverage,
    token: vscode.CancellationToken,
  ): vscode.ProviderResult<vscode.FileCoverage> {
    return coverage;
  }
}

export async function activate(context: vscode.ExtensionContext) {
  // Create the test controller
  const testController = vscode.tests.createTestController(
    "bazel-coverage",
    "Bazel Coverage",
  );
  context.subscriptions.push(testController);

  // Provide coverage info 1
  const run = testController.createTestRun(
    new vscode.TestRunRequest(),
    "/my/coverage.lcov",
    false,
  );
  run.appendOutput("Information about where we loaded the coverage from...");
  run.coverageProvider = new BazelCoverageProvider();
  run.end();

  // Provide coverage info 2
  const run2 = testController.createTestRun(
    new vscode.TestRunRequest(),
    "/my/second_coverage.lcov",
    false,
  );
  run2.appendOutput("Some other information...");
  run2.coverageProvider = new BazelCoverageProvider();
  run2.end();
}

Observed behavior

Screenshot 2024-03-05 at 14 34 15

I see two coverage entries in the test result list, and I can switch between them. Also, I see the output from the 2nd test run.

However, I do not see the test run names "/my/coverage.lcov" and "/my/second_coverage.lcov" anywhere. Also, there seems to be no way to see inspect the appendOutput output from the first run.

Expected behavior

I guess the "Close test coverage"/"View test coverage" should be grouped under a test run? Even if there are no tests and only coverage data inside this test run? Also, it would be good to be able to set the overall test run into a "success"/"failed" state, even without listing explicit sub-tests

Originally posted by @vogelsgesang in #123713 (comment)

@connor4312 connor4312 self-assigned this Mar 19, 2024
@connor4312 connor4312 added bug Issue identified by VS Code Team member as probable bug testing Built-in testing support labels Mar 19, 2024
@VSCodeTriageBot VSCodeTriageBot added the unreleased Patch has not yet been released in VS Code Insiders label Mar 19, 2024
@VSCodeTriageBot VSCodeTriageBot added this to the March 2024 milestone Mar 19, 2024
@VSCodeTriageBot VSCodeTriageBot added insiders-released Patch has been released in VS Code Insiders and removed unreleased Patch has not yet been released in VS Code Insiders labels Mar 20, 2024
@DonJayamanne
Copy link
Contributor

@connor4312 unable to verify this, as I cannot find any type defs for TestCoverageProvider
perhaps the API changed

@DonJayamanne DonJayamanne added the verification-steps-needed Steps to verify are needed for verification label Mar 26, 2024
@connor4312
Copy link
Member Author

Just ignore any compilation errors, this will still run since we have back-compat shims still in place for the API as it was when the comment was written.

@connor4312 connor4312 removed the verification-steps-needed Steps to verify are needed for verification label Mar 27, 2024
@meganrogge meganrogge added the verified Verification succeeded label Mar 27, 2024
@meganrogge
Copy link
Contributor

@connor4312 using your minimal repro, I do not see the test names anywhere

Image

@meganrogge meganrogge added verification-found Issue verification failed and removed verified Verification succeeded labels Mar 27, 2024
@meganrogge meganrogge reopened this Mar 27, 2024
@VSCodeTriageBot VSCodeTriageBot removed the insiders-released Patch has been released in VS Code Insiders label Mar 27, 2024
@meganrogge
Copy link
Contributor

Actually, I see this.... is that what is expected?

Image

@connor4312
Copy link
Member Author

You actually verified it correctly. With the shims that's what you expect to see in the tree view. The issue was the coverage node was compressing into the test run itself (as in the original screenshot) and you wouldn't see the "test run at..." header at all.

@meganrogge meganrogge added verified Verification succeeded and removed verification-found Issue verification failed labels Mar 27, 2024
@microsoft microsoft locked and limited conversation to collaborators Jun 10, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug testing Built-in testing support verified Verification succeeded
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants