Skip to content

Commit

Permalink
Tests for cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
SocksDevil committed Apr 13, 2021
1 parent 73bc827 commit 483d9fd
Show file tree
Hide file tree
Showing 10 changed files with 105 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@ private Optional<CppBuildTarget> getCppBuildTarget() {
.limit(2)
.collect(Collectors.toList());

if (cppInfo.isEmpty()) return Optional.empty();

String compiler = cppInfo.get(0);
String compilerExecutable = cppInfo.get(1);
cppBuildTarget = new CppBuildTarget(null, compiler, compilerExecutable, compilerExecutable);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ public <T> CompletableFuture<T> getValue(
.exceptionally( // TODO remove eithers in next PR
exception -> {
LOGGER.error(
"{} call finishing with exception: {}", methodName, exception.getStackTrace());
"{} call finishing with exception: {}",
methodName,
exception.getCause().getStackTrace());

return Either.forLeft(
new ResponseError(ResponseErrorCode.InternalError, exception.getMessage(), null));
Expand Down
23 changes: 22 additions & 1 deletion src/test/java/org/jetbrains/bsp/bazel/BazelBspServerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,34 @@ public void run() {
getActionGraphV2Tests().stream(),
getJava8ProjectTests().stream(),
getJava11ProjectTests().stream(),
getJavaDefaultProjectTests().stream())
getJavaDefaultProjectTests().stream(),
getCppProjects().stream())
.collect(Collectors.toList());

LOGGER.info("Created TestClients. Running BazelBspServerTest...");
runTests(testsToRun);
}

private List<BazelBspServerSingleTest> getCppProjects() {
TestClient client =
TestClient$.MODULE$.testInitialStructure(
BazelBspServerTestData.CPP_FULL_PATH,
ImmutableMap.of(),
BazelBspServerTestData.TEST_CLIENT_TIMEOUT_IN_MINUTES);
return ImmutableList.of(
new BazelBspServerSingleTest(
"cpp project",
() ->
client.testCompareWorkspaceTargetsResults(
BazelBspServerTestData.EXPECTED_BUILD_TARGETS_CPP)),
new BazelBspServerSingleTest(
"cpp options",
() ->
client.testCppOptions(
BazelBspServerTestData.CPP_OPTIONS_PARAMS,
BazelBspServerTestData.CPP_OPTIONS_RESULT)));
}

private List<BazelBspServerSingleTest> getJava8ProjectTests() {
TestClient client =
TestClient$.MODULE$.testInitialStructure(
Expand Down
37 changes: 37 additions & 0 deletions src/test/java/org/jetbrains/bsp/bazel/BazelBspServerTestData.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
import ch.epfl.scala.bsp4j.BuildTargetCapabilities;
import ch.epfl.scala.bsp4j.BuildTargetDataKind;
import ch.epfl.scala.bsp4j.BuildTargetIdentifier;
import ch.epfl.scala.bsp4j.CppBuildTarget;
import ch.epfl.scala.bsp4j.CppOptionsItem;
import ch.epfl.scala.bsp4j.CppOptionsParams;
import ch.epfl.scala.bsp4j.CppOptionsResult;
import ch.epfl.scala.bsp4j.DependencySourcesItem;
import ch.epfl.scala.bsp4j.DependencySourcesResult;
import ch.epfl.scala.bsp4j.InverseSourcesResult;
Expand Down Expand Up @@ -44,6 +48,7 @@ class BazelBspServerTestData {
private static final String JAVA_8 = "java-8-project";
private static final String JAVA_11 = "java-11-project";
private static final String JAVA_DEFAULT = "java-default-project";
private static final String CPP_PROJECT = "cpp-project";
private static final String SAMPLE_REPO_EXAMPLE_PATH = SAMPLE_REPO_PATH + "/example";
private static final String SAMPLE_REPO_DEP_PATH = SAMPLE_REPO_PATH + "/dep";

Expand Down Expand Up @@ -76,6 +81,7 @@ class BazelBspServerTestData {
static final String ACTION_GRAPH_V2_FULL_PATH = WORKSPACE_DIR_PATH + "/" + ACTION_GRAPH_V2;
static final String JAVA_8_FULL_PATH = WORKSPACE_DIR_PATH + "/" + JAVA_8;
static final String JAVA_11_FULL_PATH = WORKSPACE_DIR_PATH + "/" + JAVA_11;
static final String CPP_FULL_PATH = WORKSPACE_DIR_PATH + "/" + CPP_PROJECT;
static final String JAVA_DEFAULT_FULL_PATH = WORKSPACE_DIR_PATH + "/" + JAVA_DEFAULT;
static final String DEFAULT_JAVA_HOME = "external/local_jdk/";

Expand All @@ -85,6 +91,8 @@ class BazelBspServerTestData {
new JvmBuildTarget(null, "8");
private static final JvmBuildTarget EXAMPLE_JVM_TARGET_JAVA_11 =
new JvmBuildTarget(DEFAULT_JAVA_HOME, "11");
private static final CppBuildTarget EXAMPLE_CPP_TARGET =
new CppBuildTarget(null, "compiler", "/bin/gcc", "/bin/gcc");

private static final List<String> SCALA_TARGET_JARS =
ImmutableList.of(
Expand Down Expand Up @@ -312,4 +320,33 @@ class BazelBspServerTestData {
};
static final WorkspaceBuildTargetsResult EXPECTED_BUILD_TARGETS_JAVA_11 =
new WorkspaceBuildTargetsResult(ImmutableList.of(EXAMPLE_JAVA_TARGET_JAVA_11));

static final BuildTargetIdentifier GOOGLE_TEST_IDENTIFIER =
new BuildTargetIdentifier("@com_google_googletest//:gtest_main");

static final BuildTarget EXAMPLE_CPP_BUILD_TARGET =
new BuildTarget(
EXAMPLE_EXAMPLE_TARGET,
ImmutableList.of(),
ImmutableList.of(Constants.CPP),
ImmutableList.of(GOOGLE_TEST_IDENTIFIER),
new BuildTargetCapabilities(true, false, true)) {
{
setData(EXAMPLE_CPP_TARGET);
setDataKind(BuildTargetDataKind.CPP);
}
};

static final WorkspaceBuildTargetsResult EXPECTED_BUILD_TARGETS_CPP =
new WorkspaceBuildTargetsResult(ImmutableList.of(EXAMPLE_CPP_BUILD_TARGET));

static final CppOptionsParams CPP_OPTIONS_PARAMS =
new CppOptionsParams(ImmutableList.of(EXAMPLE_EXAMPLE_TARGET));

static final CppOptionsItem CPP_OPTIONS_ITEM =
new CppOptionsItem(
EXAMPLE_EXAMPLE_TARGET, ImmutableList.of(), ImmutableList.of(), ImmutableList.of());

static final CppOptionsResult CPP_OPTIONS_RESULT =
new CppOptionsResult(ImmutableList.of(CPP_OPTIONS_ITEM));
}
2 changes: 2 additions & 0 deletions test-resources/cpp-project/.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
build --java_toolchain=@bazel_tools//tools/jdk:toolchain_java8
build --host_java_toolchain=@bazel_tools//tools/jdk:toolchain_java8
5 changes: 5 additions & 0 deletions test-resources/cpp-project/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.bazelbsp/
.bsp/
.idea/
.ijwb/
bazel-*
16 changes: 16 additions & 0 deletions test-resources/cpp-project/WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
workspace(name = "cpp_test")

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
name = "com_google_googletest",
sha256 = "9a8a166eb6a56c7b3d7b19dc2c946fe4778fd6f21c7a12368ad3b836d8f1be48",
strip_prefix = "googletest-8567b09290fe402cf01923e2131c5635b8ed851b",
# Keep this URL in sync with ABSL_GOOGLETEST_COMMIT in ci/cmake_common.sh.
urls = ["https://github.com/google/googletest/archive/8567b09290fe402cf01923e2131c5635b8ed851b.zip"], # 2020-06-12T22:24:28Z
)

local_repository(
name = "intellij_aspect",
path = "/home/andre/Projects/bazel-intellij/aspect",
)
9 changes: 9 additions & 0 deletions test-resources/cpp-project/example/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
load("@rules_cc//cc:defs.bzl", "cc_binary")

cc_binary(
name = "example",
srcs = ["main.cpp"],
deps = [
"@com_google_googletest//:gtest_main",
],
)
7 changes: 7 additions & 0 deletions test-resources/cpp-project/example/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <iostream>

#include "gtest/gtest.h"

int main(){
std::cout << "Meias" << std::endl;

This comment has been minimized.

Copy link
@SocksDevil

SocksDevil May 18, 2021

Author Contributor

Yes it does hehe

}
4 changes: 2 additions & 2 deletions third_party.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ def _dependency(coordinates, exclusions = None):
_deps = [
_dependency("com.google.code.gson:gson:2.8.5"),
_dependency("com.google.guava:guava:28.1-jre"),
_dependency("ch.epfl.scala:bsp4j:2.0.0-M13+50-16b7c79f-SNAPSHOT"),
_dependency("ch.epfl.scala:bsp-testkit_2.13:2.0.0-M13+50-16b7c79f-SNAPSHOT"),
_dependency("ch.epfl.scala:bsp4j:2.0.0-M13+51-a3c47f39+20210413-2148-SNAPSHOT"),
_dependency("ch.epfl.scala:bsp-testkit_2.13:2.0.0-M13+51-a3c47f39+20210413-2148-SNAPSHOT"),
_dependency("org.eclipse.lsp4j:org.eclipse.lsp4j.jsonrpc:0.8.0"),
_dependency("org.eclipse.xtext:org.eclipse.xtext.xbase.lib:2.19.0"),
_dependency("commons-cli:commons-cli:jar:1.4"),
Expand Down

1 comment on commit 483d9fd

@SocksDevil
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

third_party.bzl:33
This is a known error and will be removed 😅

Please sign in to comment.