From 17857bc0bbb5a5602bbe92a768d660d244e766df Mon Sep 17 00:00:00 2001 From: Sam Deane Date: Wed, 6 Nov 2024 10:26:11 +0000 Subject: [PATCH] Fixed test examples --- Sources/VersionatorTool/VersionatorTool.swift | 15 ++-- .../e7/18e3860fceddf4cf3e5ee69a1758d6b8b3b8f4 | Bin 0 -> 137 bytes .../Example.git/git/refs/tags/v1.0.0 | 1 + .../Resources/Example.out/Info.plisth | 6 +- .../Resources/Example.out/Version.h | 6 +- .../Resources/Example.out/Version.plist | Bin 191 -> 226 bytes .../Resources/Example.out/Version.swift | 14 ++-- Tests/VersionatorTests/VersionatorTests.swift | 75 +++--------------- 8 files changed, 35 insertions(+), 82 deletions(-) create mode 100644 Tests/VersionatorTests/Resources/Example.git/git/objects/e7/18e3860fceddf4cf3e5ee69a1758d6b8b3b8f4 create mode 100644 Tests/VersionatorTests/Resources/Example.git/git/refs/tags/v1.0.0 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 0000000000000000000000000000000000000000..5f96a4e3444576b6c56b434a9f9503903557f5c7 GIT binary patch literal 137 zcmV;40CxX)0Tqlv3c@fD06pgwdl$l{O}hz*c<=|lU>i2IVj5|dg1@)UX)ZI$GdSO$ z>hzMNK$t_0EMrIGgx%mV#E6k(h^Z%+10!aiN2A}5K&quIYV>&Q&Z5P?&a%OS3*3cQ rflK3Zlef&gYI<^Q_K2?FsK*e(1nR9J4i5q0f(rJo_AbIL#6Xh(Wd{icFyIiC Z(en;XXz1wbh6pe+LTCnVC=H{g005R84&wj- 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))