|
| 1 | +// Exercise the bytes a Windows checkout packages, even when CI runs on Linux. |
| 2 | +const test = require('node:test'); |
| 3 | +const assert = require('node:assert/strict'); |
| 4 | +const { execFileSync, spawnSync } = require('node:child_process'); |
| 5 | +const { cpSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, rmSync, writeFileSync } = require('node:fs'); |
| 6 | +const os = require('node:os'); |
| 7 | +const path = require('node:path'); |
| 8 | + |
| 9 | +test('Windows checkout preserves executable Unix shell integration and login-profile startup', (t) => { |
| 10 | + const root = path.resolve(__dirname, '../..'); |
| 11 | + const fixture = mkdtempSync(path.join(os.tmpdir(), 'dormouse-shell-checkout-')); |
| 12 | + t.after(() => rmSync(fixture, { recursive: true, force: true })); |
| 13 | + const env = Object.fromEntries(Object.entries(process.env).filter(([key]) => !key.startsWith('GIT_'))); |
| 14 | + env.GIT_CONFIG_GLOBAL = os.devNull; |
| 15 | + env.GIT_CONFIG_NOSYSTEM = '1'; |
| 16 | + const git = (...args) => execFileSync('git', [ |
| 17 | + '-c', 'core.autocrlf=true', '-c', 'core.safecrlf=false', |
| 18 | + '-c', `core.attributesFile=${os.devNull}`, ...args, |
| 19 | + ], { cwd: fixture, env, stdio: 'pipe' }); |
| 20 | + const relative = 'standalone/sidecar/shell-integration'; |
| 21 | + cpSync(path.join(root, '.gitattributes'), path.join(fixture, '.gitattributes')); |
| 22 | + cpSync(path.join(root, relative), path.join(fixture, relative), { recursive: true }); |
| 23 | + git('init', '-q'); |
| 24 | + git('add', '.gitattributes', relative); |
| 25 | + const checkout = path.join(fixture, 'Windows checkout'); |
| 26 | + mkdirSync(checkout); |
| 27 | + git('checkout-index', '--all', `--prefix=${checkout}${path.sep}`); |
| 28 | + |
| 29 | + for (const shell of ['bash', 'zsh']) { |
| 30 | + const directory = path.join(checkout, relative, shell); |
| 31 | + for (const file of readdirSync(directory).filter((name) => name !== '.gitignore')) { |
| 32 | + assert.ok(!readFileSync(path.join(directory, file)).includes(Buffer.from('\r\n')), |
| 33 | + `${shell}/${file} must remain LF in a Windows checkout`); |
| 34 | + } |
| 35 | + } |
| 36 | + |
| 37 | + const home = path.join(fixture, 'home'); |
| 38 | + mkdirSync(home); |
| 39 | + writeFileSync(path.join(home, '.bash_profile'), 'export DORMOUSE_TEST_PROFILE=loaded\n'); |
| 40 | + const result = spawnSync('bash', [ |
| 41 | + '--init-file', path.join(checkout, relative, 'bash/shellIntegration.bash'), '-ic', |
| 42 | + 'test "$DORMOUSE_TEST_PROFILE" = loaded && test "$__dormouse_633_installed" = 1', |
| 43 | + ], { |
| 44 | + cwd: home, |
| 45 | + env: { PATH: process.env.PATH, HOME: home, TERM: 'xterm' }, |
| 46 | + encoding: 'utf8', |
| 47 | + timeout: 10000, |
| 48 | + }); |
| 49 | + assert.ifError(result.error); |
| 50 | + assert.equal(result.status, 0, result.stderr); |
| 51 | +}); |
0 commit comments