|
1 | 1 | /* eslint-disable no-unused-expressions */ |
2 | | -import { readKitsFile, getShellScriptEnvironment } from '@cmt/kits/kit'; |
| 2 | +import { readKitsFile, getShellScriptEnvironment, effectiveKitEnvironment } from '@cmt/kits/kit'; |
3 | 3 | import { expect } from '@test/util'; |
4 | 4 | import * as path from 'path'; |
5 | 5 | import paths from '@cmt/paths'; |
@@ -93,4 +93,57 @@ suite('Kits test', () => { |
93 | 93 | expect(env_vars_arr).to.deep.include(['TESTVAR13', 'cde']); |
94 | 94 | } |
95 | 95 | }); |
| 96 | + |
| 97 | + test('Test environmentVariables expand using environmentSetupScript output', async () => { |
| 98 | + const fname_extension = process.platform === 'win32' ? 'bat' : 'sh'; |
| 99 | + const fname = `cmake-kit-test-${Math.random().toString()}.${fname_extension}`; |
| 100 | + const script_path = path.join(paths.tmpDir, fname); |
| 101 | + const pathSeparator = process.platform === 'win32' ? ';' : ':'; |
| 102 | + const basePath = process.platform === 'win32' ? 'C:\\base-path' : '/base-path'; |
| 103 | + const scriptPath = process.platform === 'win32' ? 'C:\\script-path' : '/script-path'; |
| 104 | + const appendedPath = process.platform === 'win32' ? 'C:\\env-var-path' : '/env-var-path'; |
| 105 | + |
| 106 | + process.env.PATH = basePath; |
| 107 | + |
| 108 | + if (process.platform === 'win32') { |
| 109 | + await fs.writeFile(script_path, `set "PATH=${scriptPath};%PATH%"`); |
| 110 | + } else { |
| 111 | + await fs.writeFile(script_path, `export PATH="${scriptPath}:$PATH"`); |
| 112 | + } |
| 113 | + |
| 114 | + const kit = { |
| 115 | + name: 'Test Kit 3', |
| 116 | + environmentSetupScript: script_path, |
| 117 | + environmentVariables: { |
| 118 | + PATH: `\${env:PATH}${pathSeparator}${appendedPath}` |
| 119 | + }, |
| 120 | + isTrusted: true |
| 121 | + }; |
| 122 | + |
| 123 | + const setupOnlyKit = { |
| 124 | + name: 'Test Kit 3 setup-only', |
| 125 | + environmentSetupScript: script_path, |
| 126 | + isTrusted: true |
| 127 | + }; |
| 128 | + |
| 129 | + const setup_env_vars = await getShellScriptEnvironment(setupOnlyKit); |
| 130 | + expect(setup_env_vars).to.not.be.undefined; |
| 131 | + |
| 132 | + const env_vars = await effectiveKitEnvironment(kit); |
| 133 | + await fs.unlink(script_path); |
| 134 | + |
| 135 | + const normalizePathList = (value: string | undefined): string[] => { |
| 136 | + expect(value).to.not.eq(undefined); |
| 137 | + const parts = (value ?? '').split(pathSeparator); |
| 138 | + if (process.platform !== 'win32') { |
| 139 | + return parts; |
| 140 | + } |
| 141 | + |
| 142 | + // cmd/set can emit PATH entries with different slash and drive-letter casing. |
| 143 | + return parts.map(part => path.win32.normalize(part).toLowerCase()); |
| 144 | + }; |
| 145 | + |
| 146 | + expect(normalizePathList(setup_env_vars?.PATH)).to.deep.eq(normalizePathList(`${scriptPath}${pathSeparator}${basePath}`)); |
| 147 | + expect(normalizePathList(env_vars.PATH)).to.deep.eq(normalizePathList(`${scriptPath}${pathSeparator}${basePath}${pathSeparator}${appendedPath}`)); |
| 148 | + }); |
96 | 149 | }); |
0 commit comments