Skip to content

Commit e099fe6

Browse files
committed
Add failing test case
1 parent 5e66bd2 commit e099fe6

File tree

4 files changed

+54
-6
lines changed

4 files changed

+54
-6
lines changed

server/src/__tests__/analyzer.test.ts

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ let analyzer: Analyzer
1818
const CURRENT_URI = 'dummy-uri.sh'
1919

2020
// if you add a .sh file to testing/fixtures, update this value
21-
const FIXTURE_FILES_MATCHING_GLOB = 16
21+
const FIXTURE_FILES_MATCHING_GLOB = 17
2222

2323
const defaultConfig = getDefaultConfiguration()
2424

@@ -28,12 +28,33 @@ jest.spyOn(Logger.prototype, 'log').mockImplementation(() => {
2828
const loggerInfo = jest.spyOn(Logger.prototype, 'info')
2929
const loggerWarn = jest.spyOn(Logger.prototype, 'warn')
3030

31-
beforeAll(async () => {
31+
async function getAnalyzer({
32+
includeAllWorkspaceSymbols = false,
33+
workspaceFolder = FIXTURE_FOLDER,
34+
runBackgroundAnalysis = false,
35+
}: {
36+
includeAllWorkspaceSymbols?: boolean
37+
workspaceFolder?: string
38+
runBackgroundAnalysis?: boolean
39+
}) {
3240
const parser = await initializeParser()
33-
analyzer = new Analyzer({
41+
42+
const analyzer = new Analyzer({
3443
parser,
35-
workspaceFolder: FIXTURE_FOLDER,
44+
includeAllWorkspaceSymbols,
45+
workspaceFolder,
3646
})
47+
if (runBackgroundAnalysis) {
48+
await analyzer.initiateBackgroundAnalysis({
49+
backgroundAnalysisMaxFiles: defaultConfig.backgroundAnalysisMaxFiles,
50+
globPattern: defaultConfig.globPattern,
51+
})
52+
}
53+
return analyzer
54+
}
55+
56+
beforeAll(async () => {
57+
analyzer = await getAnalyzer({})
3758
})
3859

3960
describe('analyze', () => {
@@ -355,7 +376,6 @@ describe('findAllSourcedUris', () => {
355376
new Set([
356377
`file://${FIXTURE_FOLDER}extension.inc`,
357378
`file://${FIXTURE_FOLDER}issue101.sh`,
358-
`file://${FIXTURE_FOLDER}sourcing.sh`,
359379
]),
360380
)
361381
})
@@ -578,6 +598,27 @@ describe('findDeclarationsMatchingWord', () => {
578598
`)
579599
})
580600

601+
it('resolves sourced file not covered by the background analysis glob', async () => {
602+
async function expectThatSourcingWorksWhenIncludeAllWorkspaceSymbolsIs(v: boolean) {
603+
const analyzer = await getAnalyzer({
604+
runBackgroundAnalysis: true,
605+
includeAllWorkspaceSymbols: v,
606+
})
607+
608+
expect(
609+
analyzer.findDeclarationsMatchingWord({
610+
word: 'XXX',
611+
uri: FIXTURE_URI.SOURCING2,
612+
exactMatch: true,
613+
position: { line: 2, character: 21 }, // XXX
614+
}),
615+
).toHaveLength(1)
616+
}
617+
618+
await expectThatSourcingWorksWhenIncludeAllWorkspaceSymbolsIs(false)
619+
await expectThatSourcingWorksWhenIncludeAllWorkspaceSymbolsIs(true)
620+
})
621+
581622
it('returns symbols depending on the scope', async () => {
582623
const parser = await initializeParser()
583624

testing/fixtures.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export const FIXTURE_URI = {
3030
SCOPE: `file://${path.join(FIXTURE_FOLDER, 'scope.sh')}`,
3131
SHELLCHECK_SOURCE: `file://${path.join(FIXTURE_FOLDER, 'shellcheck', 'source.sh')}`,
3232
SOURCING: `file://${path.join(FIXTURE_FOLDER, 'sourcing.sh')}`,
33+
SOURCING2: `file://${path.join(FIXTURE_FOLDER, 'sourcing2.sh')}`,
3334
}
3435

3536
export const FIXTURE_DOCUMENT: Record<FIXTURE_KEY, TextDocument> = (

testing/fixtures/extension

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#!/bin/sh
22

3-
. sourcing.sh
3+
. ./extension.inc
44

55
echo "It works, but is not parsed initially"
6+
7+
# A little variable
8+
export XXX=1

testing/fixtures/sourcing2.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
. ./extension # notice no file extension meaning it isn't found by the background analysis
2+
3+
echo "It resolves ${XXX} in the sourced file"

0 commit comments

Comments
 (0)