-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Chore: Add integration tests for completion
- Loading branch information
1 parent
c6903bf
commit 936b777
Showing
2 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
integration-tests/project-folder/sources/meta-fixtures/completion.bb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
DESCRIPTION = 'FOO' | ||
|
||
python do_foo(){ | ||
print('123') | ||
} | ||
|
||
do_bar(){ | ||
echo '123' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* -------------------------------------------------------------------------------------------- | ||
* Copyright (c) 2023 Savoir-faire Linux. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
* ------------------------------------------------------------------------------------------ */ | ||
|
||
import * as assert from 'assert' | ||
import * as vscode from 'vscode' | ||
import path from 'path' | ||
|
||
async function delay (ms: number): Promise<void> { | ||
await new Promise(resolve => setTimeout(resolve, ms)) | ||
} | ||
|
||
suite('Bitbake Completion Test Suite', () => { | ||
const filePath = path.resolve(__dirname, '../../project-folder/sources/meta-fixtures/completion.bb') | ||
const docUri = vscode.Uri.parse(`file://${filePath}`) | ||
|
||
suiteSetup(async function (this: Mocha.Context) { | ||
this.timeout(100000) | ||
const vscodeBitbake = vscode.extensions.getExtension('yocto-project.yocto-bitbake') | ||
if (vscodeBitbake === undefined) { | ||
assert.fail('Bitbake extension is not available') | ||
} | ||
await vscodeBitbake.activate() | ||
await vscode.workspace.openTextDocument(docUri) | ||
}) | ||
|
||
const checkHasItemWithLabel = (completionList: vscode.CompletionList, label: string): boolean => { | ||
return completionList.items.some(item => { | ||
if (typeof item.label === 'string') { | ||
return item.label === label | ||
} | ||
return item.label.label === label | ||
}) | ||
} | ||
|
||
const testCompletion = async (position: vscode.Position, expected: string): Promise<void> => { | ||
let completionList: vscode.CompletionList = { items: [] } | ||
while (!checkHasItemWithLabel(completionList, expected)) { | ||
completionList = await vscode.commands.executeCommand<vscode.CompletionList>( | ||
'vscode.executeCompletionItemProvider', | ||
docUri, | ||
position | ||
) | ||
// For completion to work, an "embedded language document" needs to be generated. | ||
// We have no practical way to know when it will be done. | ||
// Attempts to wait for the "embedded language document" to be created in its folder still produced incorrect results. | ||
// So here we are, just hoping everything is fine so our test won't take forever to fail. | ||
await delay(100) | ||
} | ||
assert.strictEqual(checkHasItemWithLabel(completionList, expected), true) | ||
} | ||
|
||
test('Completion appears properly on bitbake variable', async () => { | ||
const position = new vscode.Position(0, 2) | ||
const expected = 'DESCRIPTION' | ||
await testCompletion(position, expected) | ||
}).timeout(300000) | ||
|
||
test('Completion appears properly on embedded python', async () => { | ||
const position = new vscode.Position(3, 6) | ||
const expected = 'print' | ||
await testCompletion(position, expected) | ||
}).timeout(300000) | ||
|
||
test('Completion appears properly on embedded bash', async () => { | ||
const position = new vscode.Position(7, 6) | ||
const expected = 'echo' | ||
await testCompletion(position, expected) | ||
}).timeout(300000) | ||
}) |