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
|
@testable import gensite
|
||||||
import class Foundation.Bundle
|
import Testing
|
||||||
|
|
||||||
final class gensiteTests: XCTestCase {
|
struct gensiteTests {
|
||||||
static var allTests = [(String, XCTestCase)]()
|
@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.
|
// Created by Sami Samhuri on 2019-12-31.
|
||||||
//
|
//
|
||||||
|
|
||||||
import XCTest
|
import Foundation
|
||||||
@testable import samhuri_net
|
@testable import samhuri_net
|
||||||
|
import Testing
|
||||||
|
|
||||||
extension Date {
|
class DateSugarTests {
|
||||||
final class Tests: XCTestCase {
|
let date: Date
|
||||||
var date: Date!
|
|
||||||
|
|
||||||
override func setUp() {
|
init() {
|
||||||
var calendar = Calendar(identifier: .gregorian)
|
var calendar = Calendar(identifier: .gregorian)
|
||||||
calendar.timeZone = TimeZone(secondsFromGMT: 0)!
|
calendar.timeZone = TimeZone(secondsFromGMT: 0)!
|
||||||
Date.defaultCalendar = calendar
|
Date.defaultCalendar = calendar
|
||||||
date = Date(timeIntervalSince1970: 0)
|
date = Date(timeIntervalSince1970: 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
override func tearDown() {
|
deinit {
|
||||||
Date.defaultCalendar = .current
|
Date.defaultCalendar = .current
|
||||||
date = nil
|
}
|
||||||
}
|
|
||||||
|
|
||||||
func testYear() {
|
@Test func year() {
|
||||||
XCTAssertEqual(1970, date.year)
|
#expect(date.year == 1970)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testMonth() {
|
@Test func month() {
|
||||||
XCTAssertEqual(1, date.month)
|
#expect(date.month == 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testDay() {
|
@Test func day() {
|
||||||
XCTAssertEqual(1, date.day)
|
#expect(date.day == 1)
|
||||||
}
|
|
||||||
|
|
||||||
static var allTests = [
|
|
||||||
("testYear", testYear),
|
|
||||||
("testMonth", testMonth),
|
|
||||||
("testDay", testDay),
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,59 +5,49 @@
|
||||||
// Created by Sami Samhuri on 2019-12-31.
|
// Created by Sami Samhuri on 2019-12-31.
|
||||||
//
|
//
|
||||||
|
|
||||||
import XCTest
|
|
||||||
@testable import samhuri_net
|
@testable import samhuri_net
|
||||||
|
import Testing
|
||||||
|
|
||||||
extension FilePermissions {
|
struct FilePermissionsTests {
|
||||||
final class Tests: XCTestCase {
|
@Test func description() {
|
||||||
func testDescription() {
|
#expect(FilePermissions(user: "---", group: "---", other: "---").description == "---------")
|
||||||
XCTAssertEqual("---------", FilePermissions(user: "---", group: "---", other: "---").description)
|
#expect(FilePermissions(user: "r--", group: "r--", other: "r--").description == "r--r--r--")
|
||||||
XCTAssertEqual("r--r--r--", FilePermissions(user: "r--", group: "r--", other: "r--").description)
|
#expect(FilePermissions(user: "-w-", group: "-w-", other: "-w-").description == "-w--w--w-")
|
||||||
XCTAssertEqual("-w--w--w-", FilePermissions(user: "-w-", group: "-w-", other: "-w-").description)
|
#expect(FilePermissions(user: "--x", group: "--x", other: "--x").description == "--x--x--x")
|
||||||
XCTAssertEqual("--x--x--x", FilePermissions(user: "--x", group: "--x", other: "--x").description)
|
#expect(FilePermissions(user: "rwx", group: "r-x", other: "r--").description == "rwxr-xr--")
|
||||||
XCTAssertEqual("rwxr-xr--", FilePermissions(user: "rwx", group: "r-x", other: "r--").description)
|
}
|
||||||
}
|
|
||||||
|
|
||||||
func testInitFromString() {
|
@Test func initFromString() {
|
||||||
XCTAssertEqual(FilePermissions(user: "---", group: "---", other: "---"), FilePermissions(string: "---------"))
|
#expect(FilePermissions(user: "---", group: "---", other: "---") == FilePermissions(string: "---------"))
|
||||||
XCTAssertEqual(FilePermissions(user: "r--", group: "r--", other: "r--"), FilePermissions(string: "r--r--r--"))
|
#expect(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-"))
|
#expect(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"))
|
#expect(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--"))
|
#expect(FilePermissions(user: "rwx", group: "r-x", other: "r--") == FilePermissions(string: "rwxr-xr--"))
|
||||||
|
|
||||||
// Refuses to initialize with nonsense.
|
// Refuses to initialize with nonsense.
|
||||||
XCTAssertNil(FilePermissions(string: "abcdefghi"))
|
#expect(FilePermissions(string: "abcdefghi") == nil)
|
||||||
XCTAssertNil(FilePermissions(string: "abcrwxrwx"))
|
#expect(FilePermissions(string: "abcrwxrwx") == nil)
|
||||||
XCTAssertNil(FilePermissions(string: "rwxabcrwx"))
|
#expect(FilePermissions(string: "rwxabcrwx") == nil)
|
||||||
XCTAssertNil(FilePermissions(string: "rwxrwxabc"))
|
#expect(FilePermissions(string: "rwxrwxabc") == nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testInitFromRawValue() {
|
@Test func initFromRawValue() {
|
||||||
XCTAssertEqual("---------", FilePermissions(rawValue: 0o000))
|
#expect(FilePermissions(rawValue: 0o000) == FilePermissions(string: "---------"))
|
||||||
XCTAssertEqual("rwxr-xr-x", FilePermissions(rawValue: 0o755))
|
#expect(FilePermissions(rawValue: 0o755) == FilePermissions(string: "rwxr-xr-x"))
|
||||||
XCTAssertEqual("rw-r--r--", FilePermissions(rawValue: 0o644))
|
#expect(FilePermissions(rawValue: 0o644) == FilePermissions(string: "rw-r--r--"))
|
||||||
XCTAssertEqual("rw-------", FilePermissions(rawValue: 0o600))
|
#expect(FilePermissions(rawValue: 0o600) == FilePermissions(string: "rw-------"))
|
||||||
XCTAssertEqual("rwxrwxrwx", FilePermissions(rawValue: 0o777))
|
#expect(FilePermissions(rawValue: 0o777) == FilePermissions(string: "rwxrwxrwx"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func testRawValue() {
|
@Test func rawValue() {
|
||||||
XCTAssertEqual(0o000, FilePermissions(string: "---------")!.rawValue)
|
#expect(FilePermissions(string: "---------")!.rawValue == 0o000)
|
||||||
XCTAssertEqual(0o755, FilePermissions(string: "rwxr-xr-x")!.rawValue)
|
#expect(FilePermissions(string: "rwxr-xr-x")!.rawValue == 0o755)
|
||||||
XCTAssertEqual(0o644, FilePermissions(string: "rw-r--r--")!.rawValue)
|
#expect(FilePermissions(string: "rw-r--r--")!.rawValue == 0o644)
|
||||||
XCTAssertEqual(0o600, FilePermissions(string: "rw-------")!.rawValue)
|
#expect(FilePermissions(string: "rw-------")!.rawValue == 0o600)
|
||||||
XCTAssertEqual(0o777, FilePermissions(string: "rwxrwxrwx")!.rawValue)
|
#expect(FilePermissions(string: "rwxrwxrwx")!.rawValue == 0o777)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testExpressibleByStringLiteral() {
|
@Test func expressibleByStringLiteral() {
|
||||||
XCTAssertEqual(FilePermissions(user: "rwx", group: "r-x", other: "r-x"), "rwxr-xr-x")
|
#expect(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),
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,63 +5,53 @@
|
||||||
// Created by Sami Samhuri on 2019-12-31.
|
// Created by Sami Samhuri on 2019-12-31.
|
||||||
//
|
//
|
||||||
|
|
||||||
import XCTest
|
|
||||||
@testable import samhuri_net
|
@testable import samhuri_net
|
||||||
|
import Testing
|
||||||
|
|
||||||
extension Permissions {
|
struct PermissionsTests {
|
||||||
final class Tests: XCTestCase {
|
@Test func optionsAreMutuallyExclusive() {
|
||||||
func testOptionsAreMutuallyExclusive() {
|
// If any of the bits overlap then the `or` value will be less than the sum of the raw values.
|
||||||
// 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 }
|
||||||
let allValues = [Permissions.execute, Permissions.write, Permissions.read].map { $0.rawValue }
|
#expect(allValues.reduce(0, +) == allValues.reduce(0, |))
|
||||||
XCTAssertEqual(allValues.reduce(0, +), allValues.reduce(0, |))
|
}
|
||||||
}
|
|
||||||
|
|
||||||
func testRawValuesAreUnixy() {
|
@Test func rawValuesAreUnixy() {
|
||||||
XCTAssertEqual(0o0, Permissions.none.rawValue)
|
#expect(Permissions.none.rawValue == 0o0)
|
||||||
XCTAssertEqual(0o4, Permissions.read.rawValue)
|
#expect(Permissions.read.rawValue == 0o4)
|
||||||
XCTAssertEqual(0o2, Permissions.write.rawValue)
|
#expect(Permissions.write.rawValue == 0o2)
|
||||||
XCTAssertEqual(0o1, Permissions.execute.rawValue)
|
#expect(Permissions.execute.rawValue == 0o1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testInitFromString() {
|
@Test func initFromString() {
|
||||||
XCTAssertEqual([.none], Permissions(string: "---"))
|
#expect(Permissions(string: "---") == [.none])
|
||||||
XCTAssertEqual([.execute], Permissions(string: "--x"))
|
#expect(Permissions(string: "--x") == [.execute])
|
||||||
XCTAssertEqual([.write], Permissions(string: "-w-"))
|
#expect(Permissions(string: "-w-") == [.write])
|
||||||
XCTAssertEqual([.read], Permissions(string: "r--"))
|
#expect(Permissions(string: "r--") == [.read])
|
||||||
|
|
||||||
XCTAssertEqual([.read, .write], Permissions(string: "rw-"))
|
#expect(Permissions(string: "rw-") == [.read, .write])
|
||||||
XCTAssertEqual([.read, .execute], Permissions(string: "r-x"))
|
#expect(Permissions(string: "r-x") == [.read, .execute])
|
||||||
XCTAssertEqual([.write, .execute], Permissions(string: "-wx"))
|
#expect(Permissions(string: "-wx") == [.write, .execute])
|
||||||
XCTAssertEqual([.read, .write, .execute], Permissions(string: "rwx"))
|
#expect(Permissions(string: "rwx") == [.read, .write, .execute])
|
||||||
|
|
||||||
// Refuses to initialize with nonsense.
|
// Refuses to initialize with nonsense.
|
||||||
XCTAssertNil(Permissions(string: "abc"))
|
#expect(Permissions(string: "abc") == nil)
|
||||||
XCTAssertNil(Permissions(string: "awx"))
|
#expect(Permissions(string: "awx") == nil)
|
||||||
XCTAssertNil(Permissions(string: "rax"))
|
#expect(Permissions(string: "rax") == nil)
|
||||||
XCTAssertNil(Permissions(string: "rwa"))
|
#expect(Permissions(string: "rwa") == nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testDescription() {
|
@Test func description() {
|
||||||
XCTAssertEqual("---", Permissions.none.description)
|
#expect(Permissions.none.description == "---")
|
||||||
XCTAssertEqual("r--", Permissions.read.description)
|
#expect(Permissions.read.description == "r--")
|
||||||
XCTAssertEqual("-w-", Permissions.write.description)
|
#expect(Permissions.write.description == "-w-")
|
||||||
XCTAssertEqual("--x", Permissions.execute.description)
|
#expect(Permissions.execute.description == "--x")
|
||||||
XCTAssertEqual("rw-", Permissions(arrayLiteral: [.read, .write]).description)
|
#expect(Permissions(arrayLiteral: [.read, .write]).description == "rw-")
|
||||||
XCTAssertEqual("r-x", Permissions(arrayLiteral: [.read, .execute]).description)
|
#expect(Permissions(arrayLiteral: [.read, .execute]).description == "r-x")
|
||||||
XCTAssertEqual("-wx", Permissions(arrayLiteral: [.write, .execute]).description)
|
#expect(Permissions(arrayLiteral: [.write, .execute]).description == "-wx")
|
||||||
XCTAssertEqual("rwx", Permissions(arrayLiteral: [.read, .write, .execute]).description)
|
#expect(Permissions(arrayLiteral: [.read, .write, .execute]).description == "rwx")
|
||||||
}
|
}
|
||||||
|
|
||||||
func testExpressibleByStringLiteral() {
|
@Test func expressibleByStringLiteral() {
|
||||||
XCTAssertEqual(Permissions.read, "r--")
|
#expect(Permissions.read == "r--")
|
||||||
}
|
|
||||||
|
|
||||||
static var allTests = [
|
|
||||||
("testOptionsAreMutuallyExclusive", testOptionsAreMutuallyExclusive),
|
|
||||||
("testRawValuesAreUnixy", testRawValuesAreUnixy),
|
|
||||||
("testInitFromString", testInitFromString),
|
|
||||||
("testDescription", testDescription),
|
|
||||||
("testExpressibleByStringLiteral", testExpressibleByStringLiteral),
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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
|
@testable import samhuri_net
|
||||||
|
|
||||||
extension samhuri.net {
|
struct samhuri_net_Tests {
|
||||||
final class Tests: XCTestCase {
|
@Test func example() {
|
||||||
func testExample() {
|
#expect(true)
|
||||||
XCTAssert(true)
|
|
||||||
}
|
|
||||||
|
|
||||||
static var allTests = [
|
|
||||||
("testExample", testExample),
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue