Skip to content

Commit

Permalink
tests: implement TODO-marked tests
Browse files Browse the repository at this point in the history
Signed-off-by: Joseph Benden <joe@benden.us>
  • Loading branch information
jbenden committed Sep 11, 2022
1 parent 0329b84 commit 9560349
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Added

- Allow diagnostic code lookup via the web. See #143.
- Implemented the missing tests involving `c_cpp_properties.json`.

### Changed

Expand Down
55 changes: 47 additions & 8 deletions specs/suite/unit-c_cpp_properties.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,28 +35,67 @@ describe('c_cpp_properties.json unit-tests', () => {

let document: vscode.TextDocument;

beforeAll(async () => {
beforeEach(async () => {
await vscode.commands.executeCommand('vscode.openFolder', vscode.Uri.file(workspaceFolder));

document = await vscode.workspace.openTextDocument(vscode.Uri.file(filePath));

await vscode.window.showTextDocument(document);
});

afterAll(async () => {
afterEach(async () => {
await vscode.commands.executeCommand('workbench.action.closeActiveEditor');
});

test.todo('it should handle plain includePaths setting');
async function getDocumentSettings(document: vscode.TextDocument): Promise<FlylintSettings> {
return (await RobustPromises.retry(42, // # of attempts
1000, // delay between retries
1000, // timeout for a try
() => vscode.commands.executeCommand('c-cpp-flylint.getLocalConfig', document))) as FlylintSettings;
}

test('it should handle non-existing includePaths setting', async () => {
// WHEN
let config: FlylintSettings = await getDocumentSettings(document);

// THEN: simple checks against the set of includePaths
expect(config).toBeDefined();
expect(config.includePaths.length).toBeGreaterThan(2);

test.todo('it should handle non-existing includePaths setting');
// and then: a known set of directories are in the set of all includePaths
expect(config.includePaths).not.toEqual(
expect.arrayContaining(
[
expect.stringMatching(/\/usr\/lib\/gcc\/x86_64-linux-gnu\/5\/include/),
expect.stringMatching(/\$\{workspaceRoot}/),
expect.stringMatching(/^$/)
]
)
);
});

test('it should handle plain includePaths setting', async () => {
// WHEN
let config: FlylintSettings = await getDocumentSettings(document);

// THEN: simple checks against the set of includePaths
expect(config).toBeDefined();
expect(config.includePaths.length).toBeGreaterThan(2);

// and then: a known set of directories are in the set of all includePaths
expect(config.includePaths).toEqual(
expect.arrayContaining(
[
expect.stringMatching(/a$/),
expect.stringMatching(/\/usr\/include$/)
]
)
);
});

test('it should handle glob expansion of includePaths setting', async () => {
// WHEN
let config: FlylintSettings = (await RobustPromises.retry(42, // # of attempts
1000, // delay between retries
1000, // timeout for a try
() => vscode.commands.executeCommand('c-cpp-flylint.getLocalConfig', document))) as FlylintSettings;
let config: FlylintSettings = await getDocumentSettings(document);

// THEN: simple checks against the set of includePaths
expect(config).toBeDefined();
Expand Down

0 comments on commit 9560349

Please sign in to comment.