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

Allow to not attach a debugger to the test process #3813

Merged
merged 1 commit into from Dec 13, 2021

Conversation

svenmuennich
Copy link
Contributor

Resolves n/a
Request for comments document (if applies): n/a

Short description πŸ“

In Xcode's scheme editor a test action can be configured to either attach a debugger to the test process or not:

Screenshot 2021-12-10 at 08 03 38

Currently tuist always sets the configuration to attach the debugger and there is no way to prevent this. This PR adds a new field to TestAction for configuring whether a debugger will be attached or not. The field defaults to true to not change the behavior for existing projects.

Why is this change necessary?

In our code base we make heavy use of assertion testing via Nimble's throwAssertion() matcher. This matcher does not work when a debugger is attached though (at least on Apple Silicon). Hence we want to be able to not attach a debugger to the test process by default to make the tests run smoothly.

Checklist βœ…

  • The code architecture and patterns are consistent with the rest of the codebase.
  • The changes have been tested following the documented guidelines.
  • The CHANGELOG.md has been updated to reflect the changes. In case of a breaking change, it's been flagged as such.
  • In case the PR introduces changes that affect users, the documentation has been updated.
  • In case the PR introduces changes that affect how the cache artifact is generated starting from the TuistGraph.Target, the Constants.cacheVersion has been updated.

@svenmuennich svenmuennich force-pushed the pickware/test-action-attach-debugger branch from 455934f to c90a3b8 Compare December 10, 2021 07:16
Copy link
Contributor

@pepicrft pepicrft left a comment

Choose a reason for hiding this comment

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

Excellent contribution @svenmuennich. Besides the comment that I left, I'd update the CHANGELOG.md to mention that you are introducing this functionality. Moreover, I noticed the option exists in run action. Would you mind adding it there too for consistency reasons?

@@ -64,6 +70,7 @@ public struct TestAction: Equatable, Codable {
public static func targets(_ targets: [TestableTarget],
arguments: Arguments? = nil,
configuration: ConfigurationName = .debug,
attachDebugger: Bool = true,
Copy link
Contributor

Choose a reason for hiding this comment

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

Because by default we don't set the value, the default here should be false. Otherwise it'll be a breaking change for users.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe I am missing something, but before my changes a debugger was always attached implicitly by not setting selectedDebuggerIdentifier here and hence using its default value, which is XCScheme.defaultDebugger. So to prevent this from breaking anything, the default here needs to be true, does it not?

Copy link
Collaborator

Choose a reason for hiding this comment

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

You're right, to ensure it isn't a breaking change the default would need to be true

@pepicrft
Copy link
Contributor

@all-contributors add @svenmuennich for code

@allcontributors
Copy link
Contributor

@pepicrft

I've put up a pull request to add @svenmuennich! πŸŽ‰

@pepicrft
Copy link
Contributor

@svenmuennich I made you contributor of the project so that you can push directly your branches to this repository. Doing contributions through forks is very annoying, so we don't want you to suffer from that :P

@svenmuennich
Copy link
Contributor Author

Moreover, I noticed the option exists in run action. Would you mind adding it there too for consistency reasons?

For the run action the logic is a bit more complex, since we already have some logic for this option to treat normal schemes and schemes for app extensions differently. That is, currently the debugger is only attached for normal schemes but never for app extension schemes. I can add the option there too, which would lead to the following behaviour:

scheme type attachDebugger is attaching debugger
normal true βœ…
normal false ❌
app extension true ❌
app extension false ❌

@pepicrft
Copy link
Contributor

For the run action the logic is a bit more complex, since we already have some logic for this option to treat normal schemes and schemes for app extensions differently. That is, currently the debugger is only attached for normal schemes but never for app extension schemes. I can add the option there too, which would lead to the following behaviour:

This would be awesome. If you think the behaviour might be misleading for users, we can add a note in the documentation explaining how the debugger is attached depending on the type of scheme. Thanks a lot @svenmuennich

@svenmuennich svenmuennich force-pushed the pickware/test-action-attach-debugger branch from c90a3b8 to 4d47a01 Compare December 10, 2021 10:08
@@ -1441,57 +1626,6 @@ final class SchemeDescriptorsGeneratorTests: XCTestCase {
])
}

func test_generate_appExtensionSchemeLaunchAction() throws {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I renamed this test to test_schemeLaunchAction_for_app_extension

@svenmuennich
Copy link
Contributor Author

I added the functionality to RunAction as well.

@svenmuennich svenmuennich marked this pull request as ready for review December 10, 2021 10:11
Copy link
Collaborator

@kwridan kwridan 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 contributing this @svenmuennich !

Once we address the small issue this should be good to go πŸš€

debuggerIdentifier = ""
} else {
launchActionConstants = .default
debuggerIdentifier = scheme.runAction?.attachDebugger == true ? XCScheme.defaultDebugger : ""
Copy link
Collaborator

Choose a reason for hiding this comment

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

This has a subtle issue - by default many schemes may omit explicitly specifying a runAction (i.e. it will be nil) - as such we'd be disabling the debugger option for them whereas before it was enabled :/

An example of this is the automatically generated -Project workspace scheme.

project-scheme

Suggested change
debuggerIdentifier = scheme.runAction?.attachDebugger == true ? XCScheme.defaultDebugger : ""
if let runAction = scheme.runAction {
debuggerIdentifier = runAction.attachDebugger ? XCScheme.defaultDebugger : ""
} else {
debuggerIdentifier = XCScheme.defaultDebugger
}

It may be worth expanding the tests to cover this case if they don't already.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good find 😲 I fixed this as suggested and added a test for this πŸ‘

@svenmuennich svenmuennich force-pushed the pickware/test-action-attach-debugger branch from 4d47a01 to 5577e33 Compare December 10, 2021 11:40
Copy link
Collaborator

@kwridan kwridan 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 the updates

@fortmarek fortmarek merged commit 976ffca into tuist:main Dec 13, 2021
@svenmuennich svenmuennich deleted the pickware/test-action-attach-debugger branch December 14, 2021 11:24
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.

None yet

5 participants