Expand qlpack resolution integration test to all languages
Go is not yet supported since we do not include the go submodule in the integration tests.
This commit is contained in:
committed by
Dave Bartolomeo
parent
c2d3829a72
commit
210d8a3c64
@@ -423,6 +423,12 @@ const dbSchemeToLanguage = {
|
|||||||
'go.dbscheme': 'go'
|
'go.dbscheme': 'go'
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const languageToDbScheme = Object.entries(dbSchemeToLanguage).reduce((acc, [k, v]) => {
|
||||||
|
acc[v] = k;
|
||||||
|
return acc;
|
||||||
|
}, {} as { [k: string]: string });
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the initial contents for an empty query, based on the language of the selected
|
* Returns the initial contents for an empty query, based on the language of the selected
|
||||||
* databse.
|
* databse.
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import { SemVer } from 'semver';
|
|||||||
import { CodeQLCliServer, QueryInfoByLanguage } from '../../cli';
|
import { CodeQLCliServer, QueryInfoByLanguage } from '../../cli';
|
||||||
import { CodeQLExtensionInterface } from '../../extension';
|
import { CodeQLExtensionInterface } from '../../extension';
|
||||||
import { skipIfNoCodeQL } from '../ensureCli';
|
import { skipIfNoCodeQL } from '../ensureCli';
|
||||||
import { getOnDiskWorkspaceFolders } from '../../helpers';
|
import { getOnDiskWorkspaceFolders, getQlPackForDbscheme, languageToDbScheme } from '../../helpers';
|
||||||
import { resolveQueries } from '../../contextual/queryResolver';
|
import { resolveQueries } from '../../contextual/queryResolver';
|
||||||
import { KeyType } from '../../contextual/keyType';
|
import { KeyType } from '../../contextual/keyType';
|
||||||
|
|
||||||
@@ -14,6 +14,8 @@ import { KeyType } from '../../contextual/keyType';
|
|||||||
* Perform proper integration tests by running the CLI
|
* Perform proper integration tests by running the CLI
|
||||||
*/
|
*/
|
||||||
describe('Use cli', function() {
|
describe('Use cli', function() {
|
||||||
|
const supportedLanguages = ['cpp', 'csharp', 'go', 'java', 'javascript', 'python'];
|
||||||
|
|
||||||
this.timeout(60000);
|
this.timeout(60000);
|
||||||
|
|
||||||
let cli: CodeQLCliServer;
|
let cli: CodeQLCliServer;
|
||||||
@@ -51,7 +53,7 @@ describe('Use cli', function() {
|
|||||||
// Depending on the version of the CLI, the qlpacks may have different names
|
// Depending on the version of the CLI, the qlpacks may have different names
|
||||||
// (e.g. "codeql/javascript-all" vs "codeql-javascript"),
|
// (e.g. "codeql/javascript-all" vs "codeql-javascript"),
|
||||||
// so we just check that the expected languages are included.
|
// so we just check that the expected languages are included.
|
||||||
for (const expectedLanguage of ['cpp', 'csharp', 'go', 'java', 'javascript', 'python']) {
|
for (const expectedLanguage of supportedLanguages) {
|
||||||
expect((Object.keys(qlpacks)).includes(expectedLanguage));
|
expect((Object.keys(qlpacks)).includes(expectedLanguage));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -59,7 +61,7 @@ describe('Use cli', function() {
|
|||||||
it('should resolve languages', async function() {
|
it('should resolve languages', async function() {
|
||||||
skipIfNoCodeQL(this);
|
skipIfNoCodeQL(this);
|
||||||
const languages = await cli.resolveLanguages();
|
const languages = await cli.resolveLanguages();
|
||||||
for (const expectedLanguage of ['cpp', 'csharp', 'go', 'java', 'javascript', 'python']) {
|
for (const expectedLanguage of supportedLanguages) {
|
||||||
expect(languages).to.have.property(expectedLanguage).that.is.not.undefined;
|
expect(languages).to.have.property(expectedLanguage).that.is.not.undefined;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -71,15 +73,26 @@ describe('Use cli', function() {
|
|||||||
expect((Object.keys(queryInfo.byLanguage))[0]).to.eql('javascript');
|
expect((Object.keys(queryInfo.byLanguage))[0]).to.eql('javascript');
|
||||||
});
|
});
|
||||||
|
|
||||||
it.only('should resolve printAST queries', async function() {
|
|
||||||
skipIfNoCodeQL(this);
|
|
||||||
|
|
||||||
const result = await resolveQueries(cli, {
|
supportedLanguages.forEach(lang => {
|
||||||
dbschemePack: 'codeql/javascript-all',
|
if (lang === 'go') {
|
||||||
dbschemePackIsLibraryPack: true,
|
// The codeql-go submodule is not available in the integration tests.
|
||||||
queryPack: 'codeql/javascript-queries'
|
return;
|
||||||
}, KeyType.PrintAstQuery);
|
}
|
||||||
expect(result.length).to.eq(1);
|
it(`should resolve printAST queries for ${lang}`, async function() {
|
||||||
expect(result[0].endsWith('javascript/ql/src/printAst.ql')).to.be.true;
|
skipIfNoCodeQL(this);
|
||||||
|
|
||||||
|
const pack = await getQlPackForDbscheme(cli, languageToDbScheme[lang]);
|
||||||
|
expect(pack.dbschemePack).to.contain(lang);
|
||||||
|
if (pack.dbschemePackIsLibraryPack) {
|
||||||
|
expect(pack.queryPack).to.contain(lang);
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await resolveQueries(cli, pack, KeyType.PrintAstQuery);
|
||||||
|
|
||||||
|
// It doesn't matter what the name or path of the query is, only
|
||||||
|
// that we have found exactly one query.
|
||||||
|
expect(result.length).to.eq(1);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -30,19 +30,19 @@ describe('queryResolver', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('resolveQueries', () => {
|
describe('resolveQueries', () => {
|
||||||
|
|
||||||
it('should resolve a query', async () => {
|
it('should resolve a query', async () => {
|
||||||
mockCli.resolveQueriesInSuite.returns(['a', 'b']);
|
mockCli.resolveQueriesInSuite.returns(['a', 'b']);
|
||||||
const result = await module.resolveQueries(mockCli, { dbschemePack: 'my-qlpack' }, KeyType.DefinitionQuery);
|
const result = await module.resolveQueries(mockCli, { dbschemePack: 'my-qlpack' }, KeyType.DefinitionQuery);
|
||||||
expect(result).to.deep.equal(['a', 'b']);
|
expect(result).to.deep.equal(['a', 'b']);
|
||||||
expect(writeFileSpy.getCall(0).args[0]).to.match(/.qls$/);
|
expect(writeFileSpy.getCall(0).args[0]).to.match(/.qls$/);
|
||||||
expect(yaml.safeLoad(writeFileSpy.getCall(0).args[1])).to.deep.equal({
|
expect(yaml.safeLoad(writeFileSpy.getCall(0).args[1])).to.deep.equal([{
|
||||||
qlpack: 'my-qlpack',
|
from: 'my-qlpack',
|
||||||
|
queries: '.',
|
||||||
include: {
|
include: {
|
||||||
kind: 'definitions',
|
kind: 'definitions',
|
||||||
'tags contain': 'ide-contextual-queries/local-definitions'
|
'tags contain': 'ide-contextual-queries/local-definitions'
|
||||||
}
|
}
|
||||||
});
|
}]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should resolve a query from the queries pack if this is an old CLI', async () => {
|
it('should resolve a query from the queries pack if this is an old CLI', async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user