Skip to content

Commit dc09925

Browse files
committed
Add test for quick-query in .qll fix.
1 parent 5fd2596 commit dc09925

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

extensions/ql-vscode/src/vscode-tests/minimal-workspace/activation.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import * as assert from 'assert';
2+
import * as chai from 'chai';
3+
import * as chaiAsPromised from 'chai-as-promised';
4+
import 'mocha';
25
import * as path from 'path';
36
import * as vscode from 'vscode';
7+
import * as determiningSelectedQueryTest from './determining-selected-query-test';
8+
9+
chai.use(chaiAsPromised);
410

511
describe('launching with a minimal workspace', async () => {
612
const ext = vscode.extensions.getExtension('GitHub.vscode-codeql');
@@ -24,3 +30,5 @@ describe('launching with a minimal workspace', async () => {
2430
}, 1000);
2531
});
2632
});
33+
34+
determiningSelectedQueryTest.run();
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { expect } from 'chai';
2+
import * as path from 'path';
3+
import * as vscode from 'vscode';
4+
import { Uri } from 'vscode';
5+
import { determineSelectedQuery } from '../../run-queries';
6+
7+
async function showQlDocument(name: string): Promise<vscode.TextDocument> {
8+
const folderPath = vscode.workspace.workspaceFolders![0].uri.fsPath;
9+
const documentPath = path.resolve(folderPath, name);
10+
const document = await vscode.workspace.openTextDocument(documentPath);
11+
await vscode.window.showTextDocument(document!);
12+
return document;
13+
}
14+
15+
export function run() {
16+
describe('Determining selected query', async () => {
17+
it('should allow ql files to be queried', async () => {
18+
const q = await determineSelectedQuery(Uri.parse('file:///tmp/queryname.ql'), false);
19+
expect(q.queryPath).to.equal('/tmp/queryname.ql');
20+
expect(q.quickEvalPosition).to.equal(undefined);
21+
});
22+
23+
it('should allow ql files to be quick-evaled', async () => {
24+
const doc = await showQlDocument('query.ql');
25+
const q = await determineSelectedQuery(doc.uri, true);
26+
expect(q.queryPath).to.match(new RegExp('ql-vscode/test/data/query\.ql$'));
27+
});
28+
29+
it('should allow qll files to be quick-evaled', async () => {
30+
const doc = await showQlDocument('library.qll');
31+
const q = await determineSelectedQuery(doc.uri, true);
32+
expect(q.queryPath).to.match(new RegExp('ql-vscode/test/data/library\.qll$'));
33+
});
34+
35+
it('should reject non-ql files when running a query', async () => {
36+
await expect(determineSelectedQuery(Uri.parse('file:///tmp/queryname.txt'), false)).to.be.rejectedWith(Error, 'The selected resource is not a CodeQL query file');
37+
await expect(determineSelectedQuery(Uri.parse('file:///tmp/queryname.qll'), false)).to.be.rejectedWith(Error, 'The selected resource is not a CodeQL query file');
38+
});
39+
40+
it('should reject non-ql[l] files when running a quick eval', async () => {
41+
await expect(determineSelectedQuery(Uri.parse('file:///tmp/queryname.txt'), true)).to.be.rejectedWith(Error, 'The selected resource is not a CodeQL file');
42+
});
43+
});
44+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
predicate foo() {
2+
1 == 1
3+
}

0 commit comments

Comments
 (0)