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
26 changes: 24 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,41 @@ on:
permissions:
contents: read

env:
SWIFT_VERSION: '6.2'

jobs:
test:
name: Run Tests
runs-on: macos-latest
runs-on: ${{ matrix.os }}
strategy:
matrix:
os:
- macos-latest
- ubuntu-22.04
- windows-2022

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Swift
if: matrix.os != 'windows-2022'
uses: swift-actions/setup-swift@v2
with:
swift-version: '6.2'
swift-version: ${{ env.SWIFT_VERSION }}

- name: Setup Swift (Windows)
if: matrix.os == 'windows-2022'
uses: SwiftyLab/setup-swift@latest
with:
swift-version: ${{ env.SWIFT_VERSION }}

- name: Run Swift tests
if: matrix.os != 'windows-2022'
run: swift test

- name: Run Swift tests
if: matrix.os == 'windows-2022'
run: swift test
shell: bash
26 changes: 26 additions & 0 deletions Tests/GameCLITests/RunLogPersistenceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import Foundation
import XCTest
@testable import GameCLI

#if os(Windows)
import WinSDK
#endif

final class RunLogPersistenceTests: XCTestCase {
func testRunLogService_stripsANSIAndAddsTimestamp() {
print("🧪 测试:testRunLogService_stripsANSIAndAddsTimestamp")
Expand Down Expand Up @@ -39,6 +43,13 @@ final class RunLogPersistenceTests: XCTestCase {
defer { try? FileManager.default.removeItem(at: tmp) }

let key = "SALU_DATA_DIR"
#if os(Windows)
let old = ProcessInfo.processInfo.environment[key]
defer {
setEnvironmentVariable(key, old)
}
setEnvironmentVariable(key, tmp.path)
#else
let old = getenv(key).flatMap { String(cString: $0) }
defer {
if let old {
Expand All @@ -48,6 +59,7 @@ final class RunLogPersistenceTests: XCTestCase {
}
}
setenv(key, tmp.path, 1)
#endif

let store = FileRunLogStore()
store.appendLine("line1\n")
Expand Down Expand Up @@ -91,3 +103,17 @@ private final class InMemoryRunLogStore: RunLogStore, @unchecked Sendable {
clearCount += 1
}
}

#if os(Windows)
private func setEnvironmentVariable(_ key: String, _ value: String?) {
let result: Bool = key.withCString(encodedAs: UTF16.self) { keyPtr in
if let value {
return value.withCString(encodedAs: UTF16.self) { valuePtr in
SetEnvironmentVariableW(keyPtr, valuePtr)
}
}
return SetEnvironmentVariableW(keyPtr, nil)
}
XCTAssertTrue(result, "Failed to set environment variable \(key)")
}
#endif
8 changes: 8 additions & 0 deletions Tests/GameCLITests/ScreenAndRoomCoverageTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ import XCTest
@testable import GameCLI
import GameCore

#if os(Windows)
final class ScreenAndRoomCoverageTests: XCTestCase {
func testWindowsSkip() throws {
throw XCTSkip("Screen output capture uses POSIX APIs that are unavailable on Windows.")
}
}
#else
#if canImport(Darwin)
@preconcurrency import Darwin
#else
Expand Down Expand Up @@ -199,6 +206,7 @@ final class ScreenAndRoomCoverageTests: XCTestCase {
XCTAssertEqual(store.records.first?.won, true)
}
}
#endif

private extension String {
func strippingANSICodes() -> String {
Expand Down
Loading