google / google/compile-testing

Assert non-existence of a particular error

Open
#50 1 comment 0 reactions 0 assignees View on GitHub
P3 type=enhancement
Dominant language
Java
Stars
722
Forks
129
Avg merge
11m
Merged PRs (30d)
4

Description

In the annotation processor that I am working on, I have run across a case where it is meaningless to report error2 if error1 is detected. Thus as a feature I would like my processor to not output error2 if it has output error1, and I would like to test that my processor is doing the right thing.

Unfortunately the current API doesn't provide for this case easily, as it only allows you to assert the _existence_ of a particular error, or the non-existence of _all_ errors.

In my tests I got around this problem by testing for the existence of error2 using `withErrorContaining()`, wrapping it in a try/catch, and silently continuing if no AssertionError is caught or else throwing my own AssertionError if it wasn't. However, this is a little ugly and the diagnostics are not as informative as they might be with a "native" implementation in the compile-testing API itself.

I would like to be able to do something like:

``` java
failsToCompile().withErrorContaining(error1).in(file).onLine(line1).and()
.withNoErrorContaining(error2).in(file).onLine(line2);
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.