Search in sources :

Example 16 with IntellijAspectTestFixture

use of com.google.devtools.intellij.IntellijAspectTestFixtureOuterClass.IntellijAspectTestFixture in project intellij by bazelbuild.

the class ScalaLibraryTest method testScalaLibrary.

@Test
public void testScalaLibrary() throws Exception {
    IntellijAspectTestFixture testFixture = loadTestFixture(":simple_fixture");
    TargetIdeInfo target = findTarget(testFixture, ":simple");
    assertThat(target.getKindString()).isEqualTo("scala_library");
    assertThat(target.hasJavaIdeInfo()).isTrue();
    assertThat(target.hasCIdeInfo()).isFalse();
    assertThat(target.hasAndroidIdeInfo()).isFalse();
    assertThat(target.hasPyIdeInfo()).isFalse();
    assertThat(target.hasProtoLibraryLegacyJavaIdeInfo()).isFalse();
    assertThat(relativePathsForArtifacts(target.getJavaIdeInfo().getSourcesList())).containsExactly(testRelative("Foo.scala"));
    assertThat(target.getJavaIdeInfo().getJarsList().stream().map(IntellijAspectTest::libraryArtifactToString).collect(Collectors.toList())).containsExactly(jarString(testRelative("simple.jar"), null, null));
    // Also contains ijars for scala-library.
    // Also contains jars + srcjars for liblibrary.
    assertThat(getOutputGroupFiles(testFixture, "intellij-resolve-java")).contains(testRelative("simple.jar"));
    assertThat(getOutputGroupFiles(testFixture, "intellij-info-java")).contains(testRelative("simple.intellij-info.txt"));
    assertThat(getOutputGroupFiles(testFixture, "intellij-compile-java")).contains(testRelative("simple.jar"));
    assertThat(getOutputGroupFiles(testFixture, "intellij-info-generic")).isEmpty();
    assertThat(target.getJavaIdeInfo().getMainClass()).isEmpty();
}
Also used : TargetIdeInfo(com.google.devtools.intellij.ideinfo.IntellijIdeInfo.TargetIdeInfo) IntellijAspectTestFixture(com.google.devtools.intellij.IntellijAspectTestFixtureOuterClass.IntellijAspectTestFixture) IntellijAspectTest(com.google.idea.blaze.aspect.IntellijAspectTest) Test(org.junit.Test) BazelIntellijAspectTest(com.google.idea.blaze.BazelIntellijAspectTest)

Example 17 with IntellijAspectTestFixture

use of com.google.devtools.intellij.IntellijAspectTestFixtureOuterClass.IntellijAspectTestFixture in project intellij by bazelbuild.

the class ScalaMacroLibraryTest method testScalaLibrary.

@Test
public void testScalaLibrary() throws Exception {
    IntellijAspectTestFixture testFixture = loadTestFixture(":simple_fixture");
    TargetIdeInfo target = findTarget(testFixture, ":simple");
    assertThat(target.getKindString()).isEqualTo("scala_macro_library");
    assertThat(relativePathsForArtifacts(target.getJavaIdeInfo().getSourcesList())).containsExactly(testRelative("Foo.scala"));
    assertThat(target.getJavaIdeInfo().getJarsList().stream().map(IntellijAspectTest::libraryArtifactToString).collect(Collectors.toList())).containsExactly(jarString(testRelative("simple.jar"), null, null));
    // Also contains ijars for scala-library.
    // Also contains jars + srcjars for liblibrary.
    assertThat(getOutputGroupFiles(testFixture, "intellij-info-java")).contains(testRelative("simple.intellij-info.txt"));
    assertThat(getOutputGroupFiles(testFixture, "intellij-resolve-java")).contains(testRelative("simple.jar"));
    assertThat(getOutputGroupFiles(testFixture, "intellij-compile-java")).contains(testRelative("simple.jar"));
    assertThat(getOutputGroupFiles(testFixture, "intellij-info-generic")).isEmpty();
    assertThat(target.getJavaIdeInfo().getMainClass()).isEmpty();
}
Also used : TargetIdeInfo(com.google.devtools.intellij.ideinfo.IntellijIdeInfo.TargetIdeInfo) IntellijAspectTestFixture(com.google.devtools.intellij.IntellijAspectTestFixtureOuterClass.IntellijAspectTestFixture) IntellijAspectTest(com.google.idea.blaze.aspect.IntellijAspectTest) Test(org.junit.Test) BazelIntellijAspectTest(com.google.idea.blaze.BazelIntellijAspectTest)

Example 18 with IntellijAspectTestFixture

use of com.google.devtools.intellij.IntellijAspectTestFixtureOuterClass.IntellijAspectTestFixture in project intellij by bazelbuild.

the class CcLibraryTest method testCcLibrary.

@Test
public void testCcLibrary() throws Exception {
    IntellijAspectTestFixture testFixture = loadTestFixture(":simple_fixture");
    TargetIdeInfo target = findTarget(testFixture, ":simple");
    assertThat(target.getKindString()).isEqualTo("cc_library");
    assertThat(target.hasCIdeInfo()).isTrue();
    assertThat(target.hasJavaIdeInfo()).isFalse();
    assertThat(target.hasAndroidIdeInfo()).isFalse();
    assertThat(target.hasPyIdeInfo()).isFalse();
    assertThat(target.hasProtoLibraryLegacyJavaIdeInfo()).isFalse();
    assertThat(relativePathsForArtifacts(target.getCIdeInfo().getSourceList())).containsExactly(testRelative("simple/simple.cc"));
    assertThat(relativePathsForArtifacts(target.getCIdeInfo().getHeaderList())).containsExactly(testRelative("simple/simple.h"));
    assertThat(relativePathsForArtifacts(target.getCIdeInfo().getTextualHeaderList())).containsExactly(testRelative("simple/simple_textual.h"));
    CIdeInfo cTargetIdeInfo = target.getCIdeInfo();
    assertThat(cTargetIdeInfo.getTargetIncludeList()).containsExactly("foo/bar");
    assertThat(cTargetIdeInfo.getTargetCoptList()).containsExactly("-DGOPT", "-Ifoo/baz/", "-I", "other/headers");
    assertThat(cTargetIdeInfo.getTargetDefineList()).containsExactly("VERSION2");
    // Make sure our understanding of where this attributes show up in other providers is correct.
    List<String> transDefineList = cTargetIdeInfo.getTransitiveDefineList();
    assertThat(transDefineList).contains("VERSION2");
    List<String> transQuoteIncludeDirList = cTargetIdeInfo.getTransitiveQuoteIncludeDirectoryList();
    assertThat(transQuoteIncludeDirList).contains(".");
// Can't test for this because the cc code stuffs source artifacts into
// the output group
// assertThat(testFixture.getIntellijResolveFilesList()).isEmpty();
}
Also used : TargetIdeInfo(com.google.devtools.intellij.ideinfo.IntellijIdeInfo.TargetIdeInfo) CIdeInfo(com.google.devtools.intellij.ideinfo.IntellijIdeInfo.CIdeInfo) IntellijAspectTestFixture(com.google.devtools.intellij.IntellijAspectTestFixtureOuterClass.IntellijAspectTestFixture) Test(org.junit.Test) BazelIntellijAspectTest(com.google.idea.blaze.BazelIntellijAspectTest)

Example 19 with IntellijAspectTestFixture

use of com.google.devtools.intellij.IntellijAspectTestFixtureOuterClass.IntellijAspectTestFixture in project intellij by bazelbuild.

the class CcLibraryTest method testCcLibraryHasToolchain.

@Test
public void testCcLibraryHasToolchain() throws Exception {
    IntellijAspectTestFixture testFixture = loadTestFixture(":simple_fixture");
    List<TargetIdeInfo> toolchains = testFixture.getTargetsList().stream().filter(target -> target.getKindString().equals("cc_toolchain")).collect(Collectors.toList());
    TargetIdeInfo toolchainTarget = Iterables.getOnlyElement(toolchains);
    assertThat(toolchainTarget.hasCToolchainIdeInfo()).isTrue();
    // Only cc_toolchain has toolchains
    TargetIdeInfo target = findTarget(testFixture, ":simple");
    assertThat(target.hasCToolchainIdeInfo()).isFalse();
    // Check that the library target deps on the toolchain.
    List<TargetIdeInfo> nativeToolchainDeps = dependenciesForTarget(target).stream().map(Dependency::getTarget).map(targetKey -> findTarget(testFixture, targetKey.getLabel())).filter(Objects::nonNull).filter(TargetIdeInfo::hasCToolchainIdeInfo).collect(toList());
    assertThat(toolchains).containsExactlyElementsIn(nativeToolchainDeps);
    CToolchainIdeInfo toolchainIdeInfo = toolchainTarget.getCToolchainIdeInfo();
    assertThat(toolchainIdeInfo.getCppExecutable()).isNotEmpty();
    // Should at least know the -std level (from some list of flags) to avoid b/70223102, unless the
    // default is sufficient.
    assertThat(toolchainIdeInfo.getCppOptionList().stream().anyMatch(option -> option.startsWith("-std="))).isTrue();
    // There should be several include directories, including:
    // - from compiler (for xmmintrin.h, etc.) (gcc/.../include, or clang/.../include)
    // - libc (currently something without gcc or clang and ends with "include",
    // which is a bit of a weak check)
    // - c++ library (usual several directories)
    // - if libstdc++, something like .../x86_64-vendor-linux-gnu/include/c++/<version>
    // - if libcxx, something like .../include/c++/<version>
    // This is assuming gcc or clang.
    assertThat(toolchainIdeInfo.getBuiltInIncludeDirectoryList()).isNotEmpty();
    assertThat(toolchainIdeInfo.getBuiltInIncludeDirectoryList().stream().anyMatch(dir -> (dir.contains("gcc/") || dir.contains("clang/")) && dir.endsWith("include"))).isTrue();
    assertThat(toolchainIdeInfo.getBuiltInIncludeDirectoryList().stream().anyMatch(dir -> !dir.contains("gcc/") && !dir.contains("clang/") && dir.endsWith("include"))).isTrue();
    assertThat(toolchainIdeInfo.getBuiltInIncludeDirectoryList().stream().anyMatch(dir -> dir.contains("c++"))).isTrue();
    // Check that we have *some* options. Not everything is portable, so it's hard to be strict.
    assertThat(toolchainIdeInfo.getBaseCompilerOptionList()).isNotEmpty();
}
Also used : TargetIdeInfo(com.google.devtools.intellij.ideinfo.IntellijIdeInfo.TargetIdeInfo) Iterables(com.google.common.collect.Iterables) IntellijAspectTestFixture(com.google.devtools.intellij.IntellijAspectTestFixtureOuterClass.IntellijAspectTestFixture) CToolchainIdeInfo(com.google.devtools.intellij.ideinfo.IntellijIdeInfo.CToolchainIdeInfo) RunWith(org.junit.runner.RunWith) Test(org.junit.Test) JUnit4(org.junit.runners.JUnit4) Truth.assertThat(com.google.common.truth.Truth.assertThat) BazelIntellijAspectTest(com.google.idea.blaze.BazelIntellijAspectTest) Collectors(java.util.stream.Collectors) CIdeInfo(com.google.devtools.intellij.ideinfo.IntellijIdeInfo.CIdeInfo) Objects(java.util.Objects) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) TargetIdeInfo(com.google.devtools.intellij.ideinfo.IntellijIdeInfo.TargetIdeInfo) Dependency(com.google.devtools.intellij.ideinfo.IntellijIdeInfo.Dependency) CToolchainIdeInfo(com.google.devtools.intellij.ideinfo.IntellijIdeInfo.CToolchainIdeInfo) Objects(java.util.Objects) IntellijAspectTestFixture(com.google.devtools.intellij.IntellijAspectTestFixtureOuterClass.IntellijAspectTestFixture) Dependency(com.google.devtools.intellij.ideinfo.IntellijIdeInfo.Dependency) Test(org.junit.Test) BazelIntellijAspectTest(com.google.idea.blaze.BazelIntellijAspectTest)

Example 20 with IntellijAspectTestFixture

use of com.google.devtools.intellij.IntellijAspectTestFixtureOuterClass.IntellijAspectTestFixture in project intellij by bazelbuild.

the class CcLibraryTest method testCcDependencies.

@Test
public void testCcDependencies() throws Exception {
    IntellijAspectTestFixture testFixture = loadTestFixture(":dep_fixture");
    TargetIdeInfo lib2 = findTarget(testFixture, ":lib2");
    TargetIdeInfo lib1 = findTarget(testFixture, ":lib1");
    assertThat(lib1.hasCIdeInfo()).isTrue();
    assertThat(lib2.hasCIdeInfo()).isTrue();
    CIdeInfo cIdeInfo1 = lib1.getCIdeInfo();
    assertThat(cIdeInfo1.getTargetIncludeList()).containsExactly("foo/bar");
    assertThat(cIdeInfo1.getTargetCoptList()).containsExactly("-DGOPT", "-Ifoo/baz/");
    assertThat(cIdeInfo1.getTargetDefineList()).containsExactly("VERSION2");
    assertThat(cIdeInfo1.getTransitiveDefineList()).contains("VERSION2");
    assertThat(cIdeInfo1.getTransitiveDefineList()).contains("COMPLEX_IMPL");
}
Also used : TargetIdeInfo(com.google.devtools.intellij.ideinfo.IntellijIdeInfo.TargetIdeInfo) CIdeInfo(com.google.devtools.intellij.ideinfo.IntellijIdeInfo.CIdeInfo) IntellijAspectTestFixture(com.google.devtools.intellij.IntellijAspectTestFixtureOuterClass.IntellijAspectTestFixture) Test(org.junit.Test) BazelIntellijAspectTest(com.google.idea.blaze.BazelIntellijAspectTest)

Aggregations

IntellijAspectTestFixture (com.google.devtools.intellij.IntellijAspectTestFixtureOuterClass.IntellijAspectTestFixture)34 BazelIntellijAspectTest (com.google.idea.blaze.BazelIntellijAspectTest)33 Test (org.junit.Test)33 TargetIdeInfo (com.google.devtools.intellij.ideinfo.IntellijIdeInfo.TargetIdeInfo)32 IntellijAspectTest (com.google.idea.blaze.aspect.IntellijAspectTest)11 CIdeInfo (com.google.devtools.intellij.ideinfo.IntellijIdeInfo.CIdeInfo)5 Iterables (com.google.common.collect.Iterables)1 Truth.assertThat (com.google.common.truth.Truth.assertThat)1 CToolchainIdeInfo (com.google.devtools.intellij.ideinfo.IntellijIdeInfo.CToolchainIdeInfo)1 Dependency (com.google.devtools.intellij.ideinfo.IntellijIdeInfo.Dependency)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 List (java.util.List)1 Objects (java.util.Objects)1 Collectors (java.util.stream.Collectors)1 Collectors.toList (java.util.stream.Collectors.toList)1 RunWith (org.junit.runner.RunWith)1 JUnit4 (org.junit.runners.JUnit4)1