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 2f8a1f9 commit 0f7074b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
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

0 comments on commit 0f7074b

Please sign in to comment.