mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-11-01 20:31:59 +00:00
iterative dependency solver
First, we go through every environment variable key and record all cases where there are reference to other variables / dependencies. We track two sets of variables - resolved and yet-to-be-resolved. We pass over a list of variables over and over again and when all variable's dependencies were resolved during previous passes we perform a replacement for that variable, too. Over time the size of `toResolve` set should go down to zero, however circular dependencies may prevent that. We track the size of `toResolve` between iterations to avoid infinite looping. At the end we produce an object of the same size and shape as the original, but with the values replace with resolved versions.
This commit is contained in:
parent
18d2fb81a7
commit
a86db5d0d1
2 changed files with 88 additions and 0 deletions
41
editors/code/tests/unit/settings.test.ts
Normal file
41
editors/code/tests/unit/settings.test.ts
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
import * as assert from 'assert';
|
||||
import { Context } from '.';
|
||||
import { substituteVariablesInEnv } from '../../src/config';
|
||||
|
||||
export async function getTests(ctx: Context) {
|
||||
await ctx.suite('Server Env Settings', suite => {
|
||||
suite.addTest('Replacing Env Variables', async () => {
|
||||
const envJson = {
|
||||
USING_MY_VAR: "${env:MY_VAR} test ${env:MY_VAR}",
|
||||
MY_VAR: "test"
|
||||
};
|
||||
const expectedEnv = {
|
||||
USING_MY_VAR: "test test test",
|
||||
MY_VAR: "test"
|
||||
};
|
||||
const actualEnv = await substituteVariablesInEnv(envJson);
|
||||
assert.deepStrictEqual(actualEnv, expectedEnv);
|
||||
});
|
||||
|
||||
suite.addTest('Circular dependencies remain as is', async () => {
|
||||
const envJson = {
|
||||
A_USES_B: "${env:B_USES_A}",
|
||||
B_USES_A: "${env:A_USES_B}",
|
||||
C_USES_ITSELF: "${env:C_USES_ITSELF}",
|
||||
D_USES_C: "${env:C_USES_ITSELF}",
|
||||
E_IS_ISOLATED: "test",
|
||||
F_USES_E: "${env:E_IS_ISOLATED}"
|
||||
};
|
||||
const expectedEnv = {
|
||||
A_USES_B: "${env:B_USES_A}",
|
||||
B_USES_A: "${env:A_USES_B}",
|
||||
C_USES_ITSELF: "${env:C_USES_ITSELF}",
|
||||
D_USES_C: "${env:C_USES_ITSELF}",
|
||||
E_IS_ISOLATED: "test",
|
||||
F_USES_E: "test"
|
||||
};
|
||||
const actualEnv = await substituteVariablesInEnv(envJson);
|
||||
assert.deepStrictEqual(actualEnv, expectedEnv);
|
||||
});
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue