Skip to content

Excluding specs based on location and name/pattern #15528

Open
@straight-shoota

Description

@straight-shoota

Several times now I've come across the use case that I wanted to run specs, but skip some of the examples that would usually run.
For example for #15186 (comment) I'd like to pass a flag to make primitive_spec that runs the entire spec suite except for spec/primitives/external_command_spec.cr.

Currently, it's possible to include specific locations with the --location <file>:<line> option (which implicitly excludes all other locations).
Tags can be used as exclusion with the ~ modifier: (--tag ~<tag>). But that obviously requires a tag.

Of course one could mark specific examples as pending in the source code. But that requires rebuilding the spec suite which can be quite resource intensive or not easily available (when cross-compiling, for example).

Exclusion by location

It would be nice to have a location filter to exclude specific examples.

The CLI could get another option for this, maybe --exclude or --skip which receives the same format as --location and acts as an exclusion filter.
Another option would be to integrate into the --location filter with a modifier, just like it works for tags.
Trouble here would be that in Unix semantics a path starting with ~ points to the home path of a user. So using the same syntax as for tags wouldn't quite work.
Another character commonly used for exclusion is ! (e.g. in .gitignore) but in many shells ! has a special meaning as a history command. So not a good choice either.
Perhaps - could work. It would create ambiguity when a file in the current directory starts with -. While that's technically possible, it's probably not very common for spec files and folders.

Exclusion by name

crystal spec currently has one option --example STRING (or -e STRING) to only execute examples which contain STRING in their name (it's supposed to cover the entire name, but is currently limited to each name fragment, see #10810).

I would like to have an option to exclude specific examples. When I know that one particular example is broken, I don't need to run it again until I'm able to fix it.

I'm thinking of basically the inversion of the --example option to specify an example that I don't want to execute.
Combinations betwen positive and negative filters should be possible.

Inclusion/Exclusion by pattern

Another missing feature for example filtering is pattern matching for the name. Not sure how relevant that is, but it would offer some more flexibility over plain string matching. Anyway it's worth considering this with regards to the inverse filtering feature as well.
rspec has --example-matches for this.
This might be out of scope though.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions