aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test
diff options
context:
space:
mode:
authorGravatar dslomov <dslomov@google.com>2017-12-13 05:55:07 -0800
committerGravatar Copybara-Service <copybara-piper@google.com>2017-12-13 05:56:34 -0800
commita3b8e3972379f7e32f7c72c298ee20d8127f9aff (patch)
treedc1a64ec5513b329e81d3bd631cf92c468c47228 /src/test
parent75eca48099370df836388a6afe0279d597673f33 (diff)
Implement --(no)expand_test_suites flag.
--noexpand_test_suites flag will suppress expansion of test_suite targets into constituent tests, so that command-line aspects can analyze test_suite targets. RELNOTES: Added --(no)expand_test_suites flag. PiperOrigin-RevId: 178892829
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/com/google/devtools/build/lib/analysis/util/BuildViewTestCase.java12
-rw-r--r--src/test/java/com/google/devtools/build/lib/skyframe/TargetPatternPhaseKeyTest.java33
-rwxr-xr-xsrc/test/shell/integration/test_test.sh28
3 files changed, 60 insertions, 13 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/util/BuildViewTestCase.java b/src/test/java/com/google/devtools/build/lib/analysis/util/BuildViewTestCase.java
index 764b382f1e..7939508597 100644
--- a/src/test/java/com/google/devtools/build/lib/analysis/util/BuildViewTestCase.java
+++ b/src/test/java/com/google/devtools/build/lib/analysis/util/BuildViewTestCase.java
@@ -149,6 +149,7 @@ import com.google.devtools.build.skyframe.SkyFunction;
import com.google.devtools.common.options.InvocationPolicyEnforcer;
import com.google.devtools.common.options.Options;
import com.google.devtools.common.options.OptionsParser;
+import com.google.devtools.common.options.OptionsParsingException;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
@@ -198,6 +199,8 @@ public abstract class BuildViewTestCase extends FoundationTestCase {
private MutableActionGraph mutableActionGraph;
+ private LoadingOptions customLoadingOptions = null;
+
@Before
public final void initializeSkyframeExecutor() throws Exception {
analysisMock = getAnalysisMock();
@@ -1517,6 +1520,10 @@ public abstract class BuildViewTestCase extends FoundationTestCase {
return attributes((RuleConfiguredTarget) rule);
}
+ protected void useLoadingOptions(String... options) throws OptionsParsingException {
+ customLoadingOptions = Options.parse(LoadingOptions.class, options).getOptions();
+ }
+
protected AnalysisResult update(List<String> targets,
boolean keepGoing,
int loadingPhaseThreads,
@@ -1535,7 +1542,10 @@ public abstract class BuildViewTestCase extends FoundationTestCase {
EventBus eventBus)
throws Exception {
- LoadingOptions loadingOptions = Options.getDefaults(LoadingOptions.class);
+ LoadingOptions loadingOptions =
+ customLoadingOptions == null
+ ? Options.getDefaults(LoadingOptions.class)
+ : customLoadingOptions;
BuildView.Options viewOptions = Options.getDefaults(BuildView.Options.class);
viewOptions.keepGoing = keepGoing;
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/TargetPatternPhaseKeyTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/TargetPatternPhaseKeyTest.java
index 70ba224165..e9243751e7 100644
--- a/src/test/java/com/google/devtools/build/lib/skyframe/TargetPatternPhaseKeyTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skyframe/TargetPatternPhaseKeyTest.java
@@ -49,47 +49,56 @@ public class TargetPatternPhaseKeyTest {
.addEqualityGroup(of(ImmutableList.of("c"), ""))
.addEqualityGroup(of(ImmutableList.<String>of(), ""))
.addEqualityGroup(of(
- ImmutableList.<String>of(), "", ImmutableList.<String>of(), false, null,
+ ImmutableList.<String>of(), "", ImmutableList.<String>of(), false, true, null,
COMPILE_ONE_DEPENDENCY))
.addEqualityGroup(of(
- ImmutableList.<String>of(), "", ImmutableList.<String>of(), true, null,
+ ImmutableList.<String>of(), "", ImmutableList.<String>of(), false, false, null,
COMPILE_ONE_DEPENDENCY))
- .addEqualityGroup(of(
+ .addEqualityGroup(of(
+ ImmutableList.<String>of(), "", ImmutableList.<String>of(), true, true, null,
+ COMPILE_ONE_DEPENDENCY))
+ .addEqualityGroup(of(
+ ImmutableList.<String>of(), "", ImmutableList.<String>of(), true, false, null,
+ COMPILE_ONE_DEPENDENCY))
+ .addEqualityGroup(of(
ImmutableList.<String>of(), "", ImmutableList.<String>of(), false,
- emptyTestFilter(),
+ true, emptyTestFilter(),
BUILD_TESTS_ONLY))
.addEqualityGroup(of(
ImmutableList.<String>of(), "", ImmutableList.<String>of(), true,
- emptyTestFilter(),
+ true, emptyTestFilter(),
BUILD_TESTS_ONLY))
.addEqualityGroup(of(
ImmutableList.<String>of(), "", ImmutableList.<String>of(), false,
- emptyTestFilter(),
+ true, emptyTestFilter(),
DETERMINE_TESTS))
.addEqualityGroup(of(
ImmutableList.<String>of(), "", ImmutableList.<String>of(), true,
- emptyTestFilter(),
+ true, emptyTestFilter(),
DETERMINE_TESTS))
.addEqualityGroup(of(
- ImmutableList.<String>of(), "", ImmutableList.<String>of("a"), false, null))
+ ImmutableList.<String>of(), "", ImmutableList.<String>of("a"), false, true,
+ null))
.addEqualityGroup(of(
- ImmutableList.<String>of(), "", ImmutableList.<String>of("a"), true, null))
+ ImmutableList.<String>of(), "", ImmutableList.<String>of("a"), true, true,
+ null))
.testEquals();
}
private TargetPatternPhaseKey of(ImmutableList<String> targetPatterns, String offset,
ImmutableList<String> buildTagFilter,
- boolean includeManualTests, @Nullable TestFilter testFilter, Flag... flags) {
+ boolean includeManualTests, boolean expandTestSuites, @Nullable TestFilter testFilter,
+ Flag... flags) {
ImmutableSet<Flag> set = ImmutableSet.copyOf(flags);
boolean compileOneDependency = set.contains(Flag.COMPILE_ONE_DEPENDENCY);
boolean buildTestsOnly = set.contains(Flag.BUILD_TESTS_ONLY);
boolean determineTests = set.contains(Flag.DETERMINE_TESTS);
return new TargetPatternPhaseKey(targetPatterns, offset, compileOneDependency, buildTestsOnly,
- determineTests, buildTagFilter, includeManualTests, testFilter);
+ determineTests, buildTagFilter, includeManualTests, expandTestSuites, testFilter);
}
private TargetPatternPhaseKey of(ImmutableList<String> targetPatterns, String offset) {
- return of(targetPatterns, offset, ImmutableList.<String>of(), false, null);
+ return of(targetPatterns, offset, ImmutableList.<String>of(), false, true, null);
}
private TestFilter emptyTestFilter() {
diff --git a/src/test/shell/integration/test_test.sh b/src/test/shell/integration/test_test.sh
index d288fefa17..c2e599749b 100755
--- a/src/test/shell/integration/test_test.sh
+++ b/src/test/shell/integration/test_test.sh
@@ -128,4 +128,32 @@ EOF
bazel test //dir:my_test &> $TEST_log || fail "expected test to pass"
}
+function test_test_suite_non_expansion() {
+ mkdir -p dir
+ cat > dir/BUILD <<'EOF'
+sh_test(name = 'test_a',
+ srcs = [':a.sh'],
+)
+
+sh_test(name = 'test_b',
+ srcs = [':b.sh'],
+)
+
+test_suite(name = 'suite',
+)
+EOF
+ cat > dir/a.sh <<'EOF'
+#!/bin/sh
+exit 0
+EOF
+
+ cat > dir/b.sh <<'EOF'
+#!/bin/sh
+exit 0
+EOF
+ chmod +x dir/a.sh dir/b.sh
+ bazel test --noexpand_test_suites //dir:suite &> $TEST_log || fail "expected test to pass"
+ expect_log '//dir:test_a'
+ expect_log '//dir:test_b'
+}
run_suite "test tests"