You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/index.md
+56-2
Original file line number
Diff line number
Diff line change
@@ -2590,8 +2590,8 @@ The real power, of labels, however, is around filtering. You can filter by labe
2590
2590
- The `!` unary operator representing the NOT operation.
2591
2591
- The `,` binary operator equivalent to `||`.
2592
2592
- The `()` for grouping expressions.
2593
-
- All other characters will match as label literals. Label matches are **case insensitive** and trailing and leading whitespace is trimmed.
2594
2593
- Regular expressions can be provided using `/REGEXP/` notation.
2594
+
- All other characters will match as label literals. Label matches are **case insensitive** and trailing and leading whitespace is trimmed.
2595
2595
2596
2596
To build on our example above, here are some label filter queries and their behavior:
2597
2597
@@ -2602,10 +2602,63 @@ To build on our example above, here are some label filter queries and their beha
2602
2602
|`ginkgo --label-filter="network && !slow"`| Run specs labelled `network` that aren't `slow`|
2603
2603
| `ginkgo --label-filter=/library/` | Run specs with labels matching the regular expression `library` - this will match the three library-related specs in our example.
2604
2604
2605
+
##### Label Sets
2606
+
2607
+
In addition to flat strings, Labels can also construct sets. If a label has the format `KEY:VALUE` then a set with key `KEY` is created and the value `VALUE` is added to the set. For example:
It("can fetch a list of books by shelf", Label("API:Shelf", "Readiness:Alpha"), func() {
2616
+
// has the labels [API:Library, API:Shelf, Readiness:Alpha]
2617
+
// API is a set with value {Library, Shelf}
2618
+
// Readiness is a set with value {Alpha}
2619
+
2620
+
})
2621
+
It("can fetch a list of books by zip code", Label("API:Geo", "Readiness:Beta"), func() {
2622
+
// has the labels [API:Library, API:Geo, Readiness:Beta]
2623
+
// API is a set with value {Library, Geo}
2624
+
// Readiness is a set with value {Beta}
2625
+
})
2626
+
})
2627
+
```
2628
+
2629
+
Label filters can operate on sets using the notation: `KEY: SET_OPERATION <ARGUMENT>`. The following set operations are supported:
2630
+
2631
+
| Set Operation | Argument | Description |
2632
+
| --- | --- | --- |
2633
+
|`isEmpty`| None | Matches if the set with key `KEY` is empty (i.e. no label of the form `KEY:*` exists) |
2634
+
|`containsAny`|`SINGLE_VALUE` or `{VALUE1, VALUE2, ...}`| Matches if the `KEY` set contains _any_ of the elements in `ARGUMENT`|
2635
+
|`containsAll`|`SINGLE_VALUE` or `{VALUE1, VALUE2, ...}`| Matches if the `KEY` set contains _all_ of the elements in `ARGUMENT`|
2636
+
|`consistsOf`|`SINGLE_VALUE` or `{VALUE1, VALUE2, ...}`| Matches if the `KEY` set contains _exactly_ the elements in `ARGUMENT`|
2637
+
|`isSubsetOf`|`SINGLE_VALUE` or `{VALUE1, VALUE2, ...}`| Matches if the elements in the `KEY` set are a subset of the elements in `ARGUMENT`|
2638
+
2639
+
leading and trailing whitespace is alwasy trimmed around keys and values and comparisons are always case-insensitive. Keys and values in the filter-language set operations are always literals; regular expressions are not supported. A special note should be made about the behavior of `isSubsetOf`: if the `KEY` set is empty then the filter will always match. This is because an empty set is always a subset of any other set.
2640
+
2641
+
You can combine set operations with other label filters using the logical operators. For example: `ginkgo --label-filter="integration && !slow && Readiness: isSubsetOf {Beta, RC}"` will run all tests that have the label `integration`, do not have the label `slow` and have a `Readiness` set that is a subset of `{Beta, RC}`. This would exclude `Readiness:Alpha` but include specs with `Readiness:Beta` and `Readiness:RC` as well as specs with no `Readiness:*` label.
2642
+
2643
+
Some more examples:
2644
+
2645
+
| Query | Behavior |
2646
+
| --- | --- |
2647
+
|`ginkgo --label-filter="API: consistsOf {Library, Geo}"`| Match any specs for which the `API` set contains exactly `Library` and `Geo`|
2648
+
|`ginkgo --label-filter="API: containsAny Library"`| Match any specs for which the `API` set contains either `Library`|
2649
+
|`ginkgo --label-filter="Readiness: isEmpty"`| Match any specs for which the `Readiness` set is empty |
2650
+
|`ginkgo --label-filter="Readiness: isSubsetOf Beta && !(API: containsAny Geo)"`| Match any specs for which the `Readiness` set is a subset of `{Beta}` (or empty) and the `API` set does not contain `Geo`|
2651
+
2652
+
Label sets are helpful for organizing and filtering large spec suites in which different specs satisfy multiple overlapping concerns. The use of label set filters is intended to be a more powerful and expressive alterantive to the use of regular expressions. If you find yourself using a regular expression, consider if you should be using a label set instead.
2653
+
2654
+
##### Listing Labels
2655
+
2605
2656
You can list the labels used in a given package using the `ginkgo labels` subcommand. This does a simple/naive scan of your test files for calls to `Label` and returns any labels it finds.
2606
2657
2607
2658
You can iterate on different filters quickly with `ginkgo --dry-run -v --label-filter=FILTER`. This will cause Ginkgo to tell you which specs it will run for a given filter without actually running anything.
2608
2659
2660
+
##### Runtime Label Evaluation
2661
+
2609
2662
If you want to have finer-grained control within a test about what code to run/not-run depending on what labels match/don't match the filter you can perform a manual check against the label-filter passed into Ginkgo like so:
here `GinkgoLabelFilter()` returns the configured label filter passed in via `--label-filter`. With a setup like this you could run `ginkgo --label-filter="network && !performance"` - this would select the `"can save books remotely"` spec but not run the benchmarking code in the spec. Of course, this could also have been modeled as a separate spec with the `performance` label.
2622
2675
2676
+
##### Suite-Level Labels
2677
+
2623
2678
Finally, in addition to specifying Labels on subject and container nodes you can also specify suite-wide labels by decorating the `RunSpecs` command with `Label`:
Suite-level labels apply to the entire suite making it easy to filter out entire suites using label filters.
2633
2688
2634
-
2635
2689
#### Location-Based Filtering
2636
2690
2637
2691
Ginkgo allows you to filter specs based on their source code location from the command line. You do this using the `ginkgo --focus-file` and `ginkgo --skip-file` flags. Ginkgo will only run specs that are in files that _do_ match the `--focus-file` filter *and*_don't_ match the `--skip-file` filter. You can provide multiple `--focus-file` and `--skip-file` flags. The `--focus-file`s will be ORed together and the `--skip-file`s will be ORed together.
0 commit comments