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

Support test target for local Swift Package #1074

Closed
wants to merge 0 commits into from
Closed

Conversation

freddi-kit
Copy link
Collaborator

Close: #1050

note: This PR needs to wait for releasing new version of tuist/XcodeProj with tuist/XcodeProj#605

Package.resolved Outdated
"branch": null,
"revision": "94e55232d227f9d78b811c98cb2e5d0cbd08987b",
"version": "7.22.0"
"branch": "main",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't use an unstable version.

This PR may depend on this patch.
Allows passing BuildableIdentifier String to BuildableReference initializer by freddi-kit · Pull Request #605 · tuist/XcodeProj

It's better to distribute newer XcodeProj.

Copy link
Collaborator Author

@freddi-kit freddi-kit May 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also wanna use new stable XcoreProj version with my patch, so I will modify it after new version released.
That's why this Pull Request is still Draft.

Copy link
Collaborator

@kateinoigakukun kateinoigakukun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have two comments about this PR:

  1. Is this feature limited to test targets? I think we can relax the limitation for non-test targets.

  2. Since this change, ProjectName/TargetName syntax represents a reference to a .xcodeproj or a SwiftPM package, right? Then, what happens when the given project.yml is like below:

projectReferences:
  Foo:
    path: ./Foo.xcodeproj
packages:
  Foo:
    url: ./Elsewhere/Foo

In your implementation, SwiftPM package version will be chosen, but it's not clear for users.
So we should have a single namespace for external project names or we can have a new syntax to represent a target reference for SwiftPM, but I have no idea to represent such structure with current project.yml syntax, sorry

@freddi-kit
Copy link
Collaborator Author

@kateinoigakukun

Thanks, basically, I totally agree with your ideas.

About 1., we can expand to another thing which using TargetReference type like coverageTargets, BuildTarget and more. It would be useful and not need to make more changes if it would be supported by many places.

And currently, my changes cause ambiguous format ("/" for project and package), as you explained 2, so I'm concerning change the format a little more clear.

@freddi-kit
Copy link
Collaborator Author

freddi-kit commented May 7, 2021

I have an idea for solving these 2 concerns: Having a new Yaml(JSON) format for TargetReference Type.

I feel this discussion is based on how TargetReference type is treated. Currently, TargetReference is generated by one string like the below code from yml file.

public init(_ string: String) throws {
let paths = string.split(separator: "/")
switch paths.count {
case 2:
location = .project(String(paths[0]))
name = String(paths[1])
case 1:
location = .local
name = String(paths[0])
default:
throw SpecParsingError.invalidTargetReference(string)
}
}
public static func local(_ name: String) -> TargetReference {
TargetReference(name: name, location: .local)
}

And used for many places like testTartgets and coverageTargets.

I think we can change TargetReference to have new format like below and make it convertible from Yaml(JSON)

- project: Project/ProjectTest
- package: Package/PackageTest
- local: LocalTest

What do you think about it?

@kateinoigakukun
Copy link
Collaborator

+1 for adding a new syntax in TargetReference 👍

@freddi-kit freddi-kit marked this pull request as ready for review May 25, 2021 16:50
@freddi-kit
Copy link
Collaborator Author

@kateinoigakukun @giginet
I changed code from @kateinoigakukun 's comment:

  • use new TargetReference fomat for specifying local swift package test case on Test scheme (targets and coverageTargets)

Please help review it, Thanks

@mthole
Copy link
Contributor

mthole commented Aug 2, 2021

@yonaskolb @freddi-kit Thanks for your work here! Can we get this work landed soon? I am running into this exact problem and a fix in mainline XcodeGen would be much appreciated!

@freddi-kit
Copy link
Collaborator Author

Ops, sorry for leaving it so long time. I worked on it but I stopped because it has some difficulty to achieve it. This change make the project spec confusable so I was finding a way to solve it. I have the motivation and I probably find out the way to do it without making spec complex. Let me touch you until this week!

@razor313
Copy link

@freddi-kit Could you find a way in order to solve it in an easy way? We're waiting for it. :)))

@freddi-kit
Copy link
Collaborator Author

@freddi-kit Could you find a way in order to solve it in an easy way? We're waiting for it. :)))

I'm sorry for waiting you for long time, this difficulty is about the internal API things and I just commited!

@freddi-kit freddi-kit requested a review from yonaskolb October 20, 2021 13:24
@dehlen
Copy link

dehlen commented Oct 26, 2021

Really looking forward to this. Any idea when you'll find time going over these changes @yonaskolb ?

Copy link
Owner

@yonaskolb yonaskolb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this again @freddi-kit, looks good to me! Only thing I'm slightly hesitant about is the syntax for declaring a test target is a bit verbose with the nested target.

testTargets:
         - target:
             package: XcodeGen/XcodeGenKitTests
           parallelizable: true

One other option would be to decode the TestableTargetReference at the top level, but I think how you have it is ok, and makes for cleaner code.

testTargets:
         - package: XcodeGen/XcodeGenKitTests
           parallelizable: true

What I would like to see though is some parsing and validation tests to cover this (SpecLoadingTests.testProjectSpecParser, ProjectSpectTests.testValidation), and then we can get this merged in! 👍

targets:
- Tester1
- name: Tester2
parallelizable: true
randomExecutionOrder: true
skippedTests: [Test/testExample()]
- target:
package: APIClient/APIClientTests
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
package: APIClient/APIClientTests
package: APIClient/APIClientTests

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not really consistent in the way the current yml is constructed. Is there a specific reason why this is indented here?

A target can be one of a 2 types:

- **name**: **String** - The name of the target. If you want to specify local swift package, please use `target:`.
- **target**: **[Testable Target Reference](#target-reference)** - The information of the target. You can specify more detailed information than `name:`.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This link to the Testable Target section is incorrect here. It should be:
**[Testable Target Reference](#testable-target-reference)**

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's right, nice find 👍

@jakeheis
Copy link

@freddi-kit I'd be happy to open up a PR with the requested parsing and validation tests if you'd like some help getting this across the finish line

@mthole
Copy link
Contributor

mthole commented Nov 22, 2021

FYI, I updated our project to point to this branch and successfully used the new functionality! 🚀 Looking forward to getting this in the mainline

@razor313
Copy link

razor313 commented Dec 7, 2021

@freddi-kit I see the PR has been approved, Could you please update/merge it.

@skofgar
Copy link
Contributor

skofgar commented Jan 14, 2022

Hi everyone, I was curious if this is still planned to be updated/merged at some point?

import Foundation
import JSONUtilities

public struct TestableTargetReference: Hashable {
Copy link
Contributor

@skofgar skofgar Jan 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of introducing TestableTargetReference would it be possible to just enhance TargetReference. I'm asking because build targets can also be in local Swift Packages and not just test targets?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is because we already have packages: things which is almost same with targets: but for only swift package. And I tried to do so but there is a problem that it make confuses with packages. I wanna keep them clear as possible

@ghost
Copy link

ghost commented Jan 20, 2022

I used truecaller/XcodeGen.git, but I don't see any package in testTargets show on .xcscheme

    scheme:
      testTargets:
        - target:
          package: HappyTests
        - target:
          local: DebugToolTests
        - target:
          local: Modules/HappyTests
        - target:
          package: Modules/ZTests

but this way work.

    scheme:
      testTargets:
        - target:
            package: Modules/HappyTests

@fousa
Copy link

fousa commented Feb 2, 2022

Is there any progress on this ticket? I would be happy to help.

We currently have a modular setup like this:

  • App
  • AppTests
  • Modules/Network
  • Modules/Network/NetworkTests
  • Modules/Flow
  • Modules/Flow/FlowTests

And I would like to create an AllTests scheme that runs the following tests:

  • AppTests
  • Modules/Network/NetworkTests
  • Modules/Flow/FlowTests

I think I have the perfect example to try out this pull request, so let me know if I can help!

@freddi-kit
Copy link
Collaborator Author

I'm sorry for making you waiting so long time, I finally fixed comments from @yonaskolb, please check.

@freddi-kit
Copy link
Collaborator Author

ops. I closed PR by mistake and it looks i cannot reopen it, please wait

@freddi-kit
Copy link
Collaborator Author

Reopened #1169

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

How to add testTargets from local swift package to targets in Xcodegen?