Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 51 additions & 1 deletion __tests__/installer/windows.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,57 @@ describe('windows toolchain installation verification', () => {
.mockResolvedValue()
await installer['add']('')
expect(setupSpy).toHaveBeenCalled()
expect(updateSpy).toHaveBeenCalledWith('root')
expect(updateSpy).toHaveBeenCalledWith('root', true)
})

it('tests unpack for failed path matching without additional module setup', async () => {
const installer = new WindowsToolchainInstaller({
name: 'Windows 10',
date: new Date('2023-03-30 10:29:16.000000000 -05:00'),
download: 'swift-6.0.2-RELEASE-windows10.exe',
download_signature: 'swift-6.0.2-RELEASE-windows10.exe.sig',
dir: 'swift-6.0.2-RELEASE',
platform: 'windows10',
branch: 'swift-6.0.2-release',
windows: true,
preventCaching: false
})
const exe = path.resolve('tool', 'downloaded', 'toolchain.exe')
process.env.SystemDrive = 'C:'
jest.spyOn(exec, 'exec').mockResolvedValue(0)
jest
.spyOn(exec, 'getExecOutput')
.mockResolvedValueOnce({exitCode: 0, stdout: '{}', stderr: ''})
.mockResolvedValueOnce({exitCode: 0, stdout: '{"PATH":"a"}', stderr: ''})
.mockResolvedValueOnce({exitCode: 0, stdout: '{}', stderr: ''})
.mockResolvedValue({
exitCode: 0,
stdout: `{"SDKROOT":"root","PATH":"a${path.delimiter}b${path.delimiter}c"}`,
stderr: ''
})
jest
.spyOn(fs, 'access')
.mockRejectedValueOnce(new Error())
.mockRejectedValueOnce(new Error())
.mockResolvedValue()
jest.spyOn(fs, 'cp').mockRejectedValue(new Error())
const addPathSpy = jest.spyOn(core, 'addPath')
const exportVariableSpy = jest.spyOn(core, 'exportVariable')
await expect(installer['unpack'](exe)).resolves.toBe('')
expect(addPathSpy).toHaveBeenCalledTimes(2)
expect(exportVariableSpy).toHaveBeenCalledTimes(1)
expect(addPathSpy.mock.calls).toStrictEqual([['b'], ['c']])
expect(exportVariableSpy.mock.calls).toStrictEqual([['SDKROOT', 'root']])

const setupSpy = jest
.spyOn(VisualStudio, 'setup')
.mockResolvedValue(visualStudio)
const updateSpy = jest
.spyOn(VisualStudio.prototype, 'update')
.mockResolvedValue()
await installer['add']('')
expect(setupSpy).toHaveBeenCalled()
expect(updateSpy).toHaveBeenCalledWith('root', false)
})

it('tests add to PATH', async () => {
Expand Down
13 changes: 7 additions & 6 deletions __tests__/version.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {escapeRegExp} from 'lodash'
import {
ToolchainVersion,
SemanticToolchainVersion,
Expand Down Expand Up @@ -53,7 +54,7 @@ describe('parse version from provided string', () => {
expect(version.requiresSwiftOrg).toBe(true)
const sVersion = version as SemanticToolchainVersion
expect(sVersion['dirGlob']).toBe('swift-5_0*')
expect(sVersion['dirRegex']).toStrictEqual(/swift-5.0/)
expect(sVersion['dirRegex']).toStrictEqual(/swift-5\.0/)
})

it('parses X.0.0 semver', async () => {
Expand All @@ -63,7 +64,7 @@ describe('parse version from provided string', () => {
expect(version.requiresSwiftOrg).toBe(true)
const sVersion = version as SemanticToolchainVersion
expect(sVersion['dirGlob']).toBe('swift-5_0-*')
expect(sVersion['dirRegex']).toStrictEqual(/swift-5.0-/)
expect(sVersion['dirRegex']).toStrictEqual(/swift-5\.0-/)
})

it('parses X.X semver', async () => {
Expand All @@ -73,7 +74,7 @@ describe('parse version from provided string', () => {
expect(version.requiresSwiftOrg).toBe(true)
const sVersion = version as SemanticToolchainVersion
expect(sVersion['dirGlob']).toBe('swift-5_5*')
expect(sVersion['dirRegex']).toStrictEqual(/swift-5.5/)
expect(sVersion['dirRegex']).toStrictEqual(/swift-5\.5/)
})

it('parses X.X.0 semver', async () => {
Expand All @@ -83,7 +84,7 @@ describe('parse version from provided string', () => {
expect(version.requiresSwiftOrg).toBe(true)
const sVersion = version as SemanticToolchainVersion
expect(sVersion['dirGlob']).toBe('swift-5_5-*')
expect(sVersion['dirRegex']).toStrictEqual(/swift-5.5-/)
expect(sVersion['dirRegex']).toStrictEqual(/swift-5\.5-/)
})

it('parses X.X.X semver', async () => {
Expand All @@ -93,7 +94,7 @@ describe('parse version from provided string', () => {
expect(version.requiresSwiftOrg).toBe(true)
const sVersion = version as SemanticToolchainVersion
expect(sVersion['dirGlob']).toBe('swift-5_5_1*')
expect(sVersion['dirRegex']).toStrictEqual(/swift-5.5.1/)
expect(sVersion['dirRegex']).toStrictEqual(/swift-5\.5\.1/)
})

it('parses toolchain name', async () => {
Expand All @@ -116,7 +117,7 @@ describe('parse version from provided string', () => {
expect(version.requiresSwiftOrg).toBe(true)
const lVersion = version as ToolchainSnapshotName
expect(lVersion['dirGlob']).toBe('swift-5_9-*')
expect(lVersion['dirRegex']).toStrictEqual(new RegExp(name))
expect(lVersion['dirRegex']).toStrictEqual(new RegExp(escapeRegExp(name)))
})

it('parses toolchain URL', async () => {
Expand Down
Loading