mirror of
https://github.com/samsonjs/samhuri.net.git
synced 2026-03-25 09:05:47 +00:00
Migrate from XCTest to Swift Testing
This commit is contained in:
parent
3b2d4c6440
commit
ecd9ad3b3e
9 changed files with 108 additions and 175 deletions
|
|
@ -1,7 +0,0 @@
|
|||
import XCTest
|
||||
|
||||
import gensiteTests
|
||||
|
||||
var tests = [XCTestCaseEntry]()
|
||||
tests += gensiteTests.allTests()
|
||||
XCTMain(tests)
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
import XCTest
|
||||
|
||||
#if !canImport(ObjectiveC)
|
||||
public func allTests() -> [XCTestCaseEntry] {
|
||||
return [
|
||||
testCase(gensiteTests.allTests),
|
||||
]
|
||||
}
|
||||
#endif
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
import XCTest
|
||||
import class Foundation.Bundle
|
||||
@testable import gensite
|
||||
import Testing
|
||||
|
||||
final class gensiteTests: XCTestCase {
|
||||
static var allTests = [(String, XCTestCase)]()
|
||||
struct gensiteTests {
|
||||
@Test func example() {
|
||||
#expect(true)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +0,0 @@
|
|||
import XCTest
|
||||
|
||||
import samhuri.net.Tests
|
||||
|
||||
var tests = [XCTestCaseEntry]()
|
||||
tests += samhuri.net.Tests.allTests()
|
||||
XCTMain(tests)
|
||||
|
|
@ -5,41 +5,33 @@
|
|||
// Created by Sami Samhuri on 2019-12-31.
|
||||
//
|
||||
|
||||
import XCTest
|
||||
import Foundation
|
||||
@testable import samhuri_net
|
||||
import Testing
|
||||
|
||||
extension Date {
|
||||
final class Tests: XCTestCase {
|
||||
var date: Date!
|
||||
class DateSugarTests {
|
||||
let date: Date
|
||||
|
||||
override func setUp() {
|
||||
var calendar = Calendar(identifier: .gregorian)
|
||||
calendar.timeZone = TimeZone(secondsFromGMT: 0)!
|
||||
Date.defaultCalendar = calendar
|
||||
date = Date(timeIntervalSince1970: 0)
|
||||
}
|
||||
init() {
|
||||
var calendar = Calendar(identifier: .gregorian)
|
||||
calendar.timeZone = TimeZone(secondsFromGMT: 0)!
|
||||
Date.defaultCalendar = calendar
|
||||
date = Date(timeIntervalSince1970: 0)
|
||||
}
|
||||
|
||||
override func tearDown() {
|
||||
Date.defaultCalendar = .current
|
||||
date = nil
|
||||
}
|
||||
deinit {
|
||||
Date.defaultCalendar = .current
|
||||
}
|
||||
|
||||
func testYear() {
|
||||
XCTAssertEqual(1970, date.year)
|
||||
}
|
||||
@Test func year() {
|
||||
#expect(date.year == 1970)
|
||||
}
|
||||
|
||||
func testMonth() {
|
||||
XCTAssertEqual(1, date.month)
|
||||
}
|
||||
@Test func month() {
|
||||
#expect(date.month == 1)
|
||||
}
|
||||
|
||||
func testDay() {
|
||||
XCTAssertEqual(1, date.day)
|
||||
}
|
||||
|
||||
static var allTests = [
|
||||
("testYear", testYear),
|
||||
("testMonth", testMonth),
|
||||
("testDay", testDay),
|
||||
]
|
||||
@Test func day() {
|
||||
#expect(date.day == 1)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,59 +5,49 @@
|
|||
// Created by Sami Samhuri on 2019-12-31.
|
||||
//
|
||||
|
||||
import XCTest
|
||||
@testable import samhuri_net
|
||||
import Testing
|
||||
|
||||
extension FilePermissions {
|
||||
final class Tests: XCTestCase {
|
||||
func testDescription() {
|
||||
XCTAssertEqual("---------", FilePermissions(user: "---", group: "---", other: "---").description)
|
||||
XCTAssertEqual("r--r--r--", FilePermissions(user: "r--", group: "r--", other: "r--").description)
|
||||
XCTAssertEqual("-w--w--w-", FilePermissions(user: "-w-", group: "-w-", other: "-w-").description)
|
||||
XCTAssertEqual("--x--x--x", FilePermissions(user: "--x", group: "--x", other: "--x").description)
|
||||
XCTAssertEqual("rwxr-xr--", FilePermissions(user: "rwx", group: "r-x", other: "r--").description)
|
||||
}
|
||||
struct FilePermissionsTests {
|
||||
@Test func description() {
|
||||
#expect(FilePermissions(user: "---", group: "---", other: "---").description == "---------")
|
||||
#expect(FilePermissions(user: "r--", group: "r--", other: "r--").description == "r--r--r--")
|
||||
#expect(FilePermissions(user: "-w-", group: "-w-", other: "-w-").description == "-w--w--w-")
|
||||
#expect(FilePermissions(user: "--x", group: "--x", other: "--x").description == "--x--x--x")
|
||||
#expect(FilePermissions(user: "rwx", group: "r-x", other: "r--").description == "rwxr-xr--")
|
||||
}
|
||||
|
||||
func testInitFromString() {
|
||||
XCTAssertEqual(FilePermissions(user: "---", group: "---", other: "---"), FilePermissions(string: "---------"))
|
||||
XCTAssertEqual(FilePermissions(user: "r--", group: "r--", other: "r--"), FilePermissions(string: "r--r--r--"))
|
||||
XCTAssertEqual(FilePermissions(user: "-w-", group: "-w-", other: "-w-"), FilePermissions(string: "-w--w--w-"))
|
||||
XCTAssertEqual(FilePermissions(user: "--x", group: "--x", other: "--x"), FilePermissions(string: "--x--x--x"))
|
||||
XCTAssertEqual(FilePermissions(user: "rwx", group: "r-x", other: "r--"), FilePermissions(string: "rwxr-xr--"))
|
||||
@Test func initFromString() {
|
||||
#expect(FilePermissions(user: "---", group: "---", other: "---") == FilePermissions(string: "---------"))
|
||||
#expect(FilePermissions(user: "r--", group: "r--", other: "r--") == FilePermissions(string: "r--r--r--"))
|
||||
#expect(FilePermissions(user: "-w-", group: "-w-", other: "-w-") == FilePermissions(string: "-w--w--w-"))
|
||||
#expect(FilePermissions(user: "--x", group: "--x", other: "--x") == FilePermissions(string: "--x--x--x"))
|
||||
#expect(FilePermissions(user: "rwx", group: "r-x", other: "r--") == FilePermissions(string: "rwxr-xr--"))
|
||||
|
||||
// Refuses to initialize with nonsense.
|
||||
XCTAssertNil(FilePermissions(string: "abcdefghi"))
|
||||
XCTAssertNil(FilePermissions(string: "abcrwxrwx"))
|
||||
XCTAssertNil(FilePermissions(string: "rwxabcrwx"))
|
||||
XCTAssertNil(FilePermissions(string: "rwxrwxabc"))
|
||||
}
|
||||
// Refuses to initialize with nonsense.
|
||||
#expect(FilePermissions(string: "abcdefghi") == nil)
|
||||
#expect(FilePermissions(string: "abcrwxrwx") == nil)
|
||||
#expect(FilePermissions(string: "rwxabcrwx") == nil)
|
||||
#expect(FilePermissions(string: "rwxrwxabc") == nil)
|
||||
}
|
||||
|
||||
func testInitFromRawValue() {
|
||||
XCTAssertEqual("---------", FilePermissions(rawValue: 0o000))
|
||||
XCTAssertEqual("rwxr-xr-x", FilePermissions(rawValue: 0o755))
|
||||
XCTAssertEqual("rw-r--r--", FilePermissions(rawValue: 0o644))
|
||||
XCTAssertEqual("rw-------", FilePermissions(rawValue: 0o600))
|
||||
XCTAssertEqual("rwxrwxrwx", FilePermissions(rawValue: 0o777))
|
||||
}
|
||||
@Test func initFromRawValue() {
|
||||
#expect(FilePermissions(rawValue: 0o000) == FilePermissions(string: "---------"))
|
||||
#expect(FilePermissions(rawValue: 0o755) == FilePermissions(string: "rwxr-xr-x"))
|
||||
#expect(FilePermissions(rawValue: 0o644) == FilePermissions(string: "rw-r--r--"))
|
||||
#expect(FilePermissions(rawValue: 0o600) == FilePermissions(string: "rw-------"))
|
||||
#expect(FilePermissions(rawValue: 0o777) == FilePermissions(string: "rwxrwxrwx"))
|
||||
}
|
||||
|
||||
func testRawValue() {
|
||||
XCTAssertEqual(0o000, FilePermissions(string: "---------")!.rawValue)
|
||||
XCTAssertEqual(0o755, FilePermissions(string: "rwxr-xr-x")!.rawValue)
|
||||
XCTAssertEqual(0o644, FilePermissions(string: "rw-r--r--")!.rawValue)
|
||||
XCTAssertEqual(0o600, FilePermissions(string: "rw-------")!.rawValue)
|
||||
XCTAssertEqual(0o777, FilePermissions(string: "rwxrwxrwx")!.rawValue)
|
||||
}
|
||||
@Test func rawValue() {
|
||||
#expect(FilePermissions(string: "---------")!.rawValue == 0o000)
|
||||
#expect(FilePermissions(string: "rwxr-xr-x")!.rawValue == 0o755)
|
||||
#expect(FilePermissions(string: "rw-r--r--")!.rawValue == 0o644)
|
||||
#expect(FilePermissions(string: "rw-------")!.rawValue == 0o600)
|
||||
#expect(FilePermissions(string: "rwxrwxrwx")!.rawValue == 0o777)
|
||||
}
|
||||
|
||||
func testExpressibleByStringLiteral() {
|
||||
XCTAssertEqual(FilePermissions(user: "rwx", group: "r-x", other: "r-x"), "rwxr-xr-x")
|
||||
}
|
||||
|
||||
static var allTests = [
|
||||
("testDescription", testDescription),
|
||||
("testInitFromString", testInitFromString),
|
||||
("testInitFromRawValue", testInitFromRawValue),
|
||||
("testRawValue", testRawValue),
|
||||
("testExpressibleByStringLiteral", testExpressibleByStringLiteral),
|
||||
]
|
||||
@Test func expressibleByStringLiteral() {
|
||||
#expect(FilePermissions(user: "rwx", group: "r-x", other: "r-x") == "rwxr-xr-x")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,63 +5,53 @@
|
|||
// Created by Sami Samhuri on 2019-12-31.
|
||||
//
|
||||
|
||||
import XCTest
|
||||
@testable import samhuri_net
|
||||
import Testing
|
||||
|
||||
extension Permissions {
|
||||
final class Tests: XCTestCase {
|
||||
func testOptionsAreMutuallyExclusive() {
|
||||
// If any of the bits overlap then the `or` value will be less than the sum of the raw values.
|
||||
let allValues = [Permissions.execute, Permissions.write, Permissions.read].map { $0.rawValue }
|
||||
XCTAssertEqual(allValues.reduce(0, +), allValues.reduce(0, |))
|
||||
}
|
||||
struct PermissionsTests {
|
||||
@Test func optionsAreMutuallyExclusive() {
|
||||
// If any of the bits overlap then the `or` value will be less than the sum of the raw values.
|
||||
let allValues = [Permissions.execute, Permissions.write, Permissions.read].map { $0.rawValue }
|
||||
#expect(allValues.reduce(0, +) == allValues.reduce(0, |))
|
||||
}
|
||||
|
||||
func testRawValuesAreUnixy() {
|
||||
XCTAssertEqual(0o0, Permissions.none.rawValue)
|
||||
XCTAssertEqual(0o4, Permissions.read.rawValue)
|
||||
XCTAssertEqual(0o2, Permissions.write.rawValue)
|
||||
XCTAssertEqual(0o1, Permissions.execute.rawValue)
|
||||
}
|
||||
@Test func rawValuesAreUnixy() {
|
||||
#expect(Permissions.none.rawValue == 0o0)
|
||||
#expect(Permissions.read.rawValue == 0o4)
|
||||
#expect(Permissions.write.rawValue == 0o2)
|
||||
#expect(Permissions.execute.rawValue == 0o1)
|
||||
}
|
||||
|
||||
func testInitFromString() {
|
||||
XCTAssertEqual([.none], Permissions(string: "---"))
|
||||
XCTAssertEqual([.execute], Permissions(string: "--x"))
|
||||
XCTAssertEqual([.write], Permissions(string: "-w-"))
|
||||
XCTAssertEqual([.read], Permissions(string: "r--"))
|
||||
@Test func initFromString() {
|
||||
#expect(Permissions(string: "---") == [.none])
|
||||
#expect(Permissions(string: "--x") == [.execute])
|
||||
#expect(Permissions(string: "-w-") == [.write])
|
||||
#expect(Permissions(string: "r--") == [.read])
|
||||
|
||||
XCTAssertEqual([.read, .write], Permissions(string: "rw-"))
|
||||
XCTAssertEqual([.read, .execute], Permissions(string: "r-x"))
|
||||
XCTAssertEqual([.write, .execute], Permissions(string: "-wx"))
|
||||
XCTAssertEqual([.read, .write, .execute], Permissions(string: "rwx"))
|
||||
#expect(Permissions(string: "rw-") == [.read, .write])
|
||||
#expect(Permissions(string: "r-x") == [.read, .execute])
|
||||
#expect(Permissions(string: "-wx") == [.write, .execute])
|
||||
#expect(Permissions(string: "rwx") == [.read, .write, .execute])
|
||||
|
||||
// Refuses to initialize with nonsense.
|
||||
XCTAssertNil(Permissions(string: "abc"))
|
||||
XCTAssertNil(Permissions(string: "awx"))
|
||||
XCTAssertNil(Permissions(string: "rax"))
|
||||
XCTAssertNil(Permissions(string: "rwa"))
|
||||
}
|
||||
// Refuses to initialize with nonsense.
|
||||
#expect(Permissions(string: "abc") == nil)
|
||||
#expect(Permissions(string: "awx") == nil)
|
||||
#expect(Permissions(string: "rax") == nil)
|
||||
#expect(Permissions(string: "rwa") == nil)
|
||||
}
|
||||
|
||||
func testDescription() {
|
||||
XCTAssertEqual("---", Permissions.none.description)
|
||||
XCTAssertEqual("r--", Permissions.read.description)
|
||||
XCTAssertEqual("-w-", Permissions.write.description)
|
||||
XCTAssertEqual("--x", Permissions.execute.description)
|
||||
XCTAssertEqual("rw-", Permissions(arrayLiteral: [.read, .write]).description)
|
||||
XCTAssertEqual("r-x", Permissions(arrayLiteral: [.read, .execute]).description)
|
||||
XCTAssertEqual("-wx", Permissions(arrayLiteral: [.write, .execute]).description)
|
||||
XCTAssertEqual("rwx", Permissions(arrayLiteral: [.read, .write, .execute]).description)
|
||||
}
|
||||
@Test func description() {
|
||||
#expect(Permissions.none.description == "---")
|
||||
#expect(Permissions.read.description == "r--")
|
||||
#expect(Permissions.write.description == "-w-")
|
||||
#expect(Permissions.execute.description == "--x")
|
||||
#expect(Permissions(arrayLiteral: [.read, .write]).description == "rw-")
|
||||
#expect(Permissions(arrayLiteral: [.read, .execute]).description == "r-x")
|
||||
#expect(Permissions(arrayLiteral: [.write, .execute]).description == "-wx")
|
||||
#expect(Permissions(arrayLiteral: [.read, .write, .execute]).description == "rwx")
|
||||
}
|
||||
|
||||
func testExpressibleByStringLiteral() {
|
||||
XCTAssertEqual(Permissions.read, "r--")
|
||||
}
|
||||
|
||||
static var allTests = [
|
||||
("testOptionsAreMutuallyExclusive", testOptionsAreMutuallyExclusive),
|
||||
("testRawValuesAreUnixy", testRawValuesAreUnixy),
|
||||
("testInitFromString", testInitFromString),
|
||||
("testDescription", testDescription),
|
||||
("testExpressibleByStringLiteral", testExpressibleByStringLiteral),
|
||||
]
|
||||
@Test func expressibleByStringLiteral() {
|
||||
#expect(Permissions.read == "r--")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +0,0 @@
|
|||
import XCTest
|
||||
|
||||
#if !canImport(ObjectiveC)
|
||||
public func allTests() -> [XCTestCaseEntry] {
|
||||
return [
|
||||
testCase(Date.Tests.allTests),
|
||||
testCase(Permissions.Tests.allTests),
|
||||
testCase(FilePermissions.Tests.allTests),
|
||||
testCase(samhuri.net.Tests.allTests),
|
||||
]
|
||||
}
|
||||
#endif
|
||||
|
|
@ -1,14 +1,8 @@
|
|||
import XCTest
|
||||
import Testing
|
||||
@testable import samhuri_net
|
||||
|
||||
extension samhuri.net {
|
||||
final class Tests: XCTestCase {
|
||||
func testExample() {
|
||||
XCTAssert(true)
|
||||
}
|
||||
|
||||
static var allTests = [
|
||||
("testExample", testExample),
|
||||
]
|
||||
struct samhuri_net_Tests {
|
||||
@Test func example() {
|
||||
#expect(true)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue