Skip to content

Commit

Permalink
Add JavaConfigurationTest.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 410102734
  • Loading branch information
MarkDacek authored and copybara-github committed Nov 16, 2021
1 parent 10dfca5 commit 9e9d7bf
Showing 1 changed file with 70 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Copyright 2021 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.view.java;

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

import com.google.common.collect.Iterables;
import com.google.devtools.build.lib.analysis.config.BuildConfigurationCollection;
import com.google.devtools.build.lib.analysis.config.BuildConfigurationValue;
import com.google.devtools.build.lib.analysis.util.ConfigurationTestCase;
import com.google.devtools.build.lib.cmdline.Label;
import com.google.devtools.build.lib.rules.cpp.CppConfiguration;
import com.google.devtools.build.lib.rules.java.JavaConfiguration;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

/**
* Tests for the Java-specific parts of {@link BuildConfigurationValue} creation, and the
* Java-related configuration transitions.
*/
@RunWith(JUnit4.class)
public class JavaConfigurationTest extends ConfigurationTestCase {

@Test
public void testJavaLauncherConfiguration() throws Exception {
// Default value of --java_launcher: null.
BuildConfigurationValue config = create();
JavaConfiguration cfg = config.getFragment(JavaConfiguration.class);
assertThat(cfg.getJavaLauncherLabel()).isNull();

// Explicitly enabled launcher as default
scratch.file("foo/BUILD", "filegroup(name='bar')", "filegroup(name='baz')");
config = create("--java_launcher=//foo:bar");
cfg = config.getFragment(JavaConfiguration.class);
assertThat(Label.parseAbsoluteUnchecked("//foo:bar")).isEqualTo(cfg.getJavaLauncherLabel());
}

@Test
public void testHostCrosstoolTop() throws Exception {
BuildConfigurationCollection configs = createCollection();
BuildConfigurationValue config = Iterables.getOnlyElement(configs.getTargetConfigurations());
assertThat(config.getFragment(CppConfiguration.class).getRuleProvidingCcToolchainProvider())
.isEqualTo(Label.parseAbsoluteUnchecked("//tools/cpp:toolchain"));

BuildConfigurationValue hostConfig = configs.getHostConfiguration();
assertThat(hostConfig.getFragment(CppConfiguration.class).getRuleProvidingCcToolchainProvider())
.isEqualTo(Label.parseAbsoluteUnchecked("//tools/cpp:toolchain"));
}


@Test
public void testConfigurationsHaveUniqueOutputDirectories() throws Exception {
assertConfigurationsHaveUniqueOutputDirectories(createCollection("--cpu=k8"));

assertConfigurationsHaveUniqueOutputDirectories(
createCollection("--cpu=k8", "--compilation_mode=opt"));
}
}

0 comments on commit 9e9d7bf

Please sign in to comment.