Skip to content

Commit

Permalink
Fixed test examples
Browse files Browse the repository at this point in the history
  • Loading branch information
samdeane committed Nov 6, 2024
1 parent b23e024 commit 17857bc
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 82 deletions.
15 changes: 8 additions & 7 deletions Sources/VersionatorTool/VersionatorTool.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,14 @@ import VersionatorUtils
/// This file is generated by Versionator -- DO NOT EDIT.
/// See github.com/elegantchaos/Versionator for more info.
public struct VersionatorVersion {
static let string = "\(version)"
static let build = \(buildNumber)
static let commit = "\(commit)"
static let git = "\(gitVersion)"
static let tag = "\(tag)"
static let full = "\(version) (\(buildNumber))"
static let string = "\(version)"
static let build = \(buildNumber)
static let commit = "\(commit)"
static let git = "\(gitVersion)"
static let tag = "\(tag)"
static let full = "\(version) (\(buildNumber))"
}
"""
let data = generatedSwift.data(using: .utf8)
try? FileManager.default.createDirectory(at: url.deletingLastPathComponent(), withIntermediateDirectories: true)
Expand All @@ -92,7 +93,7 @@ import VersionatorUtils
/// See github.com/elegantchaos/Versionator for more info.
#define BUILD \(buildNumber)
#define CURRENT_PROJECT_VERSION \(buildNumber)
#define COMMIT \(commit)
#define COMMIT "\(commit)"
#define GIT_VERSION "\(gitVersion)"
#define GIT_TAG "\(tag)"
"""
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
e718e3860fceddf4cf3e5ee69a1758d6b8b3b8f4
6 changes: 3 additions & 3 deletions Tests/VersionatorTests/Resources/Example.out/Info.plisth
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
/// See github.com/elegantchaos/Versionator for more info.
#define BUILD 4
#define CURRENT_PROJECT_VERSION 4
#define COMMIT
#define GIT_VERSION "70f8f9a"
#define GIT_TAG "70f8f9a"
#define COMMIT "g70f8f9a"
#define GIT_VERSION "v1.0.0-0-g70f8f9a"
#define GIT_TAG "v1.0.0"
6 changes: 3 additions & 3 deletions Tests/VersionatorTests/Resources/Example.out/Version.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
/// See github.com/elegantchaos/Versionator for more info.
#define BUILD 4
#define CURRENT_PROJECT_VERSION 4
#define COMMIT
#define GIT_VERSION "70f8f9a"
#define GIT_TAG "70f8f9a"
#define COMMIT "g70f8f9a"
#define GIT_VERSION "v1.0.0-0-g70f8f9a"
#define GIT_TAG "v1.0.0"
Binary file modified Tests/VersionatorTests/Resources/Example.out/Version.plist
Binary file not shown.
14 changes: 7 additions & 7 deletions Tests/VersionatorTests/Resources/Example.out/Version.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/// This file is generated by Versionator -- DO NOT EDIT.
/// See github.com/elegantchaos/Versionator for more info.
public struct VersionatorVersion {
static let string = "70f8f9a"
static let build = 4
static let commit = ""
static let git = "70f8f9a"
static let tag = "70f8f9a"
static let full = "70f8f9a (4)"
}
static let string = "1.0.0"
static let build = 4
static let commit = "g70f8f9a"
static let git = "v1.0.0-0-g70f8f9a"
static let tag = "v1.0.0"
static let full = "1.0.0 (4)"
}
75 changes: 13 additions & 62 deletions Tests/VersionatorTests/VersionatorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import VersionatorUtils

@testable import Runner

/// Test with a task that has a zero status.
/// Run the versionator tool over the example repo, and check that it generates the expected files,
/// with the expected content.
@Test func testTool() async throws {
let test = Test.current!
try await test.inTempFolder { folder in
Expand All @@ -29,74 +30,24 @@ import VersionatorUtils
let output = await runner.run(args)
.stdout.string

// check files were generated
// check generated files were logged to output
#expect(output.contains("Generated Version.swift"))
#expect(output.contains("Generated Version.h"))
#expect(output.contains("Generated Version.plist"))
#expect(output.contains("Generated Info.plisth"))

// check content matches expected
// check generated content matches expected
for url in paths {
let content = try Data(contentsOf: url)
let expectedURL = Bundle.module.url(forResource: "Example.out/\(url.deletingPathExtension().lastPathComponent)", withExtension: url.pathExtension)!
let expected = try Data(contentsOf: expectedURL)
#expect(content == expected, "content does not match expected for \(url.lastPathComponent)")
if url.pathExtension != "plist" {
let content = try String(contentsOf: url, encoding: .utf8)
let expected = try String(contentsOf: expectedURL, encoding: .utf8)
for (c, e) in zip(content.split(separator: "\n"), expected.split(separator: "\n")) {
#expect(c == e, "content does not match expected for \(url.lastPathComponent)")
}
} else {
#expect(NSDictionary(contentsOf: url) == NSDictionary(contentsOf: expectedURL), "content does not match expected for \(url.lastPathComponent)")
}
}
}
}

// , backupItemName: String?, options: FileManager.ItemReplacementOptions, resultingItemURL: AutoreleasingUnsafeMutablePointer<NSURL?>?)
// // let folder = URL(fileURLWithPath: "/Users/sam/Desktop/VersionatorTests")
// // make a sample repo
// let script = Runner(for: Bundle.module.url(forResource: "make-repo", withExtension: "sh")!)
// #expect(await script.run([folder.path]).waitUntilExit() == .succeeded)

// let templates = [
// """
// /// This file is generated by Versionator -- DO NOT EDIT.
// /// See github.com/elegantchaos/Versionator for more info.
// public struct VersionatorVersion {
// static let string = "\(expectedCommit)"
// static let build = \(expectedVer)
// static let commit = ""
// static let git = "\(expectedCommit)"
// static let tag = "\(expectedCommit)"
// static let full = "\(expectedCommit) (\(expectedVer))"
// }
// """,
// """
// /// This file is generated by Versionator -- DO NOT EDIT.
// /// See github.com/elegantchaos/Versionator for more info.
// #define BUILD \(expectedVer)
// #define CURRENT_PROJECT_VERSION \(expectedVer)
// #define COMMIT
// #define GIT_VERSION "\(expectedCommit)"
// #define GIT_TAG "\(expectedCommit)"
// """,
// """
// /// This file is generated by Versionator -- DO NOT EDIT.
// /// See github.com/elegantchaos/Versionator for more info.
// public struct VersionatorVersion {
// static let string = "\(expectedCommit)"
// static let build = \(expectedVer)
// static let commit = ""
// static let git = "\(expectedCommit)"
// static let tag = "\(expectedCommit)"
// static let full = "\(expectedCommit) (\(expectedVer))"
// }
// """,
// """
// /// This file is generated by Versionator -- DO NOT EDIT.
// /// See github.com/elegantchaos/Versionator for more info.
// #define BUILD \(expectedVer)
// #define CURRENT_PROJECT_VERSION \(expectedVer)
// #define COMMIT
// #define GIT_VERSION "\(expectedCommit)"
// #define GIT_TAG "\(expectedCommit)"
// """,
// ]

// var format = PropertyListSerialization.PropertyListFormat.xml
// let data = try PropertyListSerialization.propertyList(from: Data(contentsOf: url), options: [], format: &format)
// content = String(describing: data)
// content = String(describing: try PropertyListSerialization.propertyList(from: try Data(contentsOf: url), options: [], format: .binary))

0 comments on commit 17857bc

Please sign in to comment.