Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass computeDefaultStrings to query server when compiling queries #694

Merged
merged 3 commits into from
Dec 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions extensions/ql-vscode/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +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)
- 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
5 changes: 5 additions & 0 deletions extensions/ql-vscode/src/pure/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ export interface CompilationOptions {
* Whether to disable toString values in the results.
*/
noComputeToString: boolean;
/**
* Whether to ensure that elements that do not have a displayString
* get reported anyway. Useful for universal compilation options.
*/
computeDefaultStrings: boolean;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Future work: This makes me think we should have an internal integration test, which checks the external and internal copies of this protocol are in sync.

}

/**
Expand Down
1 change: 1 addition & 0 deletions extensions/ql-vscode/src/run-queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ export class QueryInfo {
localChecking: false,
noComputeGetUrl: false,
noComputeToString: false,
computeDefaultStrings: true
},
extraOptions: {
timeoutSecs: qs.config.timeoutSecs
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'),
adityasharad marked this conversation as resolved.
Show resolved Hide resolved
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 All @@ -168,6 +168,7 @@ describe('using the query server', function() {
localChecking: false,
noComputeGetUrl: false,
noComputeToString: false,
computeDefaultStrings: true
},
queryToCheck: qlProgram,
resultPath: COMPILED_QUERY_PATH,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ describe('run-queries', () => {
localChecking: false,
noComputeGetUrl: false,
noComputeToString: false,
computeDefaultStrings: true
},
extraOptions: {
timeoutSecs: 5
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]);
});
});