summaryrefslogtreecommitdiff
path: root/src/test/java/org/javacs/InferBazelConfigTest.java
blob: f5dcd80df8bd9da07dfa6c90b79fa15fd7f45603 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package org.javacs;

import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collections;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class InferBazelConfigTest {

    private Path bazelWorkspace = Paths.get("src/test/test-project/bazel-workspace"),
            bazelTemp = Paths.get("src/test/test-project/bazel-temp");
    private InferConfig bazel =
            new InferConfig(bazelWorkspace, Collections.emptySet(), Paths.get("nowhere"), Paths.get("nowhere"));
    private Path bazelBin = bazelWorkspace.resolve("bazel-bin"),
            bazelBinTarget = bazelTemp.resolve("xyz/execroot/test/bazel-out/local-fastbuild/bin").toAbsolutePath(),
            bazelGenfiles = bazelWorkspace.resolve("bazel-genfiles"),
            bazelGenfilesTarget =
                    bazelTemp.resolve("xyz/execroot/test/bazel-out/local-fastbuild/genfiles").toAbsolutePath();

    @Before
    public void createBazelBinLink() throws IOException {
        assertTrue(Files.exists(bazelBinTarget));

        Files.createSymbolicLink(bazelBin, bazelBinTarget);
    }

    @After
    public void deleteBazelBinLink() throws IOException {
        Files.deleteIfExists(bazelBin);
    }

    @Before
    public void createBazelGenfilesLink() throws IOException {
        assertTrue(Files.exists(bazelGenfilesTarget));

        Files.createSymbolicLink(bazelGenfiles, bazelGenfilesTarget);
    }

    @After
    public void deleteBazelGenfilesLink() throws IOException {
        Files.deleteIfExists(bazelGenfiles);
    }

    @Test
    public void bazelWorkspaceClassPath() {
        assertThat(bazel.workspaceClassPath(), hasItem(bazelBinTarget.resolve("module/_javac/main/libmain_classes")));
    }

    @Test
    public void bazelBuildClassPath() {
        assertThat(
                bazel.buildClassPath(),
                hasItem(
                        bazelGenfilesTarget.resolve(
                                "external/com_external_external_library/jar/_ijar/jar/external/com_external_external_library/jar/external-library-1.2.jar")));
    }
}