Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Tuist 4 #97

Merged
merged 2 commits into from
Feb 10, 2024
Merged
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
46 changes: 40 additions & 6 deletions Tests/SwiftPackageListCoreTests/ProjectTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,41 @@ final class ProjectTests: XCTestCase {
XCTAssertNil(swiftPackage.organizationName)
}

func testTuist() throws {
func testTuist4() throws {
let (exitCode, _) = try zsh("which tuist")
try XCTSkipIf(exitCode != 0)
try XCTSkipIf(exitCode != 0, "Tuist not installed")

let url = Bundle.module.url(forResource: "Project", withExtension: "swift", subdirectory: "Resources/Tuist")
let (_, data) = try zsh("tuist version")
let tuistVersion = String(decoding: data, as: UTF8.self).trimmingCharacters(in: .whitespacesAndNewlines)
try XCTSkipUnless(tuistVersion.hasPrefix("4."), "Installed Tuist version is not 4.*.* (actual: \(tuistVersion))")

let url = Bundle.module.url(forResource: "Project", withExtension: "swift", subdirectory: "Resources/Tuist4")
let unwrappedURL = try XCTUnwrap(url)

let projectType = try XCTUnwrap(ProjectType(fileURL: unwrappedURL))
XCTAssertEqual(projectType, .tuist)

let project = try projectType.project(fileURL: unwrappedURL)
let tuist = try XCTUnwrap(project as? Tuist)

let expectedPackageResolvedFileURL = unwrappedURL
.deletingLastPathComponent()
.appendingPathComponent(".package.resolved")
XCTAssertEqual(try tuist.packageResolved.url, expectedPackageResolvedFileURL)

XCTAssertEqual(tuist.name, "Tuist")
XCTAssertEqual(tuist.organizationName, "Test Inc.")
}

func testTuist3() throws {
let (exitCode, _) = try zsh("which tuist")
try XCTSkipIf(exitCode != 0, "Tuist not installed")

let (_, data) = try zsh("tuist version")
let tuistVersion = String(decoding: data, as: UTF8.self).trimmingCharacters(in: .whitespacesAndNewlines)
try XCTSkipUnless(tuistVersion.hasPrefix("3."), "Installed Tuist version is not 3.*.* (actual: \(tuistVersion))")

let url = Bundle.module.url(forResource: "Project", withExtension: "swift", subdirectory: "Resources/Tuist3")
let unwrappedURL = try XCTUnwrap(url)

let projectType = try XCTUnwrap(ProjectType(fileURL: unwrappedURL))
Expand All @@ -97,14 +127,18 @@ final class ProjectTests: XCTestCase {
XCTAssertEqual(tuist.organizationName, "Test Inc.")
}

func testTuistDependencies() throws {
func testTuist3Dependencies() throws {
let (exitCode, _) = try zsh("which tuist")
try XCTSkipIf(exitCode != 0)
try XCTSkipIf(exitCode != 0, "Tuist not installed")

let (_, data) = try zsh("tuist version")
let tuistVersion = String(decoding: data, as: UTF8.self).trimmingCharacters(in: .whitespacesAndNewlines)
try XCTSkipUnless(tuistVersion.hasPrefix("3."), "Installed Tuist version is not 3.*.* (actual: \(tuistVersion))")

let url = Bundle.module.url(
forResource: "Dependencies",
withExtension: "swift",
subdirectory: "Resources/TuistDependencies/Tuist"
subdirectory: "Resources/Tuist3Dependencies/Tuist"
)
let unwrappedURL = try XCTUnwrap(url)

Expand Down
14 changes: 14 additions & 0 deletions Tests/SwiftPackageListCoreTests/Resources/Tuist4/.package.resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"pins" : [
{
"identity" : "alamofire",
"kind" : "remoteSourceControl",
"location" : "https://github.com/Alamofire/Alamofire",
"state" : {
"revision" : "3dc6a42c7727c49bf26508e29b0a0b35f9c7e1ad",
"version" : "5.8.1"
}
}
],
"version" : 2
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UIApplicationSceneManifest</key>
<dict>
<key>UIApplicationSupportsMultipleScenes</key>
<false/>
<key>UISceneConfigurations</key>
<dict/>
</dict>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen.storyboard</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
// swiftlint:disable all
// swift-format-ignore-file
// swiftformat:disable all
// Generated using tuist — https://github.com/tuist/tuist

#if os(macOS)
import AppKit
#elseif os(iOS)
import UIKit
#elseif os(tvOS) || os(watchOS)
import UIKit
#endif
#if canImport(SwiftUI)
import SwiftUI
#endif

// swiftlint:disable superfluous_disable_command file_length implicit_return

// MARK: - Asset Catalogs

// swiftlint:disable identifier_name line_length nesting type_body_length type_name
public enum TuistAsset {
public enum Assets {
public static let accentColor = TuistColors(name: "AccentColor")
}
public enum PreviewAssets {
}
}
// swiftlint:enable identifier_name line_length nesting type_body_length type_name

// MARK: - Implementation Details

public final class TuistColors {
public fileprivate(set) var name: String

#if os(macOS)
public typealias Color = NSColor
#elseif os(iOS) || os(tvOS) || os(watchOS)
public typealias Color = UIColor
#endif

@available(iOS 11.0, tvOS 11.0, watchOS 4.0, macOS 10.13, *)
public private(set) lazy var color: Color = {
guard let color = Color(asset: self) else {
fatalError("Unable to load color asset named \(name).")
}
return color
}()

#if canImport(SwiftUI)
private var _swiftUIColor: Any? = nil
@available(iOS 13.0, tvOS 13.0, watchOS 6.0, macOS 10.15, *)
public private(set) var swiftUIColor: SwiftUI.Color {
get {
if self._swiftUIColor == nil {
self._swiftUIColor = SwiftUI.Color(asset: self)
}

return self._swiftUIColor as! SwiftUI.Color
}
set {
self._swiftUIColor = newValue
}
}
#endif

fileprivate init(name: String) {
self.name = name
}
}

public extension TuistColors.Color {
@available(iOS 11.0, tvOS 11.0, watchOS 4.0, macOS 10.13, *)
convenience init?(asset: TuistColors) {
let bundle = TuistResources.bundle
#if os(iOS) || os(tvOS)
self.init(named: asset.name, in: bundle, compatibleWith: nil)
#elseif os(macOS)
self.init(named: NSColor.Name(asset.name), bundle: bundle)
#elseif os(watchOS)
self.init(named: asset.name)
#endif
}
}

#if canImport(SwiftUI)
@available(iOS 13.0, tvOS 13.0, watchOS 6.0, macOS 10.15, *)
public extension SwiftUI.Color {
init(asset: TuistColors) {
let bundle = TuistResources.bundle
self.init(asset.name, bundle: bundle)
}
}
#endif

// swiftlint:enable all
// swiftformat:enable all
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// swiftlint:disable all
// swift-format-ignore-file
// swiftformat:disable all
import Foundation

// MARK: - Swift Bundle Accessor

private class BundleFinder {}

extension Foundation.Bundle {
/// Since Tuist is a application, the bundle for classes within this module can be used directly.
static let module = Bundle(for: BundleFinder.self)
}

// MARK: - Objective-C Bundle Accessor

@objc
public class TuistResources: NSObject {
@objc public class var bundle: Bundle {
return .module
}
}
// swiftlint:enable all
// swiftformat:enable all
37 changes: 37 additions & 0 deletions Tests/SwiftPackageListCoreTests/Resources/Tuist4/Project.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import ProjectDescription

let project = Project(
name: "Tuist",
organizationName: "Test Inc.",
packages: [
.remote(url: "https://github.com/Alamofire/Alamofire", requirement: .upToNextMajor(from: "5.0.0")),
],
targets: [
.target(
name: "Tuist",
destinations: .iOS,
product: .app,
bundleId: "io.tuist.Tuist",
infoPlist: .extendingDefault(
with: [
"UILaunchStoryboardName": "LaunchScreen.storyboard",
]
),
sources: ["Tuist/Sources/**"],
resources: ["Tuist/Resources/**"],
dependencies: [
.package(product: "Alamofire"),
]
),
.target(
name: "TuistTests",
destinations: .iOS,
product: .unitTests,
bundleId: "io.tuist.TuistTests",
infoPlist: .default,
sources: ["Tuist/Tests/**"],
resources: [],
dependencies: [.target(name: "Tuist")]
),
]
)
Loading