Skip to content

Add tests for Bazel sourceroot inference#967

Merged
jupblb merged 2 commits into
mainfrom
michal/fix-1
Jul 2, 2026
Merged

Add tests for Bazel sourceroot inference#967
jupblb merged 2 commits into
mainfrom
michal/fix-1

Conversation

@jupblb

@jupblb jupblb commented Jul 2, 2026

Copy link
Copy Markdown
Member

Fixes #444.

Adds end-to-end tests for the sourceroot inference of -build-tool:bazel compilations (ScipTaskListener.inferBazelSourceroot), as requested in a review comment on #439.

BazelSourcerootTest drives the real compiler with file objects that mimic the ones constructed by Bazel's Java compiler: toUri() points into a sandbox directory while toString() renders a human-readable workspace path. The tests assert the observable outputs: shard locations under targetroot/META-INF/scip/ and Document.relative_path. Covered cases:

  • a sandboxed two-file compilation where the sourceroot is inferred from the first compilation unit,
  • sandbox and workspace layouts sharing only the file name,
  • unrecognized file objects (toString() matching no known Bazel pattern), where inference falls back to the URI path.

Notes:

  • javac wraps client-supplied file objects in ClientCodeWrapper.WrappedJavaFileObject, whose toString() would defeat the plugin's pattern matching. Real Bazel file objects are javac-internal classes and therefore trusted/unwrapped; the test file object opts out of wrapping via @ClientCodeWrapper.Trusted. Since that annotation is an internal API, compileTestJava in scip-javac now clears --release and adds the same --add-exports flags the test JVM already uses at runtime.
  • Writing the tests exposed a crash in the previously untested fallback path: when the human-readable path equals the URI path (e.g. unrecognized file objects), absolutePath.subpath(0, 0) threw IllegalArgumentException. The inference now falls back to the filesystem root in that case, and the third test covers it.

@jupblb jupblb merged commit e9898f5 into main Jul 2, 2026
23 checks passed
@jupblb jupblb deleted the michal/fix-1 branch July 2, 2026 14:28
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.

Add unit tests for inferBazelSourceroot

1 participant