|
1 | 1 | import { describeShellDialect } from "../shellDialect" |
2 | 2 |
|
3 | 3 | describe("describeShellDialect", () => { |
| 4 | + const cmdSyntax = ["`&`", "`&&`", "`%VAR%`", "`set X=Y`", "`%ERRORLEVEL%`"] |
| 5 | + const powershellSyntax = ["`;`", "`$env:VAR`", "`$?`", "`$LASTEXITCODE`"] |
| 6 | + |
4 | 7 | it.each([ |
5 | | - { shell: "C:\\Windows\\System32\\cmd.exe", expected: "cmd.exe" }, |
6 | | - { shell: "C:\\Windows\\System32\\CMD.EXE", expected: "cmd.exe" }, |
7 | | - { shell: "C:\\Program Files\\PowerShell\\7\\pwsh.exe", expected: "PowerShell" }, |
8 | | - { shell: "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe", expected: "PowerShell" }, |
9 | | - ])("names the dialect for $shell", ({ shell, expected }) => { |
10 | | - expect(describeShellDialect(shell)).toContain(expected) |
| 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: "C:\\Program Files\\PowerShell\\7\\pwsh.exe", expected: "PowerShell", syntax: powershellSyntax }, |
| 11 | + { |
| 12 | + shell: "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe", |
| 13 | + expected: "PowerShell", |
| 14 | + syntax: powershellSyntax, |
| 15 | + }, |
| 16 | + ])("names the dialect and its syntax for $shell", ({ shell, expected, syntax }) => { |
| 17 | + const description = describeShellDialect(shell) |
| 18 | + |
| 19 | + expect(description).toContain(expected) |
| 20 | + for (const token of syntax) { |
| 21 | + expect(description).toContain(token) |
| 22 | + } |
| 23 | + }) |
| 24 | + |
| 25 | + it("tells PowerShell users that a failed cmdlet does not change $LASTEXITCODE", () => { |
| 26 | + expect(describeShellDialect("pwsh.exe")).toContain("does not change when a cmdlet fails") |
11 | 27 | }) |
12 | 28 |
|
13 | 29 | it("warns that ';' does not chain commands in cmd.exe", () => { |
|
0 commit comments