Skip to content

Commit

Permalink
Added tests and lint
Browse files Browse the repository at this point in the history
  • Loading branch information
kapitoshka438 committed Apr 12, 2024
1 parent d7f2e7c commit d2d59e6
Show file tree
Hide file tree
Showing 40 changed files with 674 additions and 4 deletions.
3 changes: 3 additions & 0 deletions Sources/TuistAcceptanceTesting/TuistAcceptanceFixtures.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public enum TuistAcceptanceFixtures {
case iosAppWithLocalBinarySwiftPackage
case iosAppWithLocalSwiftPackage
case iosAppWithMultiConfigs
case iosAppWithOnDemandResources
case iosAppWithPluginsAndTemplates
case iosAppWithPrivacyManifest
case iosAppWithRemoteBinarySwiftPackage
Expand Down Expand Up @@ -139,6 +140,8 @@ public enum TuistAcceptanceFixtures {
return "ios_app_with_local_swift_package"
case .iosAppWithMultiConfigs:
return "ios_app_with_multi_configs"
case .iosAppWithOnDemandResources:
return "ios_app_with_on_demand_resources"
case .iosAppWithPluginsAndTemplates:
return "ios_app_with_plugins_and_templates"
case .iosAppWithPrivacyManifest:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation
import TuistGraph

private let ASSET_FORMATS: Set = [
private let assetFormats: Set = [
"arresourcegroup",
"cubetextureset",
"dataset",
Expand Down Expand Up @@ -42,7 +42,7 @@ final class KnownAssetTagsGenerator: KnownAssetTagsGenerating {
target.resources.resources.forEach {
guard let children = try? $0.path.path.recursiveChildren() else { return }
children.forEach {
guard let pathExtension = $0.extension, ASSET_FORMATS.contains(pathExtension) else { return }
guard let pathExtension = $0.extension, assetFormats.contains(pathExtension) else { return }
guard let contents = try? $0.children() else { return }
contents.forEach {
guard $0.lastComponent == "Contents.json" else { return }
Expand Down
11 changes: 11 additions & 0 deletions Sources/TuistGenerator/Linter/TargetLinter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class TargetLinter: TargetLinting {
issues.append(contentsOf: validateCoreDataModelsExist(target: target))
issues.append(contentsOf: validateCoreDataModelVersionsExist(target: target))
issues.append(contentsOf: lintMergeableLibrariesOnlyAppliesToDynamicTargets(target: target))
issues.append(contentsOf: lintOnDemandResourcesTags(target: target))
for script in target.scripts {
issues.append(contentsOf: targetScriptLinter.lint(script))
}
Expand Down Expand Up @@ -292,6 +293,16 @@ class TargetLinter: TargetLinting {
}
return []
}

private func lintOnDemandResourcesTags(target: Target) -> [LintingIssue] {
let intersection = Set(target.odrInitialInstallTags).intersection(Set(target.odrPrefetchOrder))
return intersection.map { tag in
LintingIssue(
reason: "Prefetched Order Tag \"\(tag)\" is already assigned to Initial Install Tags category for the target \(target.name) and will be ingored by Xcode",
severity: .warning
)
}
}
}

extension TargetDependency {
Expand Down
8 changes: 6 additions & 2 deletions Sources/TuistGraphTesting/Models/Target+TestData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,9 @@ extension Target {
environmentVariables: [String: EnvironmentVariable] = [:],
filesGroup: ProjectGroup = .group(name: "Project"),
dependencies: [TargetDependency] = [],
rawScriptBuildPhases: [RawScriptBuildPhase] = []
rawScriptBuildPhases: [RawScriptBuildPhase] = [],
odrInitialInstallTags: [String] = [],
odrPrefetchOrder: [String] = []
) -> Target {
Target(
name: name,
Expand All @@ -160,7 +162,9 @@ extension Target {
environmentVariables: environmentVariables,
filesGroup: filesGroup,
dependencies: dependencies,
rawScriptBuildPhases: rawScriptBuildPhases
rawScriptBuildPhases: rawScriptBuildPhases,
odrInitialInstallTags: odrInitialInstallTags,
odrPrefetchOrder: odrPrefetchOrder
)
}

Expand Down
8 changes: 8 additions & 0 deletions Tests/TuistAcceptanceTests/EditAcceptanceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ final class EditAcceptanceTestSPMPackage: TuistAcceptanceTestCase {
}
}

final class EditAcceptanceTestAppWithOnDemandResources: TuistAcceptanceTestCase {
func test_app_with_on_demand_resources() async throws {
try setUpFixture(.iosAppWithOnDemandResources)
try await run(EditCommand.self)
try build(scheme: "Manifests")
}
}

extension TuistAcceptanceTestCase {
fileprivate func build(scheme: String) throws {
try System.shared.runAndPrint(
Expand Down
28 changes: 28 additions & 0 deletions Tests/TuistGeneratorAcceptanceTests/GenerateAcceptanceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,34 @@ final class GenerateAcceptanceTestiOSAppWithFrameworkAndResources: TuistAcceptan
}
}

final class GenerateAcceptanceTestiOSAppWithOnDemandResources: TuistAcceptanceTestCase {
func test_ios_app_with_on_demand_resources() async throws {
try setUpFixture(.iosAppWithOnDemandResources)
try await run(GenerateCommand.self)
try await run(BuildCommand.self)
let pbxprojPath = xcodeprojPath.appending(component: "project.pbxproj")
let data = try Data(contentsOf: pbxprojPath.url)
let pbxProj = try PBXProj(data: data)
let attributes = try XCTUnwrap(pbxProj.projects.first?.attributes)
let knownAssetTags = try XCTUnwrap(attributes["KnownAssetTags"] as? [String])
let givenTags = [
"ar-resource-group",
"cube-texture",
"data",
"data file",
"datafile",
"datafolder",
"image",
"image-stack",
"json",
"sprite",
"tag with space",
"texture",
]
XCTAssertEqual(knownAssetTags, givenTags)
}
}

final class GenerateAcceptanceTestiOSAppWithPrivacyManifest: TuistAcceptanceTestCase {
func test_ios_app_with_privacy_manifest() async throws {
try setUpFixture(.iosAppWithPrivacyManifest)
Expand Down
17 changes: 17 additions & 0 deletions Tests/TuistGeneratorTests/Linter/TargetLinterTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -454,4 +454,21 @@ final class TargetLinterTests: TuistUnitTestCase {
severity: .warning
))
}

func test_lint_when_target_has_invalid_on_demand_resources_tags() throws {
// Given
let target = Target.empty(
odrInitialInstallTags: ["tag1", "tag2"],
odrPrefetchOrder: ["tag2", "tag3"]
)

// When
let got = subject.lint(target: target)

// Then
XCTContainsLintingIssue(got, .init(
reason: "Prefetched Order Tag \"tag2\" is already assigned to Initial Install Tags category for the target \(target.name) and will be ingored by Xcode",
severity: .warning
))
}
}
70 changes: 70 additions & 0 deletions fixtures/ios_app_with_on_demand_resources/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
### macOS ###
# General
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two
Icon

# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

### Xcode ###
# Xcode
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore

## User settings
xcuserdata/

## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9)
*.xcscmblueprint
*.xccheckout

## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4)
build/
DerivedData/
*.moved-aside
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3

### Xcode Patch ###
*.xcodeproj/*
!*.xcodeproj/project.pbxproj
!*.xcodeproj/xcshareddata/
!*.xcworkspace/contents.xcworkspacedata
/*.gcno

### Projects ###
*.xcodeproj
*.xcworkspace

### Tuist derived files ###
graph.dot
Derived/

### Tuist managed dependencies ###
Tuist/.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"on-demand-resource-tags" : [
"ar-resource-group"
]
},
"resources" : [

]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"colors" : [
{
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
{
"images" : [
{
"idiom" : "iphone",
"scale" : "2x",
"size" : "20x20"
},
{
"idiom" : "iphone",
"scale" : "3x",
"size" : "20x20"
},
{
"idiom" : "iphone",
"scale" : "2x",
"size" : "29x29"
},
{
"idiom" : "iphone",
"scale" : "3x",
"size" : "29x29"
},
{
"idiom" : "iphone",
"scale" : "2x",
"size" : "40x40"
},
{
"idiom" : "iphone",
"scale" : "3x",
"size" : "40x40"
},
{
"idiom" : "iphone",
"scale" : "2x",
"size" : "60x60"
},
{
"idiom" : "iphone",
"scale" : "3x",
"size" : "60x60"
},
{
"idiom" : "ipad",
"scale" : "1x",
"size" : "20x20"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "20x20"
},
{
"idiom" : "ipad",
"scale" : "1x",
"size" : "29x29"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "29x29"
},
{
"idiom" : "ipad",
"scale" : "1x",
"size" : "40x40"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "40x40"
},
{
"idiom" : "ipad",
"scale" : "1x",
"size" : "76x76"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "76x76"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "83.5x83.5"
},
{
"idiom" : "ios-marketing",
"scale" : "1x",
"size" : "1024x1024"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}

0 comments on commit d2d59e6

Please sign in to comment.