Skip to content
Open
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
5 changes: 3 additions & 2 deletions .github/workflows/BuildPR.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ jobs:
matrix:
xcode:
# The '^' stands for a semantic version range
- ^15
- ^16
os:
- macos-14
- macos-15
- macos-26
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -39,12 +39,13 @@ jobs:
xcode:
- ^16
os:
- macos-15
- macos-26
platform:
- iOS
platform-version:
# The '^' stands for a semantic version range
- ^18
- ^26
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down
36 changes: 0 additions & 36 deletions Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ let package = Package(
),
],
dependencies: [
.package(url: "https://github.com/Quick/Quick.git", from: "7.0.0"),
.package(url: "https://github.com/Quick/Nimble.git", from: "13.0.0"),
.package(url: "https://github.com/ZipArchive/ZipArchive.git", from: "2.5.5"),
],
targets: [
Expand All @@ -29,7 +27,7 @@ let package = Package(
),
.testTarget(
name: "SwiftGit2Tests",
dependencies: ["SwiftGit2", "Clibgit2", "Quick", "Nimble", "ZipArchive"],
dependencies: ["SwiftGit2", "Clibgit2", "ZipArchive"],
resources: [.copy("Fixtures")]
),
.target(
Expand Down Expand Up @@ -76,7 +74,7 @@ let package = Package(
// Disable -fmodules flag. Clang finds (`struct entry`) in a different file (`search.h`).
"-fno-modules",
// Disable warning: "implicit conversion loses integer precision"
"-Wno-single-bit-bitfield-constant-conversion",
"-Wno-single-bit-bitfield-constant-conversion", "-Wno-conversion",
// Disable warning: "a function definition without a prototype is deprecated"
"-Wno-deprecated-non-prototype",
]),
Expand Down
75 changes: 39 additions & 36 deletions Tests/SwiftGit2Tests/Fixtures.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,58 +11,61 @@ import ZipArchive

final class Fixtures {

// MARK: Lifecycle
let directoryURL: URL

class var sharedInstance: Fixtures {
enum Singleton {
static let instance = Fixtures()
}
return Singleton.instance
}
// MARK: - Setup and Teardown

init() {
init() throws {
directoryURL = URL(fileURLWithPath: NSTemporaryDirectory(), isDirectory: true)
.appendingPathComponent("org.libgit2.SwiftGit2")
.appendingPathComponent(ProcessInfo.processInfo.globallyUniqueString)
// Each instance of `Fixtures` gets a unique namespace
.appendingPathComponent(UUID().uuidString)
try setUp()
}

// MARK: - Setup and Teardown

let directoryURL: URL

func setUp() {
try! FileManager.default.createDirectory(at: directoryURL, withIntermediateDirectories: true, attributes: nil)

let bundle = Bundle.module
let zipURLs = bundle.urls(forResourcesWithExtension: "zip", subdirectory: "Fixtures")!

for URL in zipURLs {
SSZipArchive.unzipFile(atPath: URL.path, toDestination: directoryURL.path)
}
deinit {
do {
try tearDown()
} catch {
print("Warning: failed to tear down fixtures: \(error)")
}
}

private func setUp() throws {
// Create target directory for this set of fixtures
try FileManager.default.createDirectory(at: directoryURL,
withIntermediateDirectories: true, attributes: nil)
}

func tearDown() {
try! FileManager.default.removeItem(at: directoryURL)
private func tearDown() throws {
try FileManager.default.removeItem(at: directoryURL)
}

// MARK: - Helpers

func repository(named name: String) -> Repository {
let url = directoryURL.appendingPathComponent(name, isDirectory: true)
return Repository.at(url).value!
func repository(named name: String) throws -> Repository {
let url = directoryURL.appendingPathComponent(name, isDirectory: true)

// Lazily initialize the fixture repositories as they are requested
if !FileManager.default.fileExists(atPath: url.path) {
let zipPath = Bundle.module.path(forResource: name, ofType: "zip", inDirectory: "Fixtures")!
SSZipArchive.unzipFile(atPath: zipPath, toDestination: directoryURL.path)
}

return try Repository.at(url).get()
}

// MARK: - The Fixtures

class var detachedHeadRepository: Repository {
return Fixtures.sharedInstance.repository(named: "detached-head")
}
func detachedHeadRepository() throws -> Repository {
return try repository(named: "detached-head")
}

class var simpleRepository: Repository {
return Fixtures.sharedInstance.repository(named: "simple-repository")
}
func simpleRepository() throws -> Repository {
return try repository(named: "simple-repository")
}

class var mantleRepository: Repository {
return Fixtures.sharedInstance.repository(named: "Mantle")
}
func mantleRepository() throws -> Repository {
return try repository(named: "Mantle")
}
}
24 changes: 12 additions & 12 deletions Tests/SwiftGit2Tests/FixturesSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@
// Copyright (c) 2014 GitHub, Inc. All rights reserved.
//

import Quick
import SwiftGit2
import Testing
import Clibgit2

class FixturesSpec: QuickSpec {
override class func spec() {
beforeSuite {
_ = SwiftGit2Init()
Fixtures.sharedInstance.setUp()
}
class FixturesSpec {
let fixtures: Fixtures

afterSuite {
Fixtures.sharedInstance.tearDown()
_ = SwiftGit2Shutdown()
}
}
init() throws {
_ = SwiftGit2Init()
self.fixtures = try Fixtures()
}

deinit {
_ = SwiftGit2Shutdown()
}
}
103 changes: 50 additions & 53 deletions Tests/SwiftGit2Tests/OIDSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,66 +7,63 @@
//

import SwiftGit2
import Nimble
import Quick
import Testing

class OIDSpec: QuickSpec {
override class func spec() {
describe("OID(string:)") {
it("should be nil if string is too short") {
expect(OID(string: "123456789012345678901234567890123456789")).to(beNil())
}
@Suite("OID") class OIDSpec {
@Suite("OID(string:)") struct InitializeWithString {
@Test("should be nil if string is too short") func tooShort() {
#expect(OID(string: "123456789012345678901234567890123456789") == nil)
}

it("should be nil if string is too long") {
expect(OID(string: "12345678901234567890123456789012345678901")).to(beNil())
}
@Test("should be nil if string is too long") func tooLong() {
#expect(OID(string: "12345678901234567890123456789012345678901") == nil)
}

it("should not be nil if string is just right") {
expect(OID(string: "1234567890123456789012345678ABCDEFabcdef")).notTo(beNil())
}
@Test("should not be nil if string is just right") func justRight() {
#expect(OID(string: "1234567890123456789012345678ABCDEFabcdef") != nil)
}

it("should be nil with non-hex characters") {
expect(OID(string: "123456789012345678901234567890123456789j")).to(beNil())
}
}
@Test("should be nil with non-hex characters") func invalidCharacters() {
#expect(OID(string: "123456789012345678901234567890123456789j") == nil)
}
}

describe("OID(oid)") {
it("should equal an OID with the same git_oid") {
let oid = OID(string: "1234567890123456789012345678901234567890")!
expect(OID(oid.oid)).to(equal(oid))
}
}
@Suite("OID(oid)") struct InitializeWithOID {
@Test("should equal an OID with the same git_oid") func equal() throws {
let oid = try #require(OID(string: "1234567890123456789012345678901234567890"))
#expect(OID(oid.oid) == oid)
}
}

describe("OID.description") {
it("should return the SHA") {
let SHA = "1234567890123456789012345678901234567890"
let oid = OID(string: SHA)!
expect(oid.description).to(equal(SHA))
}
}
@Suite("OID.description") struct Description {
@Test("should return the SHA") func sha() throws {
let SHA = "1234567890123456789012345678901234567890"
let oid = try #require(OID(string: SHA))
#expect(oid.description == SHA)
}
}

describe("==(OID, OID)") {
it("should be equal when identical") {
let SHA = "1234567890123456789012345678901234567890"
let oid1 = OID(string: SHA)!
let oid2 = OID(string: SHA)!
expect(oid1).to(equal(oid2))
}
@Suite("==(OID, OID)") struct Equality {
@Test("should be equal when identical") func equal() throws {
let SHA = "1234567890123456789012345678901234567890"
let oid1 = try #require(OID(string: SHA))
let oid2 = try #require(OID(string: SHA))
#expect(oid1 == oid2)
}

it("should be not equal when different") {
let oid1 = OID(string: "1234567890123456789012345678901234567890")!
let oid2 = OID(string: "0000000000000000000000000000000000000000")!
expect(oid1).notTo(equal(oid2))
}
}
@Test("should be not equal when different") func notEqual() throws {
let oid1 = try #require(OID(string: "1234567890123456789012345678901234567890"))
let oid2 = try #require(OID(string: "0000000000000000000000000000000000000000"))
#expect(oid1 != oid2)
}
}

describe("OID.hashValue") {
it("should be equal when OIDs are equal") {
let SHA = "1234567890123456789012345678901234567890"
let oid1 = OID(string: SHA)!
let oid2 = OID(string: SHA)!
expect(oid1.hashValue).to(equal(oid2.hashValue))
}
}
}
@Suite("OID.hashValue") struct HashValue {
@Test("should be equal when OIDs are equal") func equal() throws {
let SHA = "1234567890123456789012345678901234567890"
let oid1 = try #require(OID(string: SHA))
let oid2 = try #require(OID(string: SHA))
#expect(oid1.hashValue == oid2.hashValue)
}
}
}
Loading