Skip to content

Commit

Permalink
Add query running test for computeDefaultStrings flag
Browse files Browse the repository at this point in the history
  • Loading branch information
aeisenberg committed Dec 1, 2020
1 parent 6afb946 commit 3c08baf
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 21 deletions.
2 changes: 1 addition & 1 deletion extensions/ql-vscode/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## [UNRELEASED]

- 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)
- 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)
- 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)

## 1.3.7 - 24 November 2020

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ import { ColumnValue } from '../../pure/bqrs-cli-types';
import { FindDistributionResultKind } from '../../distribution';


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

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

Expand Down Expand Up @@ -61,21 +59,27 @@ type QueryTestCase = {
// Test cases: queries to run and their expected results.
const queryTestCases: QueryTestCase[] = [
{
queryPath: path.join(__dirname, '../data/query.ql'),
queryPath: path.join(baseDir, 'query.ql'),
expectedResultSets: {
'#select': [[42, 3.14159, 'hello world', true]]
}
},
{
queryPath: path.join(__dirname, '../data/multiple-result-sets.ql'),
queryPath: path.join(baseDir, 'compute-default-strings.ql'),
expectedResultSets: {
'#select': [[{ label: '(no string representation)' }]]
}
},
{
queryPath: path.join(baseDir, 'multiple-result-sets.ql'),
expectedResultSets: {
'edges': [[1, 2], [2, 3]],
'#select': [['s']]
}
}
];

describe('using the query server', function() {
describe.only('using the query server', function() {
before(function() {
if (process.env['CODEQL_PATH'] === undefined) {
console.log('The environment variable CODEQL_PATH is not set. The query server tests, which require the CodeQL CLI, will be skipped.');
Expand All @@ -92,12 +96,8 @@ describe('using the query server', function() {
let cliServer: cli.CodeQLCliServer;
const queryServerStarted = new Checkpoint<void>();
after(() => {
if (qs) {
qs.dispose();
}
if (cliServer) {
cliServer.dispose();
}
qs?.dispose();
cliServer?.dispose();
});

it('should be able to start the query server', async function() {
Expand Down Expand Up @@ -156,7 +156,7 @@ describe('using the query server', function() {
try {
const qlProgram: messages.QlProgram = {
libraryPath: [],
dbschemePath: path.join(__dirname, '../data/test.dbscheme'),
dbschemePath: path.join(baseDir, 'test.dbscheme'),
queryPath: queryTestCase.queryPath
};
const params: messages.CompileQueryParams = {
Expand Down
12 changes: 12 additions & 0 deletions extensions/ql-vscode/test/data/compute-default-strings.ql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Test that computeDefaultStrings is set correctly.

newtype TUnit = MkUnit()

class Unit extends TUnit {
Unit() { this = MkUnit() }

string toString() { none() }
}

from Unit u
select u
17 changes: 10 additions & 7 deletions extensions/ql-vscode/test/pure-tests/files.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,12 @@ describe('files', () => {
});

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

const result = await gatherQlFiles([dataDir]);
expect(result.sort()).to.deep.equal([[otherFile, singleFile], true]);
expect(result.sort()).to.deep.equal([[file1, file2, file3], true]);
});

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

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

const result = await gatherQlFiles([singleFile, dataDir, otherFile]);
expect(result.sort()).to.deep.equal([[singleFile, otherFile], true]);
const result = await gatherQlFiles([file1, dataDir, file3]);
result[0].sort();
expect(result.sort()).to.deep.equal([[file1, file2, file3], true]);
});
});

0 comments on commit 3c08baf

Please sign in to comment.