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

Return tests discovered by workspace/tests and textDocument/tests in a hierarchical format #1149

Merged
merged 2 commits into from
Apr 11, 2024

Conversation

ahoppen
Copy link
Collaborator

@ahoppen ahoppen commented Mar 28, 2024

This ways the client doesn’t need to create a hierarchical structure using the container names. It is also more flexible and allows nesting of test suites + the addition of labels and tags for swift-testing.

The data structure for TestItem has been heavily inspired by VS Code’s TestItem for the test explorer, which should make it fairly straightforward to integrate these results into the VS Code test explorer.

A known limitation is that the test IDs are currently not qualified by the module name. I’m planning to implement this soon via a follow-up PR (#1150).

Definition of TestItem in VS Code

/**
 * An item shown in the "test explorer" view.
 *
 * A `TestItem` can represent either a test suite or a test itself, since
 * they both have similar capabilities.
 */
export interface TestItem {
    /**
     * Identifier for the `TestItem`. This is used to correlate
     * test results and tests in the document with those in the workspace
     * (test explorer). This cannot change for the lifetime of the `TestItem`,
     * and must be unique among its parent's direct children.
     */
    readonly id: string;

    /**
     * URI this `TestItem` is associated with. May be a file or directory.
     */
    readonly uri: Uri | undefined;

    /**
     * The children of this test item. For a test suite, this may contain the
     * individual test cases or nested suites.
     */
    readonly children: TestItemCollection;

    /**
     * The parent of this item. It's set automatically, and is undefined
     * top-level items in the {@link TestController.items} and for items that
     * aren't yet included in another item's {@link TestItem.children children}.
     */
    readonly parent: TestItem | undefined;

    /**
     * Tags associated with this test item. May be used in combination with
     * {@link TestRunProfile.tags}, or simply as an organizational feature.
     */
    tags: readonly TestTag[];

    /**
     * Indicates whether this test item may have children discovered by resolving.
     *
     * If true, this item is shown as expandable in the Test Explorer view and
     * expanding the item will cause {@link TestController.resolveHandler}
     * to be invoked with the item.
     *
     * Default to `false`.
     */
    canResolveChildren: boolean;

    /**
     * Controls whether the item is shown as "busy" in the Test Explorer view.
     * This is useful for showing status while discovering children.
     *
     * Defaults to `false`.
     */
    busy: boolean;

    /**
     * Display name describing the test case.
     */
    label: string;

    /**
     * Optional description that appears next to the label.
     */
    description?: string;

    /**
     * A string that should be used when comparing this item
     * with other items. When `falsy` the {@link TestItem.label label}
     * is used.
     */
    sortText?: string | undefined;

    /**
     * Location of the test item in its {@link TestItem.uri uri}.
     *
     * This is only meaningful if the `uri` points to a file.
     */
    range: Range | undefined;

    /**
     * Optional error encountered while loading the test.
     *
     * Note that this is not a test result and should only be used to represent errors in
     * test discovery, such as syntax errors.
     */
    error: string | MarkdownString | undefined;
}

/**
 * Tags can be associated with {@link TestItem TestItems} and
 * {@link TestRunProfile TestRunProfiles}. A profile with a tag can only
 * execute tests that include that tag in their {@link TestItem.tags} array.
 */
export class TestTag {
    /**
     * ID of the test tag. `TestTag` instances with the same ID are considered
     * to be identical.
     */
    readonly id: string;

    /**
     * Creates a new TestTag instance.
     * @param id ID of the test tag.
     */
    constructor(id: string);
}

@ahoppen ahoppen requested a review from bnbarham March 28, 2024 14:15
@ahoppen ahoppen changed the title Return tests discovered by workspace/tests and textDocument/tests in a hierarchical format 🚥 #1148 Return tests discovered by workspace/tests and textDocument/tests in a hierarchical format Apr 2, 2024
@ahoppen ahoppen marked this pull request as ready for review April 3, 2024 02:03
@ahoppen
Copy link
Collaborator Author

ahoppen commented Apr 3, 2024

@swift-ci Please test

@ahoppen
Copy link
Collaborator Author

ahoppen commented Apr 4, 2024

@swift-ci Please test

@ahoppen
Copy link
Collaborator Author

ahoppen commented Apr 4, 2024

@swift-ci Please test Windows

This ways the client doesn’t need to create a hierarchical structure using the container names. It is also more flexible and allows nesting of test suites + the addition of labels and tags for swift-testing.

The data structure for `TestItem` has been heavily inspired by VS Code’s `TestItem` for the test explorer, which should make it fairly straightforward to integrate these results into the VS Code test explorer.
Same as for workspace tests, instead of returning a flat list of symbols, return a hierarchical structure.
@ahoppen
Copy link
Collaborator Author

ahoppen commented Apr 6, 2024

@swift-ci Please test

@ahoppen
Copy link
Collaborator Author

ahoppen commented Apr 11, 2024

@swift-ci Please test Windows

@ahoppen ahoppen merged commit 15189bb into apple:main Apr 11, 2024
3 checks passed
@ahoppen ahoppen deleted the ahoppen/structured-tests branch April 11, 2024 18:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants