Skip to content

Instantly share code, notes, and snippets.

@wessmith
Created October 20, 2015 19:03
Show Gist options
  • Save wessmith/df5785625ed4a1025e8c to your computer and use it in GitHub Desktop.
Save wessmith/df5785625ed4a1025e8c to your computer and use it in GitHub Desktop.
Generate warnings when focusing tests with Specta
#!/bin/sh
FOCUS="fit\(|fdescribe\(|fcontext\("
find "${SRCROOT}/Path/To/Tests" \( -name "*.m" \) -print0 | xargs -0 egrep --with-filename --line-number --only-matching "($FOCUS).*\$" | perl -p -e "s/($FOCUS)/ warning: \$1/"
@wessmith
Copy link
Author

In your test bundle target Build Phases:

  • Add a run script phase "Specta Focus Check"
  • Paste in the contents of the above script
  • Be sure to update the path to point to the directory of your tests

screen shot 2015-10-20 at 3 07 36 pm

Alternatively (for better diffs)

  • Add the script as a new tracked file in your project directory
  • Add a run script phase "Specta Focus Check"
  • Invoke the script from the run script phase:
"${SRCROOT}/Path/To/Tests/BuildScripts/specta-focus-check.sh"

screen shot 2015-10-20 at 3 08 21 pm

Result
screen shot 2015-10-21 at 11 36 35 am

@modocache
Copy link

This is awesome!! 😍

I wonder, should Specta define fit and friends as macros such that they could add #warning pragmas? That would display warnings inline. Separate function definitions would have to be kept for Swift support, though.

This might also make a great Clang plugin. /cc @kastiglione

@briancroom
Copy link

Cedar's approach to this is to treat the overall test run as a failure if any tests are marked as focused. This lets a CI script flag the build if a commit slips through with a focused test.

https://github.com/pivotal/cedar/blob/master/Source/Reporters/CDRDefaultReporter.m#L63

@modocache
Copy link

@briancroom that's really neat. But when running via Xcode, does that display a "tests failed" overlay?

@wessmith
Copy link
Author

@modocache Love the idea of including it in Specta!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment