|
| 1 | +import { describeShellDialect } from "../shellDialect" |
| 2 | + |
| 3 | +describe("describeShellDialect", () => { |
| 4 | + const cmdSyntax = ["`&`", "`&&`", "`%VAR%`", "`set X=Y`", "`%ERRORLEVEL%`", "`!ERRORLEVEL!`"] |
| 5 | + const powershellSyntax = ["`;`", "`$env:VAR`", "`$?`", "`$LASTEXITCODE`"] |
| 6 | + |
| 7 | + it.each([ |
| 8 | + { shell: "C:\\Windows\\System32\\cmd.exe", expected: "cmd.exe", syntax: cmdSyntax }, |
| 9 | + { shell: "C:\\Windows\\System32\\CMD.EXE", expected: "cmd.exe", syntax: cmdSyntax }, |
| 10 | + { shell: "cmd", expected: "cmd.exe", syntax: cmdSyntax }, |
| 11 | + { shell: "C:\\Program Files\\PowerShell\\7\\pwsh.exe", expected: "PowerShell", syntax: powershellSyntax }, |
| 12 | + { |
| 13 | + shell: "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe", |
| 14 | + expected: "PowerShell", |
| 15 | + syntax: powershellSyntax, |
| 16 | + }, |
| 17 | + { shell: "powershell", expected: "PowerShell", syntax: powershellSyntax }, |
| 18 | + { shell: "pwsh", expected: "PowerShell", syntax: powershellSyntax }, |
| 19 | + ])("names the dialect and its syntax for $shell", ({ shell, expected, syntax }) => { |
| 20 | + const description = describeShellDialect(shell) |
| 21 | + |
| 22 | + expect(description).toContain(expected) |
| 23 | + for (const token of syntax) { |
| 24 | + expect(description).toContain(token) |
| 25 | + } |
| 26 | + }) |
| 27 | + |
| 28 | + it("tells PowerShell users that a failed cmdlet does not change $LASTEXITCODE", () => { |
| 29 | + expect(describeShellDialect("pwsh.exe")).toContain("does not change when a cmdlet fails") |
| 30 | + }) |
| 31 | + |
| 32 | + it("warns that ';' does not chain commands in cmd.exe", () => { |
| 33 | + expect(describeShellDialect("C:\\Windows\\System32\\cmd.exe")).toContain("`;` is not a separator") |
| 34 | + }) |
| 35 | + |
| 36 | + it("tells cmd.exe users that %ERRORLEVEL% expands before a chained line runs", () => { |
| 37 | + const description = describeShellDialect("C:\\Windows\\System32\\cmd.exe") |
| 38 | + |
| 39 | + expect(description).toContain("`%ERRORLEVEL%` expands before a chained line runs") |
| 40 | + expect(description).toContain("use `&&` or `||` for same-line success checks") |
| 41 | + expect(description).toContain("enable delayed expansion and use `!ERRORLEVEL!`") |
| 42 | + }) |
| 43 | + |
| 44 | + it.each(["/bin/bash", "/bin/zsh", "C:\\Program Files\\Git\\bin\\bash.exe", "C:\\Windows\\System32\\wsl.exe"])( |
| 45 | + "adds nothing for POSIX shell %s", |
| 46 | + (shell) => { |
| 47 | + expect(describeShellDialect(shell)).toBeUndefined() |
| 48 | + }, |
| 49 | + ) |
| 50 | +}) |
0 commit comments