Skip to content

Commit ed5dc69

Browse files
committed
Add query running test for computeDefaultStrings flag
1 parent 2f8a1f9 commit ed5dc69

4 files changed

Lines changed: 36 additions & 21 deletions

File tree

extensions/ql-vscode/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
## [UNRELEASED]
44

55
- Fix bug when removing databases where sometimes the source folder would not be removed from the workspace or the database files would not be removed from the workspace storage location. [#692](https://github.com/github/vscode-codeql/pull/692)
6-
- Always pass the `computeDefaultStrings` flag to query compilation commands. This will change the output of some queries. [#694](https://github.com/github/vscode-codeql/pull/694)
6+
- Query results with no string representation will now be displayed with placeholder text in query results. Previously, they were omitted. [#694](https://github.com/github/vscode-codeql/pull/694)
77

88
## 1.3.7 - 24 November 2020
99

extensions/ql-vscode/src/vscode-tests/no-workspace/query-test.ts renamed to extensions/ql-vscode/src/vscode-tests/no-workspace/query.test.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ import { ColumnValue } from '../../pure/bqrs-cli-types';
1313
import { FindDistributionResultKind } from '../../distribution';
1414

1515

16-
declare module 'url' {
17-
export function pathToFileURL(urlStr: string): Url;
18-
}
16+
const baseDir = path.join(__dirname, '../../../test/data');
1917

2018
const tmpDir = tmp.dirSync({ prefix: 'query_test_', keep: false, unsafeCleanup: true });
2119

@@ -61,21 +59,27 @@ type QueryTestCase = {
6159
// Test cases: queries to run and their expected results.
6260
const queryTestCases: QueryTestCase[] = [
6361
{
64-
queryPath: path.join(__dirname, '../data/query.ql'),
62+
queryPath: path.join(baseDir, 'query.ql'),
6563
expectedResultSets: {
6664
'#select': [[42, 3.14159, 'hello world', true]]
6765
}
6866
},
6967
{
70-
queryPath: path.join(__dirname, '../data/multiple-result-sets.ql'),
68+
queryPath: path.join(baseDir, 'compute-default-strings.ql'),
69+
expectedResultSets: {
70+
'#select': [[{ label: '(no string representation)' }]]
71+
}
72+
},
73+
{
74+
queryPath: path.join(baseDir, 'multiple-result-sets.ql'),
7175
expectedResultSets: {
7276
'edges': [[1, 2], [2, 3]],
7377
'#select': [['s']]
7478
}
7579
}
7680
];
7781

78-
describe('using the query server', function() {
82+
describe.only('using the query server', function() {
7983
before(function() {
8084
if (process.env['CODEQL_PATH'] === undefined) {
8185
console.log('The environment variable CODEQL_PATH is not set. The query server tests, which require the CodeQL CLI, will be skipped.');
@@ -92,12 +96,8 @@ describe('using the query server', function() {
9296
let cliServer: cli.CodeQLCliServer;
9397
const queryServerStarted = new Checkpoint<void>();
9498
after(() => {
95-
if (qs) {
96-
qs.dispose();
97-
}
98-
if (cliServer) {
99-
cliServer.dispose();
100-
}
99+
qs?.dispose();
100+
cliServer?.dispose();
101101
});
102102

103103
it('should be able to start the query server', async function() {
@@ -156,7 +156,7 @@ describe('using the query server', function() {
156156
try {
157157
const qlProgram: messages.QlProgram = {
158158
libraryPath: [],
159-
dbschemePath: path.join(__dirname, '../data/test.dbscheme'),
159+
dbschemePath: path.join(baseDir, 'test.dbscheme'),
160160
queryPath: queryTestCase.queryPath
161161
};
162162
const params: messages.CompileQueryParams = {
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Test that computeDefaultStrings is set correctly.
2+
3+
newtype TUnit = MkUnit()
4+
5+
class Unit extends TUnit {
6+
Unit() { this = MkUnit() }
7+
8+
string toString() { none() }
9+
}
10+
11+
from Unit u
12+
select u

extensions/ql-vscode/test/pure-tests/files.test.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,12 @@ describe('files', () => {
4747
});
4848

4949
it('should scan a directory', async () => {
50-
const singleFile = path.join(dataDir, 'query.ql');
51-
const otherFile = path.join(dataDir, 'multiple-result-sets.ql');
50+
const file1 = path.join(dataDir, 'compute-default-strings.ql');
51+
const file2 = path.join(dataDir, 'multiple-result-sets.ql');
52+
const file3 = path.join(dataDir, 'query.ql');
5253

5354
const result = await gatherQlFiles([dataDir]);
54-
expect(result.sort()).to.deep.equal([[otherFile, singleFile], true]);
55+
expect(result.sort()).to.deep.equal([[file1, file2, file3], true]);
5556
});
5657

5758
it('should scan a directory and some files', async () => {
@@ -64,10 +65,12 @@ describe('files', () => {
6465
});
6566

6667
it('should avoid duplicates', async () => {
67-
const singleFile = path.join(dataDir, 'query.ql');
68-
const otherFile = path.join(dataDir, 'multiple-result-sets.ql');
68+
const file1 = path.join(dataDir, 'compute-default-strings.ql');
69+
const file2 = path.join(dataDir, 'multiple-result-sets.ql');
70+
const file3 = path.join(dataDir, 'query.ql');
6971

70-
const result = await gatherQlFiles([singleFile, dataDir, otherFile]);
71-
expect(result.sort()).to.deep.equal([[singleFile, otherFile], true]);
72+
const result = await gatherQlFiles([file1, dataDir, file3]);
73+
result[0].sort();
74+
expect(result.sort()).to.deep.equal([[file1, file2, file3], true]);
7275
});
7376
});

0 commit comments

Comments
 (0)