Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@CraigSiemens
Copy link
Contributor

@CraigSiemens CraigSiemens commented Jul 6, 2023

Adds a TestState property wrapper

The main difference from the original implementation is it tries to detect which "World" is currently running tests, then add's the afterEach/aroundEach to that world. I'm not 100% sure if that's the right approach or if there's another way to add those to the current world.

From the original PR description

It will always reset a property to nil at the end of a test. If the property wrapper is created with a value, the value will be set at the start of a test.

Checklist - While not every PR needs it, new features should consider this list:

  • Does this have tests?
  • Does this have documentation?
  • Does this break the public API (Requires major version bump)?
  • Is this a new feature (Requires minor version bump)?

It's for use in tests where a property should be reset to either nil or an initial value between tests.
@CraigSiemens CraigSiemens force-pushed the test-state-property-wrapper branch from b9e0735 to fbdda51 Compare July 6, 2023 21:28
Copy link
Member

@younata younata 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 re-adding this!

@younata younata merged commit c6a3fba into Quick:main Jul 6, 2023
@tahirmt
Copy link
Contributor

tahirmt commented Jul 26, 2023

@younata when it was removed from Quick, we created separate property wrappers namespaced within QuickSpec and AsyncSpec. Is this approach better? Is it possible to have any errors in the approach in this PR?

@younata
Copy link
Member

younata commented Jul 26, 2023

Is this approach better?

There's no namespacing required with this approach. I don't know enough about how you implemented this to know whether it'll interfere with your approach.

Is it possible to have any errors in the approach in this PR?

If XCTest ever does run test discovery in parallel, then there's the potential for errors as AsyncWorld.sharedWorld.currentExampleGroup and World.sharedWorld.currentExampleGroup could both be non-nil at the same time. Right now, XCTest runs test discovery synchronously. If this ever changes, we will have to either figure out a way to explicitly disable parallelized test discovery, or do a significant amount of engineering work to get Quick's DSL to work with parallelized test discovery.

I don't think it's worth worrying about parallelized test discovery at the moment.

I'm more than happy to release this as a beta, if you'd like. Otherwise, I was planning to release it as part of 7.2.0 on Friday morning.

@tahirmt
Copy link
Contributor

tahirmt commented Jul 26, 2023

I was worried about parallelized testing but if runnings tests in parallel doesn’t change how currentExampleGroup works, that sounds good. Thanks for your reply.

@younata
Copy link
Member

younata commented Jul 26, 2023

Yes. That's correct. currentExampleGroup is determined at test discovery time, not during test runtime. Parallelized testing won't have any effect here.

Edit:

The way that XCTest does test parallelization is that each parallelized test runs in a separate process. So there's no chance for both those variables to be non-nil at the same time.

cgrindel-self-hosted-renovate bot referenced this pull request in cgrindel/rules_swift_package_manager Aug 24, 2023
This PR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [Quick/Quick](https://togithub.com/Quick/Quick) | minor | `from:
"7.1.0"` -> `from: "7.2.0"` |

---

### Release Notes

<details>
<summary>Quick/Quick (Quick/Quick)</summary>

### [`v7.2.0`](https://togithub.com/Quick/Quick/releases/tag/v7.2.0): -
TestState property wrapper

[Compare
Source](https://togithub.com/Quick/Quick/compare/v7.1.0...v7.2.0)

### Highlight

You can now use the `@TestState` property wrapper to automatically
deconstruct test variables. For example:

```swift
describe("using TestState") {
    @&#8203;TestState var subject: SomeObject?
}
```

Is functionally equivalent to:

```swift
describe("using TestState") {
    var subject: SomeObject?
    afterEach {
        subject = nil
    }
}
```

You can also specify an initial value, and `TestState` will act as an
`aroundEach`: setting the wrapped variable to the value, then setting it
to nil at test teardown.

```swift
describe("using TestState") {
    @&#8203;TestState(1) var value: Int?

    it("is already configured") {
        expect(value).to(equal(1))
    }
}
```

Thanks [@&#8203;CraigSiemens](https://togithub.com/CraigSiemens) for
their contribution!

### Automated Release Notes

#### What's Changed

- Added a TestState property wrapper, again :D by
[@&#8203;CraigSiemens](https://togithub.com/CraigSiemens) in
[https://github.com/Quick/Quick/pull/1233](https://togithub.com/Quick/Quick/pull/1233)

**Full Changelog**:
Quick/Quick@v7.1.0...v7.2.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR is behind base branch, or you tick the
rebase/retry checkbox.

👻 **Immortal**: This PR will be recreated if closed unmerged. Get
[config help](https://togithub.com/renovatebot/renovate/discussions) if
that's undesired.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Renovate
Bot](https://togithub.com/renovatebot/renovate).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNi41Ny4yIiwidXBkYXRlZEluVmVyIjoiMzYuNTcuMiIsInRhcmdldEJyYW5jaCI6Im1haW4ifQ==-->

Co-authored-by: Self-hosted Renovate Bot <361546+cgrindel-self-hosted-renovate[bot]@users.noreply.github.enterprise.com>
@CraigSiemens CraigSiemens deleted the test-state-property-wrapper branch August 31, 2023 22:52
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.

3 participants