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'
|
||||
};
|
||||
|
||||
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
|
||||
* databse.
|
||||
|
||||
@@ -6,7 +6,7 @@ import { SemVer } from 'semver';
|
||||
import { CodeQLCliServer, QueryInfoByLanguage } from '../../cli';
|
||||
import { CodeQLExtensionInterface } from '../../extension';
|
||||
import { skipIfNoCodeQL } from '../ensureCli';
|
||||
import { getOnDiskWorkspaceFolders } from '../../helpers';
|
||||
import { getOnDiskWorkspaceFolders, getQlPackForDbscheme, languageToDbScheme } from '../../helpers';
|
||||
import { resolveQueries } from '../../contextual/queryResolver';
|
||||
import { KeyType } from '../../contextual/keyType';
|
||||
|
||||
@@ -14,6 +14,8 @@ import { KeyType } from '../../contextual/keyType';
|
||||
* Perform proper integration tests by running the CLI
|
||||
*/
|
||||
describe('Use cli', function() {
|
||||
const supportedLanguages = ['cpp', 'csharp', 'go', 'java', 'javascript', 'python'];
|
||||
|
||||
this.timeout(60000);
|
||||
|
||||
let cli: CodeQLCliServer;
|
||||
@@ -51,7 +53,7 @@ describe('Use cli', function() {
|
||||
// Depending on the version of the CLI, the qlpacks may have different names
|
||||
// (e.g. "codeql/javascript-all" vs "codeql-javascript"),
|
||||
// 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));
|
||||
}
|
||||
});
|
||||
@@ -59,7 +61,7 @@ describe('Use cli', function() {
|
||||
it('should resolve languages', async function() {
|
||||
skipIfNoCodeQL(this);
|
||||
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;
|
||||
}
|
||||
});
|
||||
@@ -71,15 +73,26 @@ describe('Use cli', function() {
|
||||
expect((Object.keys(queryInfo.byLanguage))[0]).to.eql('javascript');
|
||||
});
|
||||
|
||||
it.only('should resolve printAST queries', async function() {
|
||||
|
||||
supportedLanguages.forEach(lang => {
|
||||
if (lang === 'go') {
|
||||
// The codeql-go submodule is not available in the integration tests.
|
||||
return;
|
||||
}
|
||||
it(`should resolve printAST queries for ${lang}`, async function() {
|
||||
skipIfNoCodeQL(this);
|
||||
|
||||
const result = await resolveQueries(cli, {
|
||||
dbschemePack: 'codeql/javascript-all',
|
||||
dbschemePackIsLibraryPack: true,
|
||||
queryPack: 'codeql/javascript-queries'
|
||||
}, KeyType.PrintAstQuery);
|
||||
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);
|
||||
expect(result[0].endsWith('javascript/ql/src/printAst.ql')).to.be.true;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -30,19 +30,19 @@ describe('queryResolver', () => {
|
||||
});
|
||||
|
||||
describe('resolveQueries', () => {
|
||||
|
||||
it('should resolve a query', async () => {
|
||||
mockCli.resolveQueriesInSuite.returns(['a', 'b']);
|
||||
const result = await module.resolveQueries(mockCli, { dbschemePack: 'my-qlpack' }, KeyType.DefinitionQuery);
|
||||
expect(result).to.deep.equal(['a', 'b']);
|
||||
expect(writeFileSpy.getCall(0).args[0]).to.match(/.qls$/);
|
||||
expect(yaml.safeLoad(writeFileSpy.getCall(0).args[1])).to.deep.equal({
|
||||
qlpack: 'my-qlpack',
|
||||
expect(yaml.safeLoad(writeFileSpy.getCall(0).args[1])).to.deep.equal([{
|
||||
from: 'my-qlpack',
|
||||
queries: '.',
|
||||
include: {
|
||||
kind: 'definitions',
|
||||
'tags contain': 'ide-contextual-queries/local-definitions'
|
||||
}
|
||||
});
|
||||
}]);
|
||||
});
|
||||
|
||||
it('should resolve a query from the queries pack if this is an old CLI', async () => {
|
||||
|
||||
Reference in New Issue
Block a user