diff --git a/Sources/VersionatorTool/VersionatorTool.swift b/Sources/VersionatorTool/VersionatorTool.swift index 8c4b101..fa7a954 100644 --- a/Sources/VersionatorTool/VersionatorTool.swift +++ b/Sources/VersionatorTool/VersionatorTool.swift @@ -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) @@ -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)" """ diff --git a/Tests/VersionatorTests/Resources/Example.git/git/objects/e7/18e3860fceddf4cf3e5ee69a1758d6b8b3b8f4 b/Tests/VersionatorTests/Resources/Example.git/git/objects/e7/18e3860fceddf4cf3e5ee69a1758d6b8b3b8f4 new file mode 100644 index 0000000..5f96a4e Binary files /dev/null and b/Tests/VersionatorTests/Resources/Example.git/git/objects/e7/18e3860fceddf4cf3e5ee69a1758d6b8b3b8f4 differ diff --git a/Tests/VersionatorTests/Resources/Example.git/git/refs/tags/v1.0.0 b/Tests/VersionatorTests/Resources/Example.git/git/refs/tags/v1.0.0 new file mode 100644 index 0000000..5fd9447 --- /dev/null +++ b/Tests/VersionatorTests/Resources/Example.git/git/refs/tags/v1.0.0 @@ -0,0 +1 @@ +e718e3860fceddf4cf3e5ee69a1758d6b8b3b8f4 diff --git a/Tests/VersionatorTests/Resources/Example.out/Info.plisth b/Tests/VersionatorTests/Resources/Example.out/Info.plisth index 1a7f496..e8cb893 100644 --- a/Tests/VersionatorTests/Resources/Example.out/Info.plisth +++ b/Tests/VersionatorTests/Resources/Example.out/Info.plisth @@ -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" \ No newline at end of file +#define COMMIT "g70f8f9a" +#define GIT_VERSION "v1.0.0-0-g70f8f9a" +#define GIT_TAG "v1.0.0" \ No newline at end of file diff --git a/Tests/VersionatorTests/Resources/Example.out/Version.h b/Tests/VersionatorTests/Resources/Example.out/Version.h index 1a7f496..e8cb893 100644 --- a/Tests/VersionatorTests/Resources/Example.out/Version.h +++ b/Tests/VersionatorTests/Resources/Example.out/Version.h @@ -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" \ No newline at end of file +#define COMMIT "g70f8f9a" +#define GIT_VERSION "v1.0.0-0-g70f8f9a" +#define GIT_TAG "v1.0.0" \ No newline at end of file diff --git a/Tests/VersionatorTests/Resources/Example.out/Version.plist b/Tests/VersionatorTests/Resources/Example.out/Version.plist index 67f0096..9f89b4e 100644 Binary files a/Tests/VersionatorTests/Resources/Example.out/Version.plist and b/Tests/VersionatorTests/Resources/Example.out/Version.plist differ diff --git a/Tests/VersionatorTests/Resources/Example.out/Version.swift b/Tests/VersionatorTests/Resources/Example.out/Version.swift index c9184e4..1185c77 100644 --- a/Tests/VersionatorTests/Resources/Example.out/Version.swift +++ b/Tests/VersionatorTests/Resources/Example.out/Version.swift @@ -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)" -} \ No newline at end of file + 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)" +} diff --git a/Tests/VersionatorTests/VersionatorTests.swift b/Tests/VersionatorTests/VersionatorTests.swift index 861d991..cfeebe9 100644 --- a/Tests/VersionatorTests/VersionatorTests.swift +++ b/Tests/VersionatorTests/VersionatorTests.swift @@ -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 @@ -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?) -// // 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))