From b94d98099523ff46b91dc9334b27c72d880ff352 Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Tue, 9 May 2023 13:33:46 -0700 Subject: [PATCH 1/4] Add support for Windows Treat windows similar to Linux - use `FoundationXML` for the import. This allows building SWXMLHash on Windows. --- Source/FullXMLParser.swift | 2 +- Source/LazyXMLParser.swift | 2 +- Tests/SWXMLHashTests/XMLParsingTests.swift | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/FullXMLParser.swift b/Source/FullXMLParser.swift index 99cfaf7e..ed91ce4a 100644 --- a/Source/FullXMLParser.swift +++ b/Source/FullXMLParser.swift @@ -25,7 +25,7 @@ import Foundation -#if os(Linux) +#if os(Linux) || os(Windows) import FoundationXML #endif diff --git a/Source/LazyXMLParser.swift b/Source/LazyXMLParser.swift index c074f438..dd9d2ffd 100644 --- a/Source/LazyXMLParser.swift +++ b/Source/LazyXMLParser.swift @@ -25,7 +25,7 @@ import Foundation -#if os(Linux) +#if os(Linux) || os(Windows) import FoundationXML #endif diff --git a/Tests/SWXMLHashTests/XMLParsingTests.swift b/Tests/SWXMLHashTests/XMLParsingTests.swift index b6ca92f2..05686b60 100644 --- a/Tests/SWXMLHashTests/XMLParsingTests.swift +++ b/Tests/SWXMLHashTests/XMLParsingTests.swift @@ -375,7 +375,7 @@ class XMLParsingTests: XCTestCase { XCTAssertNotNil(err) -#if !os(Linux) +#if !(os(Linux) || os(Windows)) if err != nil { XCTAssert(err!.line == 1) } From 985865fbe23d8fa22b1e6772bf36765d19cd98b4 Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Tue, 9 May 2023 13:35:35 -0700 Subject: [PATCH 2/4] Tests: repair tests on Windows Windows does not use `/` for the path separator and may use mixed path spellings. Use `URL(fileURLWithPath:)` to create an `URL` and use that to construct the path to read the source input from. This enables passing the test suite on Windows. --- Tests/SWXMLHashTests/LazyWhiteSpaceParsingTests.swift | 2 +- Tests/SWXMLHashTests/WhiteSpaceParsingTests.swift | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/SWXMLHashTests/LazyWhiteSpaceParsingTests.swift b/Tests/SWXMLHashTests/LazyWhiteSpaceParsingTests.swift index 90f3a062..0e40832e 100644 --- a/Tests/SWXMLHashTests/LazyWhiteSpaceParsingTests.swift +++ b/Tests/SWXMLHashTests/LazyWhiteSpaceParsingTests.swift @@ -38,7 +38,7 @@ class LazyWhiteSpaceParsingTests: XCTestCase { // Put setup code here. This method is called before the invocation of each test method in the class. #if SWIFT_PACKAGE - let path = NSString.path(withComponents: NSString(string: #file).pathComponents.dropLast() + ["test.xml"]) + let path = URL(fileURLWithPath: #file).deletingLastPathComponent().appendingPathComponent("test.xml").path #else let bundle = Bundle(for: WhiteSpaceParsingTests.self) let path = bundle.path(forResource: "test", ofType: "xml")! diff --git a/Tests/SWXMLHashTests/WhiteSpaceParsingTests.swift b/Tests/SWXMLHashTests/WhiteSpaceParsingTests.swift index 21f569ea..66f5a26c 100644 --- a/Tests/SWXMLHashTests/WhiteSpaceParsingTests.swift +++ b/Tests/SWXMLHashTests/WhiteSpaceParsingTests.swift @@ -37,7 +37,7 @@ class WhiteSpaceParsingTests: XCTestCase { super.setUp() // Put setup code here. This method is called before the invocation of each test method in the class. #if SWIFT_PACKAGE - let path = NSString.path(withComponents: NSString(string: #file).pathComponents.dropLast() + ["test.xml"]) + let path = URL(fileURLWithPath: #file).deletingLastPathComponent().appendingPathComponent("test.xml").path #else let bundle = Bundle(for: WhiteSpaceParsingTests.self) let path = bundle.path(forResource: "test", ofType: "xml")! From 7f22a9d93c00a31b40f9d53bc4a040c4d998afc0 Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Tue, 9 May 2023 13:41:27 -0700 Subject: [PATCH 3/4] GHA: add a Windows test workflow Add a Windows build and test workflow to match the other platforms. --- .github/workflows/main.yml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 88461295..e9429e3d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -33,3 +33,18 @@ jobs: run: | eval "$(curl -sL https://gist.githubusercontent.com/kylef/5c0475ff02b7c7671d2a/raw/9f442512a46d7a2af7b850d65a7e9bd31edfb09b/swiftenv-install.sh)" swift test + + windows-test: + name: Windows Test + runs-on: windows-latest + + steps: + - name: Install Swift + uses: compnerd/gha-setup-swift@main + with: + branch: swift-5.8-release + tag: 5.8-RELEASE + - name: Checkout + uses: actions/checkout@master + - name: Build and test + run: swift test From 85470827ed70c8a8bc3369da8988ff7a333e28a1 Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Tue, 9 May 2023 17:15:00 -0700 Subject: [PATCH 4/4] gitattributes: always checkout the test content in Unix line endings The windows line endings cause test failures as the expectation is written for Unix line endings. --- .gitattributes | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000..280866bc --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +*.xml text eol=lf