Skip to content

[stdlib] Port StdlibUnittest to FreeBSD. #902

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

Merged
merged 1 commit into from
Jan 7, 2016
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
2 changes: 1 addition & 1 deletion stdlib/private/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
endif()
endif()

if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
if(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
add_subdirectory(StdlibUnittest)
add_subdirectory(SwiftPrivateDarwinExtras)
add_subdirectory(SwiftPrivatePthreadExtras)
Expand Down
2 changes: 1 addition & 1 deletion stdlib/private/StdlibUnittest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ if(SWIFT_HOST_VARIANT MATCHES "${SWIFT_DARWIN_VARIANTS}")
list(APPEND swift_stdlib_unittest_framework_depends
Foundation)
endif()
if(SWIFT_HOST_VARIANT STREQUAL "linux")
if(SWIFT_HOST_VARIANT STREQUAL "linux" OR SWIFT_HOST_VARIANT STREQUAL "FreeBSD")
list(APPEND swift_stdlib_unittest_module_depends
Glibc)
endif()
Expand Down
20 changes: 19 additions & 1 deletion stdlib/private/StdlibUnittest/StdlibUnittest.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import SwiftPrivateDarwinExtras

#if os(OSX) || os(iOS) || os(watchOS) || os(tvOS)
import Darwin
#elseif os(Linux)
#elseif os(Linux) || os(FreeBSD)
import Glibc
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm OK with this in the short term, but as we discussed before, Glibc is not the right module name on FreeBSD.

#endif

Expand Down Expand Up @@ -992,6 +992,7 @@ public enum OSVersion : CustomStringConvertible {
case TVOSSimulator
case watchOSSimulator
case Linux
case FreeBSD

public var description: String {
switch self {
Expand All @@ -1011,6 +1012,8 @@ public enum OSVersion : CustomStringConvertible {
return "watchOSSimulator"
case Linux:
return "Linux"
case FreeBSD:
return "FreeBSD"
}
}
}
Expand Down Expand Up @@ -1043,6 +1046,8 @@ func _getOSVersion() -> OSVersion {
return .watchOSSimulator
#elseif os(Linux)
return .Linux
#elseif os(FreeBSD)
return .FreeBSD
#else
let productVersion = _stdlib_getSystemVersionPlistProperty("ProductVersion")!
let (major, minor, bugFix) = _parseDottedVersionTriple(productVersion)
Expand Down Expand Up @@ -1112,6 +1117,8 @@ public enum TestRunPredicate : CustomStringConvertible {

case LinuxAny(reason: String)

case FreeBSDAny(reason: String)

public var description: String {
switch self {
case Custom(_, let reason):
Expand Down Expand Up @@ -1179,6 +1186,9 @@ public enum TestRunPredicate : CustomStringConvertible {

case LinuxAny(reason: let reason):
return "LinuxAny(*, reason: \(reason))"

case FreeBSDAny(reason: let reason):
return "FreeBSDAny(*, reason: \(reason))"
}
}

Expand Down Expand Up @@ -1410,6 +1420,14 @@ public enum TestRunPredicate : CustomStringConvertible {
default:
return false
}

case FreeBSDAny:
switch _getRunningOSVersion() {
case .FreeBSD:
return true
default:
return false
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion stdlib/private/SwiftPrivateDarwinExtras/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set(swift_private_darwin_extras_module_depends
if(SWIFT_HOST_VARIANT MATCHES "${SWIFT_DARWIN_VARIANTS}")
list(APPEND swift_private_darwin_extras_module_depends
Darwin)
elseif(SWIFT_HOST_VARIANT STREQUAL "linux")
elseif(SWIFT_HOST_VARIANT STREQUAL "linux" OR SWIFT_HOST_VARIANT STREQUAL "FreeBSD")
list(APPEND swift_private_darwin_extras_module_depends
Glibc)
endif()
Expand Down
2 changes: 1 addition & 1 deletion stdlib/private/SwiftPrivateDarwinExtras/Subprocess.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import SwiftPrivate
#if os(OSX) || os(iOS) || os(watchOS) || os(tvOS)
import Darwin
#elseif os(Linux)
#elseif os(Linux) || os(FreeBSD)
import Glibc
#endif

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import SwiftPrivate
#if os(OSX) || os(iOS) || os(watchOS) || os(tvOS)
import Darwin
#elseif os(Linux)
#elseif os(Linux) || os(FreeBSD)
import Glibc
#endif

Expand Down
2 changes: 1 addition & 1 deletion stdlib/private/SwiftPrivatePthreadExtras/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ set(swift_private_pthread_extras_module_depends)
if(SWIFT_HOST_VARIANT MATCHES "${SWIFT_DARWIN_VARIANTS}")
list(APPEND swift_private_pthread_extras_module_depends
Darwin)
elseif(SWIFT_HOST_VARIANT STREQUAL "linux")
elseif(SWIFT_HOST_VARIANT STREQUAL "linux" OR SWIFT_HOST_VARIANT STREQUAL "FreeBSD")
list(APPEND swift_private_pthread_extras_module_depends
Glibc)
endif()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

#if os(OSX) || os(iOS) || os(watchOS) || os(tvOS)
import Darwin
#elseif os(Linux)
#elseif os(Linux) || os(FreeBSD)
import Glibc
#endif

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

#if os(OSX) || os(iOS) || os(watchOS) || os(tvOS)
import Darwin
#elseif os(Linux)
#elseif os(Linux) || os(FreeBSD)
import Glibc
#endif

Expand Down
34 changes: 34 additions & 0 deletions validation-test/stdlib/StdlibUnittestFreeBSD.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// RUN: %target-run-stdlib-swift | FileCheck %s
// REQUIRES: executable_test

import Swift
import StdlibUnittest

// Also import modules which are used by StdlibUnittest internally. This
// workaround is needed to link all required libraries in case we compile
// StdlibUnittest with -sil-serialize-all.
import SwiftPrivate
#if _runtime(_ObjC)
import ObjectiveC
#endif

_setOverrideOSVersion(.FreeBSD)
_setTestSuiteFailedCallback() { print("abort()") }

var XFailsFreeBSD = TestSuite("XFailsFreeBSD")

// CHECK: [ UXPASS ] XFailsFreeBSD.xfail FreeBSD passes{{$}}
XFailsFreeBSD.test("xfail FreeBSD passes").xfail(.FreeBSDAny(reason: "")).code {
expectEqual(1, 1)
}

// CHECK: [ XFAIL ] XFailsFreeBSD.xfail FreeBSD fails{{$}}
XFailsFreeBSD.test("xfail FreeBSD fails").xfail(.FreeBSDAny(reason: "")).code {
expectEqual(1, 2)
}

// CHECK: XFailsFreeBSD: Some tests failed, aborting
// CHECK: abort()

runAllTests()