forked from bazelbuild/bazel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
-- MOS_MIGRATED_REVID=112027454
- Loading branch information
Showing
57 changed files
with
4,971 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/java_tools/junitrunner/java/com/google/testing/junit/junit4/BUILD
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Description: | ||
# | ||
# JUnit 4.x extensions | ||
|
||
package( | ||
default_testonly = 1, | ||
default_visibility = ["//src:__subpackages__"], | ||
) | ||
|
||
# Libraries | ||
# ========================================================= | ||
|
||
# Extensions for writing custom JUnit4 runners | ||
java_library( | ||
name = "runner", | ||
testonly = 0, # TODO(bazel-team): make it testonly | ||
srcs = glob(["runner/*.java"]), | ||
deps = [ | ||
"//third_party:guava", | ||
"//third_party:junit4", | ||
], | ||
) | ||
|
||
filegroup( | ||
name = "srcs", | ||
srcs = glob(["**"]), | ||
) |
45 changes: 45 additions & 0 deletions
45
src/java_tools/junitrunner/java/com/google/testing/junit/junit4/runner/AndFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright 2015 The Bazel Authors. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package com.google.testing.junit.junit4.runner; | ||
|
||
import static com.google.common.base.Preconditions.checkNotNull; | ||
|
||
import org.junit.runner.Description; | ||
import org.junit.runner.manipulation.Filter; | ||
|
||
/** | ||
* A filter that returns {@code true} if both of its components return {@code | ||
* true}. | ||
*/ | ||
@Deprecated | ||
class AndFilter extends Filter { | ||
private final Filter filter1; | ||
private final Filter filter2; | ||
|
||
public AndFilter(Filter filter1, Filter filter2) { | ||
this.filter1 = checkNotNull(filter1); | ||
this.filter2 = checkNotNull(filter2); | ||
} | ||
|
||
@Override | ||
public boolean shouldRun(Description description) { | ||
return filter1.shouldRun(description) && filter2.shouldRun(description); | ||
} | ||
|
||
@Override | ||
public String describe() { | ||
return String.format("%s && %s", filter1.describe(), filter2.describe()); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
...a_tools/junitrunner/java/com/google/testing/junit/junit4/runner/DynamicTestException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright 2015 The Bazel Authors. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package com.google.testing.junit.junit4.runner; | ||
|
||
import com.google.common.base.Preconditions; | ||
|
||
import org.junit.runner.Description; | ||
|
||
/** | ||
* The test runner may throw a {@code DynamicTestFailureException} to indicate a | ||
* test case failed due to a failure in a dynamically-discovered test within | ||
* a JUnit test case. | ||
*/ | ||
public class DynamicTestException extends Exception { | ||
private final Description test; | ||
|
||
/** | ||
* Constructs a {@code DynamicTestFailureException} that indicates a | ||
* dynamically-discovered test, specified as a (@link Description}, failed | ||
* due to the specified {@code cause}. | ||
*/ | ||
public DynamicTestException(Description test, Throwable cause) { | ||
super(cause); | ||
Preconditions.checkArgument(test.isTest()); | ||
this.test = test; | ||
} | ||
|
||
/** | ||
* Returns the description of the dynamically-added test case. | ||
*/ | ||
public final Description getTest() { | ||
return test; | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
src/java_tools/junitrunner/java/com/google/testing/junit/junit4/runner/Filters.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Copyright 2015 The Bazel Authors. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package com.google.testing.junit.junit4.runner; | ||
|
||
import org.junit.runner.Request; | ||
import org.junit.runner.Runner; | ||
import org.junit.runner.manipulation.Filter; | ||
import org.junit.runner.manipulation.NoTestsRemainException; | ||
|
||
/** | ||
* Common filters. | ||
*/ | ||
@Deprecated | ||
public final class Filters { | ||
|
||
private Filters() {} | ||
|
||
/** | ||
* Returns a filter that evaluates to {@code true} if both of its | ||
* components evaluates to {@code true}. The filters are evaluated in | ||
* order, and evaluation will be "short-circuited" if the first filter | ||
* returns {@code false}. | ||
*/ | ||
public static Filter and(Filter delegate1, Filter delegate2) { | ||
return delegate1 == Filter.ALL ? delegate2 | ||
: (delegate2 == Filter.ALL ? delegate1 | ||
: new AndFilter(delegate1, delegate2)); | ||
} | ||
|
||
/** | ||
* Returns a Request that only contains those tests that should run when | ||
* a filter is applied, filtering out all empty suites.<p> | ||
* | ||
* Note that if the request passed into this method caches its runner, | ||
* that runner will be modified to use the given filter. To be safe, | ||
* do not use the passed-in request after calling this method. | ||
* | ||
* @param request Request to filter | ||
* @param filter Filter to apply | ||
* @return request | ||
* @throws NoTestsRemainException if the applying the filter removes all tests | ||
*/ | ||
public static Request apply(Request request, Filter filter) throws NoTestsRemainException { | ||
filter = new SuiteTrimmingFilter(filter); | ||
Runner runner = request.getRunner(); | ||
filter.apply(runner); | ||
|
||
return Request.runner(runner); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
src/java_tools/junitrunner/java/com/google/testing/junit/junit4/runner/MemoizingRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright 2015 The Bazel Authors. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package com.google.testing.junit.junit4.runner; | ||
|
||
import org.junit.runner.Request; | ||
import org.junit.runner.Runner; | ||
|
||
/** | ||
* A {@link Request} that memoizies another {@code Request}. | ||
* This class is meant to be overridden to modify some behaviors. | ||
*/ | ||
@Deprecated | ||
public class MemoizingRequest extends Request { | ||
private final Request requestDelegate; | ||
private Runner runnerDelegate; | ||
|
||
public MemoizingRequest(Request delegate) { | ||
this.requestDelegate = delegate; | ||
} | ||
|
||
@Override | ||
public final synchronized Runner getRunner() { | ||
if (runnerDelegate == null) { | ||
runnerDelegate = createRunner(requestDelegate); | ||
} | ||
return runnerDelegate; | ||
} | ||
|
||
/** | ||
* Creates the runner. This method is called at most once. | ||
* Subclasses can override this method for different behavior. | ||
* The default implementation returns the runner created by the delegate. | ||
* | ||
* @param delegate request to delegate to | ||
* @return runner | ||
*/ | ||
protected Runner createRunner(Request delegate) { | ||
return delegate.getRunner(); | ||
} | ||
} |
101 changes: 101 additions & 0 deletions
101
...ava_tools/junitrunner/java/com/google/testing/junit/junit4/runner/RunNotifierWrapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
// Copyright 2015 The Bazel Authors. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package com.google.testing.junit.junit4.runner; | ||
|
||
import org.junit.runner.Description; | ||
import org.junit.runner.Result; | ||
import org.junit.runner.notification.Failure; | ||
import org.junit.runner.notification.RunListener; | ||
import org.junit.runner.notification.RunNotifier; | ||
import org.junit.runner.notification.StoppedByUserException; | ||
|
||
/** | ||
* A {@link RunNotifier} that delegates all its operations to another {@code RunNotifier}. | ||
* This class is meant to be overridden to modify some behaviors. | ||
*/ | ||
public abstract class RunNotifierWrapper extends RunNotifier { | ||
private final RunNotifier delegate; | ||
|
||
/** | ||
* Creates a new instance. | ||
* | ||
* @param delegate notifier to delegate to | ||
*/ | ||
public RunNotifierWrapper(RunNotifier delegate) { | ||
this.delegate = delegate; | ||
} | ||
|
||
/** | ||
* @return the delegate | ||
*/ | ||
protected final RunNotifier getDelegate() { | ||
return delegate; | ||
} | ||
|
||
@Override | ||
public void addFirstListener(RunListener listener) { | ||
delegate.addFirstListener(listener); | ||
} | ||
|
||
@Override | ||
public void addListener(RunListener listener) { | ||
delegate.addListener(listener); | ||
} | ||
|
||
@Override | ||
public void removeListener(RunListener listener) { | ||
delegate.removeListener(listener); | ||
} | ||
|
||
@Override | ||
public void fireTestRunStarted(Description description) { | ||
delegate.fireTestRunStarted(description); | ||
} | ||
|
||
@Override | ||
public void fireTestStarted(Description description) throws StoppedByUserException { | ||
delegate.fireTestStarted(description); | ||
} | ||
|
||
@Override | ||
public void fireTestIgnored(Description description) { | ||
delegate.fireTestIgnored(description); | ||
} | ||
|
||
@Override | ||
public void fireTestAssumptionFailed(Failure failure) { | ||
delegate.fireTestAssumptionFailed(failure); | ||
} | ||
|
||
@Override | ||
public void fireTestFailure(Failure failure) { | ||
delegate.fireTestFailure(failure); | ||
} | ||
|
||
@Override | ||
public void fireTestFinished(Description description) { | ||
delegate.fireTestFinished(description); | ||
} | ||
|
||
@Override | ||
public void fireTestRunFinished(Result result) { | ||
delegate.fireTestRunFinished(result); | ||
} | ||
|
||
@Override | ||
public void pleaseStop() { | ||
delegate.pleaseStop(); | ||
} | ||
} |
Oops, something went wrong.