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

LinuxMain template #125

Merged
merged 1 commit into from Jan 18, 2017
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
43 changes: 43 additions & 0 deletions README.md
Expand Up @@ -245,6 +245,49 @@ to this:
- `skipEquality` allows you to skip variable from being compared.
</details>

<details>
<summary>I want to generate `LinuxMain.swift` for all my tests</summary>

For all test cases generates `allTests` static variable and passes all of them as `XCTestCaseEntry` to `XCTMain`. Run with `--args testimports='import MyTests'` parameter to import test modules.

#### [Stencil template](Templates/LinuxMain.stencil)

#### Available annotations:

- `disableTests` allows you to disable the whole test case.

#### Example output:

```swift
import XCTest
//testimports

extension AutoInjectionTests {
static var allTests = [
("testThatItResolvesAutoInjectedDependencies", testThatItResolvesAutoInjectedDependencies),
...
]
}

extension AutoWiringTests {
static var allTests = [
("testThatItCanResolveWithAutoWiring", testThatItCanResolveWithAutoWiring),
...
]
}

...

XCTMain([
testCase(AutoInjectionTests.allTests),
testCase(AutoWiringTests.allTests),
...
])

```

</details>

## Writing templates
*Sourcery templates are powered by [Stencil](https://github.com/kylef/Stencil)*

Expand Down
14 changes: 14 additions & 0 deletions Templates/LinuxMain.stencil
@@ -0,0 +1,14 @@
import XCTest
{{ argument.testimports }}
{% for type in types.classes|based:"XCTestCase" %}
{% if not type.annotations.disableTests %}extension {{ type.name }} {
static var allTests = [
{% for method in type.methods %}{% if method.parameters.count == 0 and method.shortName|hasPrefix:"test" %} ("{{ method.shortName }}", {{ method.shortName }}),
{% endif %}{% endfor %}]
}
{% endif %}{% endfor %}

XCTMain([
{% for type in types.classes|based:"XCTestCase" %}{% if not type.annotations.disableTests %} testCase({{ type.name }}.allTests),
{% endif %}{% endfor %}])