public void testAspectGenerateJson()

in javatests/com/google/devtools/bazel/e4b/integration/AspectIntegrationTest.java [105:154]


  public void testAspectGenerateJson() throws Exception {
    Command cmd = driver.bazelCommand("build", "--override_repository=local_eclipse_aspect=" + aspectWorkspace,
        "--aspects=@local_eclipse_aspect//:e4b_aspect.bzl%e4b_aspect", "-k",
        "--output_groups=ide-info-text,ide-resolve,-_,-defaults", "--experimental_show_artifacts",
        "//...").build();
    int retCode = cmd.run();
    assertEquals("Bazel failed to build, stderr: " + Joiner.on("\n").join(cmd.getErrorLines()),
        0, retCode);
    String[] jsonFiles = cmd.getErrorLines().stream().filter((s) -> {
      return s.startsWith(">>>") && s.endsWith(".json");
    }).map((s) -> {
      return s.substring(3);
    }).toArray(String[]::new);
    assertThat(jsonFiles).hasLength(3);

    ImmutableMap<String, IdeBuildInfo> infos =
        IdeBuildInfo.getInfo(ImmutableList.<String>copyOf(jsonFiles));

    assertThat(infos).hasSize(3);

    assertThat(infos.get("//java/my/pkg:pkg").getLabel()).isEqualTo("//java/my/pkg:pkg");
    assertThat(infos.get("//java/my/pkg:pkg").getLocation()).isEqualTo("java/my/pkg/BUILD");
    assertThat(infos.get("//java/my/pkg:pkg").getKind()).isEqualTo("java_binary");
    assertThat(infos.get("//java/my/pkg:pkg").getGeneratedJars()).isEmpty();
    assertThat(infos.get("//java/my/pkg:pkg").getDeps())
        .containsExactly("//java/my/other/pkg:Annex");
    assertThat(infos.get("//java/my/pkg:pkg").getSources())
        .containsExactly("java/my/pkg/Main.java");

    assertThat(infos.get("//java/my/other/pkg:Annex").getLabel())
        .isEqualTo("//java/my/other/pkg:Annex");
    assertThat(infos.get("//java/my/other/pkg:Annex").getLocation())
        .isEqualTo("java/my/other/pkg/BUILD");
    assertThat(infos.get("//java/my/other/pkg:Annex").getKind()).isEqualTo("java_library");
    assertThat(infos.get("//java/my/other/pkg:Annex").getGeneratedJars()).isEmpty();
    assertThat(infos.get("//java/my/other/pkg:Annex").getDeps()).isEmpty();
    assertThat(infos.get("//java/my/other/pkg:Annex").getSources())
        .containsExactly("java/my/other/pkg/Annex.java");

    assertThat(infos.get("//javatests/my/other/pkg:AnnexTest").getLabel())
        .isEqualTo("//javatests/my/other/pkg:AnnexTest");
    assertThat(infos.get("//javatests/my/other/pkg:AnnexTest").getLocation())
        .isEqualTo("javatests/my/other/pkg/BUILD");
    assertThat(infos.get("//javatests/my/other/pkg:AnnexTest").getKind()).isEqualTo("java_test");
    assertThat(infos.get("//javatests/my/other/pkg:AnnexTest").getGeneratedJars()).isEmpty();
    assertThat(infos.get("//javatests/my/other/pkg:AnnexTest").getDeps())
        .containsExactly("//java/my/other/pkg:Annex");
    assertThat(infos.get("//javatests/my/other/pkg:AnnexTest").getSources())
        .containsExactly("javatests/my/other/pkg/AnnexTest.java");
  }