Skip to content
This repository has been archived by the owner on Nov 10, 2023. It is now read-only.

Commit

Permalink
Add "contacts" as an option to java_test().
Browse files Browse the repository at this point in the history
Summary:
Add the `contacts =` kwarg to `java_test()` and pass them through to
the test recorder, recording them in the `TR_APIRecorder` API.
  • Loading branch information
Edward Speyer authored and bolinfest committed Sep 19, 2013
1 parent 9ea5704 commit e793ed7
Show file tree
Hide file tree
Showing 12 changed files with 81 additions and 15 deletions.
2 changes: 2 additions & 0 deletions DEFS
Expand Up @@ -35,6 +35,7 @@ def java_test(
target='7',
vm_args=[],
source_under_test=[],
contacts=[],
deps=[],
visibility=[],
):
Expand All @@ -49,6 +50,7 @@ def java_test(
# http://arihantwin.blogspot.com/2012/08/getting-error-illegal-local-variable.html
vm_args=['-XX:-UseSplitVerifier'] + vm_args,
source_under_test=source_under_test,
contacts=contacts,
deps=deps,
visibility=visibility,
)
3 changes: 3 additions & 0 deletions src/com/facebook/buck/android/RobolectricTestRule.java
Expand Up @@ -68,6 +68,7 @@ protected RobolectricTestRule(BuildRuleParams buildRuleParams,
Set<String> srcs,
Set<SourcePath> resources,
Set<String> labels,
Set<String> contacts,
Optional<String> proguardConfig,
JavacOptions javacOptions,
List<String> vmArgs,
Expand All @@ -76,6 +77,7 @@ protected RobolectricTestRule(BuildRuleParams buildRuleParams,
srcs,
resources,
labels,
contacts,
proguardConfig,
javacOptions,
vmArgs,
Expand Down Expand Up @@ -140,6 +142,7 @@ public RobolectricTestRule build(BuildRuleResolver ruleResolver) {
srcs,
resources,
labels,
contacts,
proguardConfig,
javacOptions.build(),
allVmArgs.build(),
Expand Down
6 changes: 6 additions & 0 deletions src/com/facebook/buck/java/JavaTestBuildRuleFactory.java
Expand Up @@ -26,6 +26,8 @@
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;

import java.util.List;

public class JavaTestBuildRuleFactory extends AbstractTestRuleFactory<JavaTestRule.Builder> {

@Override
Expand Down Expand Up @@ -59,5 +61,9 @@ protected void amendBuilder(JavaTestRule.Builder builder,
ImmutableSet<BuildTarget> sourceUnderTest = ImmutableSet.copyOf(Iterables.transform(
params.getOptionalListAttribute("source_under_test"), contextualBuildParser));
builder.setSourceUnderTest(sourceUnderTest);

// contacts
List<String> contacts = params.getOptionalListAttribute("contacts");
builder.setContacts(ImmutableSet.copyOf(contacts));
}
}
19 changes: 18 additions & 1 deletion src/com/facebook/buck/java/JavaTestRule.java
Expand Up @@ -74,10 +74,13 @@ public class JavaTestRule extends DefaultJavaLibraryRule implements TestRule {

private final ImmutableSet<String> labels;

private final ImmutableSet<String> contacts;

protected JavaTestRule(BuildRuleParams buildRuleParams,
Set<String> srcs,
Set<SourcePath> resources,
Set<String> labels,
Set<String> contacts,
Optional<String> proguardConfig,
JavacOptions javacOptions,
List<String> vmArgs,
Expand All @@ -91,6 +94,7 @@ protected JavaTestRule(BuildRuleParams buildRuleParams,
this.vmArgs = ImmutableList.copyOf(vmArgs);
this.sourceUnderTest = Preconditions.checkNotNull(sourceUnderTest);
this.labels = ImmutableSet.copyOf(labels);
this.contacts = ImmutableSet.copyOf(contacts);
}

@Override
Expand All @@ -103,6 +107,11 @@ public ImmutableSet<String> getLabels() {
return labels;
}

@Override
public ImmutableSet<String> getContacts() {
return contacts;
}

@Override
public RuleKey.Builder appendToRuleKey(RuleKey.Builder builder) throws IOException {
ImmutableSortedSet<? extends BuildRule> srcUnderTest = ImmutableSortedSet.copyOf(
Expand Down Expand Up @@ -240,6 +249,7 @@ private String getPathToTestOutput() {

@Override
public Callable<TestResults> interpretTestResults(final ExecutionContext context) {
final ImmutableSet<String> contacts = getContacts();
return new Callable<TestResults>() {

@Override
Expand All @@ -260,7 +270,7 @@ public TestResults call() throws Exception {
summaries.add(summary);
}

return new TestResults(summaries);
return new TestResults(contacts, summaries);
}

};
Expand Down Expand Up @@ -378,6 +388,7 @@ public static class Builder extends DefaultJavaLibraryRule.Builder
@Nullable protected List<String> vmArgs = ImmutableList.of();
protected ImmutableSet<BuildTarget> sourcesUnderTest = ImmutableSet.of();
protected ImmutableSet<String> labels = ImmutableSet.of();
protected ImmutableSet<String> contacts = ImmutableSet.of();

protected Builder(AbstractBuildRuleBuilderParams params) {
super(params);
Expand All @@ -394,6 +405,7 @@ public JavaTestRule build(BuildRuleResolver ruleResolver) {
srcs,
resources,
labels,
contacts,
proguardConfig,
javacOptions.build(),
vmArgs,
Expand Down Expand Up @@ -434,6 +446,11 @@ public Builder setLabels(ImmutableSet<String> labels) {
return this;
}

public Builder setContacts(ImmutableSet<String> contacts) {
this.contacts = contacts;
return this;
}

/**
* Generates the set of build rules that contain the source that will be under test.
*/
Expand Down
4 changes: 4 additions & 0 deletions src/com/facebook/buck/parser/buck.py
Expand Up @@ -221,6 +221,7 @@ def java_test(
target='6',
vm_args=[],
source_under_test=[],
contacts=[],
deps=[],
visibility=[],
build_env=None):
Expand All @@ -234,6 +235,7 @@ def java_test(
'target' : target,
'vm_args' : vm_args,
'source_under_test' : source_under_test,
'contacts' : contacts,
'deps' : deps,
'visibility' : visibility,
}, build_env)
Expand All @@ -247,6 +249,7 @@ def robolectric_test(
resources=[],
vm_args=[],
source_under_test=[],
contacts=[],
deps=[],
visibility=[],
build_env=None):
Expand All @@ -258,6 +261,7 @@ def robolectric_test(
'resources' : resources,
'vm_args' : vm_args,
'source_under_test' : source_under_test,
'contacts' : contacts,
'deps' : deps,
'visibility' : visibility,
}, build_env)
Expand Down
5 changes: 5 additions & 0 deletions src/com/facebook/buck/rules/TestRule.java
Expand Up @@ -57,4 +57,9 @@ public interface TestRule extends BuildRule {
* @return The set of labels for this build rule.
*/
public ImmutableSet<String> getLabels();

/**
* @return The set of email addresses to act as contact points for this test.
*/
public ImmutableSet<String> getContacts();
}
7 changes: 6 additions & 1 deletion src/com/facebook/buck/shell/ShTestRule.java
Expand Up @@ -86,6 +86,10 @@ public ImmutableSet<String> getLabels() {
return labels;
}

public ImmutableSet<String> getContacts() {
return ImmutableSet.<String>of();
}

@Override
public List<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
// Nothing to build: test is run directly.
Expand Down Expand Up @@ -125,6 +129,7 @@ String getPathToTestOutputResult() {

@Override
public Callable<TestResults> interpretTestResults(ExecutionContext context) {
final ImmutableSet<String> contacts = getContacts();
return new Callable<TestResults>() {

@Override
Expand All @@ -135,7 +140,7 @@ public TestResults call() throws Exception {
TestResultSummary.class);
TestCaseSummary testCaseSummary = new TestCaseSummary(
getFullyQualifiedName(), ImmutableList.of(testResultSummary));
return new TestResults(ImmutableList.of(testCaseSummary));
return new TestResults(contacts, ImmutableList.of(testCaseSummary));
}

};
Expand Down
11 changes: 9 additions & 2 deletions src/com/facebook/buck/test/TestResults.java
Expand Up @@ -18,6 +18,7 @@

import com.google.common.annotations.Beta;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;

import java.util.List;

Expand All @@ -30,14 +31,16 @@
public class TestResults {

private static final TestResults EMPTY_TEST_RESULTS = new TestResults(
ImmutableList.<TestCaseSummary>of());
null, ImmutableList.<TestCaseSummary>of());

private final ImmutableSet<String> contacts;
private final ImmutableList<TestCaseSummary> testCases;
private final List<TestCaseSummary> failures;
private final int failureCount;

@Beta
public TestResults(List<TestCaseSummary> testCases) {
public TestResults(ImmutableSet<String> contacts, List<TestCaseSummary> testCases) {
this.contacts = contacts;
this.testCases = ImmutableList.copyOf(testCases);

int failureCount = 0;
Expand Down Expand Up @@ -67,5 +70,9 @@ public int getFailureCount() {
public ImmutableList<TestCaseSummary> getTestCases() {
return testCases;
}

public ImmutableSet<String> getContacts() {
return contacts;
}
}

20 changes: 15 additions & 5 deletions test/com/facebook/buck/cli/TestCommandTest.java
Expand Up @@ -58,18 +58,19 @@
import org.junit.BeforeClass;
import org.junit.Test;
import org.kohsuke.args4j.CmdLineException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.StringWriter;
import java.util.List;
import java.util.Map;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class TestCommandTest {

Expand Down Expand Up @@ -274,6 +275,11 @@ private DependencyGraph createDependencyGraphFromBuildRules(Iterable<? extends B
return new DependencyGraph(graph);
}

<<<<<<< HEAD
=======
<<<<<<< HEAD
=======
>>>>>>> d80e841... Add "contacts" as an option to java_test()
/**
* Tests the --xml flag, ensuring that test result data is correctly
* formatted.
Expand Down Expand Up @@ -316,7 +322,7 @@ public void testXmlGeneration() throws Exception {
TestCaseSummary testCase = new TestCaseSummary("TestCase", resultList);
List<TestCaseSummary> testCases = ImmutableList.of(testCase);
TestResults testResults = new TestResults(testCases);
TestResults testResults = new TestResults(ImmutableSet.<String>of(), testCases);
List<TestResults> testResultsList = ImmutableList.of(testResults);
// Call the XML generation method with our test data.
Expand Down Expand Up @@ -388,6 +394,10 @@ private void checkXmlTextContents(Element testResult,
(expectedStr.equals(firstChild.getNodeValue())));
}
<<<<<<< HEAD
=======
>>>>>>> Add "contacts" as an option to java_test()
>>>>>>> d80e841... Add "contacts" as an option to java_test()
@Test
public void testGetCandidateRulesByIncludedLabels() throws CmdLineException {
TestRule rule1 = new FakeTestRule(BuildRuleType.JAVA_TEST,
Expand Down
Expand Up @@ -26,6 +26,7 @@
import com.google.common.base.Joiner;
import com.google.common.base.Throwables;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;

import org.junit.Before;
import org.junit.Test;
Expand Down Expand Up @@ -98,7 +99,7 @@ public void shouldIndicateThatNoTestRanIfNoneRan() {
public void allTestsPassingShouldBeAcknowledged() {
TestCaseSummary summary = new TestCaseSummary(
"com.example.FooTest", ImmutableList.of(successTest));
TestResults results = new TestResults(ImmutableList.of(summary));
TestResults results = new TestResults(ImmutableSet.<String>of(), ImmutableList.of(summary));
ImmutableList.Builder<String> builder = ImmutableList.builder();

formatter.runComplete(builder, ImmutableList.of(results));
Expand All @@ -110,7 +111,7 @@ public void allTestsPassingShouldBeAcknowledged() {
public void shouldReportTheNumberOfFailingTests() {
TestCaseSummary summary = new TestCaseSummary(
"com.example.FooTest", ImmutableList.of(successTest, failingTest));
TestResults results = new TestResults(ImmutableList.of(summary));
TestResults results = new TestResults(ImmutableSet.<String>of(), ImmutableList.of(summary));
ImmutableList.Builder<String> builder = ImmutableList.builder();

formatter.runComplete(builder, ImmutableList.of(results));
Expand All @@ -122,7 +123,7 @@ public void shouldReportTheNumberOfFailingTests() {
public void shouldReportMinimalInformationForAPassingTest() {
TestCaseSummary summary = new TestCaseSummary(
"com.example.FooTest", ImmutableList.of(successTest));
TestResults results = new TestResults(ImmutableList.of(summary));
TestResults results = new TestResults(ImmutableSet.<String>of(), ImmutableList.of(summary));
ImmutableList.Builder<String> builder = ImmutableList.builder();

formatter.reportResult(builder, results);
Expand All @@ -135,7 +136,7 @@ public void shouldReportMinimalInformationForAPassingTest() {
public void shouldOutputStackTraceStdOutAndStdErrOfFailingTest() {
TestCaseSummary summary = new TestCaseSummary(
"com.example.FooTest", ImmutableList.of(failingTest));
TestResults results = new TestResults(ImmutableList.of(summary));
TestResults results = new TestResults(ImmutableSet.<String>of(), ImmutableList.of(summary));
ImmutableList.Builder<String> builder = ImmutableList.builder();

formatter.reportResult(builder, results);
Expand Down
5 changes: 5 additions & 0 deletions test/com/facebook/buck/rules/FakeTestRule.java
Expand Up @@ -100,4 +100,9 @@ public Callable<TestResults> interpretTestResults(ExecutionContext executionCont
public ImmutableSet<String> getLabels() {
return labels;
}

@Override
public ImmutableSet<String> getContacts() {
return ImmutableSet.of();
}
}
5 changes: 3 additions & 2 deletions test/com/facebook/buck/rules/IndividualTestEventTest.java
Expand Up @@ -22,6 +22,7 @@
import com.facebook.buck.test.TestCaseSummary;
import com.facebook.buck.test.TestResults;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;

import org.junit.Test;

Expand All @@ -32,7 +33,7 @@ public void startAndStopShouldPairUpProperlyBasedOnHash() {

IndividualTestEvent.Started started = IndividualTestEvent.started(tests);
IndividualTestEvent.Finished finished = IndividualTestEvent.finished(
tests, new TestResults(ImmutableList.<TestCaseSummary>of()));
tests, new TestResults(ImmutableSet.<String>of(), ImmutableList.<TestCaseSummary>of()));

assertTrue(started.eventsArePair(finished));
assertTrue(finished.eventsArePair(started));
Expand All @@ -45,7 +46,7 @@ public void shouldNotBelieveThatEventsThatAreNotPairsArePairs() {

IndividualTestEvent.Started started = IndividualTestEvent.started(tests);
IndividualTestEvent.Finished finished = IndividualTestEvent.finished(
otherTests, new TestResults(ImmutableList.<TestCaseSummary>of()));
otherTests, new TestResults(ImmutableSet.<String>of(), ImmutableList.<TestCaseSummary>of()));

assertFalse(started.eventsArePair(finished));
assertFalse(finished.eventsArePair(started));
Expand Down

0 comments on commit e793ed7

Please sign in to comment.