Skip to content

Commit

Permalink
WIP: Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
fmeum committed Aug 18, 2022
1 parent b8cc0b0 commit 7304185
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/test/java/com/google/devtools/build/lib/analysis/BUILD
Expand Up @@ -400,6 +400,21 @@ java_test(
],
)

java_test(
name = "RunfilesLibraryUsersTest",
srcs = ["RunfilesLibraryUsersTest.java"],
deps = [
"//src/main/java/com/google/devtools/build/lib/actions",
"//src/main/java/com/google/devtools/build/lib/analysis:analysis_cluster",
"//src/main/java/com/google/devtools/build/lib/analysis:configured_target",
"//src/main/java/com/google/devtools/build/lib/cmdline",
"//src/main/java/com/google/devtools/build/lib/events",
"//src/test/java/com/google/devtools/build/lib/buildtool/util",
"//third_party:junit4",
"//third_party:truth",
],
)

test_suite(
name = "AllAnalysisTests",
tests = [
Expand Down
@@ -0,0 +1,75 @@
// Copyright 2020 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.devtools.build.lib.analysis;

import static com.google.common.truth.Truth.assertThat;

import com.google.devtools.build.lib.analysis.RunfilesProvider.RepositoryNameAndMapping;
import com.google.devtools.build.lib.buildtool.util.BuildIntegrationTestCase;
import com.google.devtools.build.lib.cmdline.RepositoryMapping;
import com.google.devtools.build.lib.cmdline.RepositoryName;
import java.util.Map;
import java.util.stream.Collectors;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

@RunWith(JUnit4.class)
public final class RunfilesLibraryUsersTest extends BuildIntegrationTestCase {

@Before
public void setupWorkspace() throws Exception {
write("WORKSPACE", "workspace(name = 'my_workspace')");
write("common/rules.bzl",
"def fake_runfiles_library_impl(ctx):",
" return [",
" CcInfo(),",
" JavaInfo(),",
" PyInfo(),",
" RunfilesLibraryInfo(),",
" ]",
"fake_runfiles_library = rule(implementation = fake_runfiles_library_impl)"
);
write("common/BUILD.bazel",
"load(':rules.bzl', 'fake_runfiles_library')",
"fake_runfiles_library(name = 'runfiles_lib')"
);
write("pkg/java/BUILD.bazel",
"java_library(",
" name = 'lib',",
" srcs = ['Lib.java'],",
" runtime_deps = ['//common:runfiles_lib'],",
")"
);
}

@Test
public void testNoRunfilesLibraryUsers() throws Exception {
assertThat(getRunfilesLibraryUsers("//pkg/java:lib").keySet()).containsExactly(
RepositoryName.MAIN);
}

private Map<RepositoryName, RepositoryMapping> getRunfilesLibraryUsers(String label)
throws Exception {
ConfiguredTarget target = getConfiguredTarget(label);
RunfilesProvider runfilesProvider = target.getProvider(RunfilesProvider.class);

assertThat(runfilesProvider).isNotNull();
assertThat(runfilesProvider.getRunfilesLibraryUsers()).isNotNull();
return runfilesProvider.getRunfilesLibraryUsers().toList().stream().collect(
Collectors.toMap(RepositoryNameAndMapping::getRepositoryName,
RepositoryNameAndMapping::getRepositoryMapping));
}
}

0 comments on commit 7304185

Please sign in to comment.