Skip to content

[testing-support][intellij-bazel] specs2 gutter triangles + Bazel --test_filter (#SCL-25391)#718

Open
gosha212 wants to merge 3 commits into
JetBrains:idea261.xfrom
gosha212:feat/specs2-gutter-and-bazel-filter
Open

[testing-support][intellij-bazel] specs2 gutter triangles + Bazel --test_filter (#SCL-25391)#718
gosha212 wants to merge 3 commits into
JetBrains:idea261.xfrom
gosha212:feat/specs2-gutter-and-bazel-filter

Conversation

@gosha212
Copy link
Copy Markdown

@gosha212 gosha212 commented May 5, 2026

Summary

Closes #SCL-25391.

Two related fixes for IntelliJ Scala's Specs2 support:

  1. [testing-support] Per-test gutter triangles for specs2. ScalaTestRunLineMarkerProvider#infoForTestMethodRef previously had cases for ScalaTest and MUnit but not Specs2, so individual tests ("x" in {…}, >>, !) and scope blocks (should, can) had no gutter icons even though the class itself did. Adds a Specs2TestLocationsFinder parallel to ScalaTestTestLocationsFinder, using the existing TestNodeProvider.isSpecs2TestExpr/isSpecs2ScopeExpr predicates already shared with Specs2ConfigurationProducer.

  2. [intellij-bazel] Bazel --test_filter for specs2. Following SCL-24481 (PR SCL-24481: Support running separate ScalaTest tests via Bazel #709) which wired ScalaTest+ZIO single-test filters via BazelScalaTestRunLineMarkerLogic, this restores specs2 parity. Without it, clicking the gutter on a specs2 spec produces --test_filter=<classFQN>, which fails to whole-string-match specs2-junit's scope-prefixed Description names — JUnit4Runner reports No tests found matching RegEx. Adds Specs2BazelTestFilter, a Scala 3 port of Google's deleted IJwB Specs2Utils.java (commit f62b2670648d, removed in 36a4550602 "Remove IJwB build (#7868)"). Filter format identical to Google's:

    • test ref: <classFQN>#\Q<scope> should::<test>\E$
    • scope ref: <classFQN>#\Q<scope> should\E::

Architecture note

Specs2BazelTestFilter lives in testing-support (Scala 2.13) rather than intellij-bazel (Scala 3) for two reasons:

  1. It is a pure PSI-to-string utility with no Bazel-runtime dependency — only the call site in BazelScalaTestRunLineMarkerLogic is bazel-specific.
  2. intellij-bazel has no test source root today; testing-support already has ScalaFixtureTestCase infrastructure used by the unit test (Specs2BazelTestFilterTest).

Tests

  • Specs2BazelTestFilterTest (new) — 7 cases covering top-level in, scoped in/>> (under should), in under can, should scope, can scope, and a non-test-element negative case. Uses the new WithSpecs2_4 fixture trait.
  • Specs2RunLineMarkerProviderTest for the gutter side will land as a follow-up commit on this branch — the IntelliJ test fixture boot is slow on our hardware and we wanted to surface the changes for review without further delay.

Verification

  • sbt testing-support/Test/compile and sbt intellij-bazel/Compile/compile both pass on JDK 21.
  • Manual smoke test: opened a scala_specs2_junit_test Bazel target in the sandboxed IDE, clicked gutter triangles on test/scope/class, confirmed each generates the expected filter and runs.

Related

  • SCL-24481 / SCL-24481: Support running separate ScalaTest tests via Bazel #709 — parent change that introduced Bazel run-line-markers for ScalaTest and ZIO. This extends that work to specs2.
  • bazelbuild/intellij commit f62b2670648d — Google IJwB Scala plugin's specs2 producer (since deleted), source of the proposed filter format.

gosha212 added 2 commits May 5, 2026 18:06
…5391

Adds runnable gutter icons for each specs2 test ("x" in {…}, >>, !)
and scope expression ("x" should {…}, can). Mirrors the
ScalaTestTestLocationsFinder pattern: a new Specs2TestLocationsFinder
walks the class body and collects the operation refs of every
ScInfixExpr that TestNodeProvider recognises as a specs2 test or
scope.

Wires the result into ScalaTestRunLineMarkerProvider#infoForTestMethodRef
behind a Specs2TestFramework branch.

The companion test (Specs2RunLineMarkerProviderTest, plus its
WithSpecs2_4 fixture trait) will land in a follow-up commit on the
same PR once the locally-built specs2-core test classpath is verified.
…ts and scopes #SCL-25391

Following SCL-24481 (PR JetBrains#709) which added ScalaTest+ZIO single-test
support to BazelScalaTestRunLineMarkerLogic, this restores specs2
parity. Without it, clicking the gutter on a specs2 spec produces
--test_filter=<classFQN>, which fails to match specs2-junit's
scope-prefixed Description display names; bazel's JUnit4Runner
reports "No tests found matching RegEx".

Specs2BazelTestFilter is a Scala 3 port of the deleted Google IJwB
plugin (bazelbuild/intellij commit f62b2670648d, file
scala/src/com/google/idea/blaze/scala/run/Specs2Utils.java).
Filter format identical to Google's:
  - test ref:  <classFQN>#\Q<scope> should::<test>\E$
  - scope ref: <classFQN>#\Q<scope> should\E::

A specs2 class identifier itself (no enclosing test/scope expression)
falls back to <classFQN>.* which empirically works for
scala_specs2_junit_test targets.

The helper lives in testing-support (Scala 2.13) rather than
intellij-bazel (Scala 3) because it is a pure PSI-to-string utility
with no bazel-runtime dependency, and testing-support already has
the ScalaFixtureTestCase infrastructure used to unit-test it
(Specs2BazelTestFilterTest).
@jastice jastice requested a review from unkarjedy May 5, 2026 15:16
@vasilmkd vasilmkd self-requested a review May 5, 2026 15:35
…ixed

Mirrors ScalaTestRunLineMarkerProviderTest_Scalatest_3_2_Scala2 against
a Specs2 mutable.Specification with both `should` and `can` scopes and
all three test operators (`in`, `>>`, `!`). Asserts seven gutters:
class identifier, both scope refs, and all four test refs.

Expected offsets were computed by manual character counting of the
fixture source. If JetBrains CI surfaces a mismatch, the assertion's
`expected:<…> but was:<…>` output gives us the actuals to swap in.
@vasilmkd
Copy link
Copy Markdown
Collaborator

vasilmkd commented May 7, 2026

Thanks for the contribution. I will run it in our internal CI to see if the tests pass and I will do a review afterwards.

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.

2 participants