Skip to content

Commit

Permalink
(non-cherrypick) Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hvadehra committed Sep 11, 2024
1 parent a018135 commit 37180a2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,71 +103,6 @@ public void javaTestSetsSecurityManagerPropertyOnVersion17() throws Exception {
}
}

@Test
public void experimentalShardedJavaLibrary_succeeds() throws Exception {
setBuildLanguageOptions("--experimental_java_library_export");
scratch.file(
"foo/rule.bzl",
//
"java_library = experimental_java_library_export_do_not_use.sharded_java_library(",
" default_shard_size = 10",
")");
scratch.file(
"foo/BUILD",
"load(':rule.bzl', 'java_library')",
"",
"java_library(",
" name = 'lib1',",
" srcs = ['1.java', '2.java', '3.java'],",
" experimental_javac_shard_size = 1,",
")",
"java_library(",
" name = 'lib2',",
" srcs = ['1.java', '2.java', '3.java'],",
" experimental_javac_shard_size = 2,",
")");

ImmutableList<Action> compileActionsWithShardSize1 =
getActions("//foo:lib1", JavaCompileAction.class);
ImmutableList<Action> compileActionsWithShardSize2 =
getActions("//foo:lib2", JavaCompileAction.class);

assertThat(compileActionsWithShardSize1).hasSize(3);
assertThat(compileActionsWithShardSize2).hasSize(2);
}

// regression test for b/297356812#comment31
@Test
public void experimentalShardedJavaLibrary_allOutputsHaveUniqueNames() throws Exception {
setBuildLanguageOptions("--experimental_java_library_export");
scratch.file(
"foo/rule.bzl",
//
"java_library = experimental_java_library_export_do_not_use.sharded_java_library(",
" default_shard_size = 1",
")");
scratch.file(
"foo/BUILD",
"load(':rule.bzl', 'java_library')",
"",
"java_library(",
" name = 'lib',",
" srcs = ['1.java', '2.java', '3.java'],",
")");

ImmutableList<Artifact> outputs =
getActions("//foo:lib", JavaCompileAction.class).stream()
.map(ActionAnalysisMetadata::getPrimaryOutput)
.collect(toImmutableList());
ImmutableSet<String> uniqueFilenamesWithoutExtension =
outputs.stream()
.map(file -> MoreFiles.getNameWithoutExtension(file.getPath().getPathFile().toPath()))
.collect(toImmutableSet());

assertThat(outputs).hasSize(3);
assertThat(uniqueFilenamesWithoutExtension).hasSize(3);
}

// regression test for https://github.com/bazelbuild/bazel/issues/20378
@Test
public void javaTestInvalidTestClassAtRootPackage() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -741,23 +741,23 @@ public void testWhenDynamicRuntimeLibAttributeMandatoryWhenSupportsEmbeddedRunti
@Test
public void testDwpFilesIsBlocked() throws Exception {
scratch.file(
"test/dwp_files_rule.bzl",
"foobar/dwp_files_rule.bzl",
"def _impl(ctx):",
" cc_toolchain = ctx.attr._cc_toolchain[cc_common.CcToolchainInfo]",
" cc_toolchain.dwp_files()",
" return []",
"dwp_files_rule = rule(",
" implementation = _impl,",
" attrs = {'_cc_toolchain':" + " attr.label(default=Label('//test:alias'))},",
" attrs = {'_cc_toolchain':" + " attr.label(default=Label('//foobar:alias'))},",
")");
scratch.file(
"test/BUILD",
"foobar/BUILD",
"load(':dwp_files_rule.bzl', 'dwp_files_rule')",
"cc_toolchain_alias(name='alias')",
"dwp_files_rule(name = 'target')");
reporter.removeHandler(failFastHandler);

getConfiguredTarget("//test:target");
getConfiguredTarget("//foobar:target");

assertContainsEvent("cannot use private API");
}
Expand Down

0 comments on commit 37180a2

Please sign in to comment.