Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add running InteropTests to CI #34

Merged
merged 6 commits into from
Dec 3, 2023
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
21 changes: 19 additions & 2 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
name: Build & Test

on: [push]
on:
pull_request:
branches:
- main
push:
branches:
- main
workflow_dispatch:

jobs:
build:
Expand Down Expand Up @@ -35,4 +42,14 @@ jobs:

- name: Test support module
shell: pwsh
run: swift test --verbose --skip-build
run: swift test --verbose --skip-build

- name: Build InteropTests
working-directory: InteropTests
shell: pwsh
run: '& .\Build.ps1'

- name: Run InteropTests
working-directory: InteropTests
shell: pwsh
run: '& .\Run.ps1'
30 changes: 28 additions & 2 deletions InteropTests/Build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ param(
[switch] $Release
)

Set-StrictMode -Version 3
$ErrorActionPreference = "Stop"

$SwiftConfiguration = if ($Release) { "release" } else { "debug" }
$MSBuildConfiguration = if ($Release) { "Release" } else { "Debug" }

Expand Down Expand Up @@ -35,6 +38,9 @@ Write-Host -ForegroundColor Cyan "Generating Swift projection for WinRT componen
--out "$PSScriptRoot\Generated"
if ($LASTEXITCODE -ne 0) { throw "Failed to generate Swift projection for WinRT component" }

Write-Host -ForegroundColor Cyan "Copying Package.swift for the generated code..."
Copy-Item -Path "$PSScriptRoot\GeneratedPackage.swift" -Destination "$PSScriptRoot\Generated\Package.swift" -Force

Write-Host -ForegroundColor Cyan "Building Swift test package..."
$SwiftTestPackageDir = $PSScriptRoot
& swift.exe build `
Expand All @@ -49,7 +55,27 @@ Write-Host -ForegroundColor Cyan "Embedding the WinRT component activation manif
& mt.exe -nologo `
-manifest $PSScriptRoot\Activation.manifest `
-outputresource:$SwiftTestBuildOutputDir\InteropTestsPackageTests.xctest
if ($LASTEXITCODE -ne 0) { throw "Failed to embed WinRT component activation manifest in the test executable" }
if ($LASTEXITCODE -ne 0) { throw "Failed to embed WinRT component activation manifest in the test executable" }

Write-Host -ForegroundColor Cyan "Copying the WinRT component dll next to the test..."
Copy-Item -Path $TestComponentDir\WinRTComponent.dll -Destination $SwiftTestBuildOutputDir -Force
Copy-Item -Path $TestComponentDir\WinRTComponent.dll -Destination $SwiftTestBuildOutputDir -Force

Write-Host -ForegroundColor Cyan "Copying XCTest.dll next to the test..."
# Swift 5.9:
# C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swift.exe
# C:\Library\Developer\Platforms\Windows.platform\Developer\Library\XCTest-development\usr\bin64\XCTest.dll
# Swift 5.10+:
# %localappdata%\Programs\Swift\Toolchains\0.0.0+Asserts\usr\bin\swift.exe
# %localappdata%\Programs\Swift\Platforms\0.0.0\Windows.platform\Developer\Library\XCTest-development\usr\bin64\XCTest.dll
$SwiftExePath = @(& where.exe swift.exe)[0]
$SwiftToolchainPathPrefixMatch = [regex]::Match($SwiftExePath, "^(.*)\\Toolchains\\(\d+\.\d+\.\d+)?")
if (!$SwiftToolchainPathPrefixMatch.Success) { throw "Unexpected Swift toolchain path." }

$SwiftToolchainInstallDir = $SwiftToolchainPathPrefixMatch.Groups[1].Value
$SwiftToolchainVersionGroup = $SwiftToolchainPathPrefixMatch.Groups[2]

$XCTestDllPath = "$SwiftToolchainInstallDir\Platforms"
if ($SwiftToolchainVersionGroup.Success) { $XCTestDllPath += "\$($SwiftToolchainVersionGroup.Value)" }
$XCTestDllPath += "\Windows.platform\Developer\Library\XCTest-development\usr\bin64\XCTest.dll"

Copy-Item -Path $XCTestDllPath -Destination $SwiftTestBuildOutputDir -Force
30 changes: 30 additions & 0 deletions InteropTests/GeneratedPackage.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// swift-tools-version: 5.9

// TODO(#10): Swift/WinRT should generate this Package.swift file
import PackageDescription

let package = Package(
name: "Generated",
products: [
.library(
name: "Projection",
targets: [
"WinRTComponent"
]),
],
dependencies: [
.package(path: "../.."),
],
targets: [
.target(
name: "CWinRT",
path: "CWinRT"),
.target(
name: "WinRTComponent",
dependencies: [
"CWinRT",
.product(name: "WindowsRuntime", package: "swift-winrt")
],
path: "WinRTComponent/Assembly")
]
)
15 changes: 15 additions & 0 deletions InteropTests/Run.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
param(
[switch] $Release
)

Set-StrictMode -Version 3
$ErrorActionPreference = "Stop"

$SwiftConfiguration = if ($Release) { "release" } else { "debug" }

$OriginalPathExt = $env:PATHEXT
$env:PATHEXT += ";.xctest"
& $PSScriptRoot\.build\$SwiftConfiguration\InteropTestsPackageTests.xctest
$env:PATHEXT = $OriginalPathExt

if ($LASTEXITCODE -ne 0) { throw "Failure running interop tests" }