aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/test/LcovMerger/javatests/com/google/devtools/lcovmerger/MainTest.java
blob: a6b99fb12e4bbc4c5a3c4a692d8ce699e95de82c (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
// Copyright 2018 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.lcovmerger;

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

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

/**
 * Test for {@link Main}.
 */
@RunWith(JUnit4.class)
public class MainTest {

  private Path coverageDir;

  @Before
  public void createCoverageDirectory() throws IOException {
    coverageDir = Files.createTempDirectory("coverage-dir");
  }

  @Test
  public void testMainEmptyCoverageDir() {
    assertThat(Main.getLcovTracefilesFromDir(coverageDir.toAbsolutePath().toString())).isEmpty();
  }

  @Test
  public void testMainGetLcovTracefiles()  throws IOException {
    Path ccCoverageDir = Files.createTempDirectory(coverageDir, "cc_coverage");
    Path javaCoverageDir = Files.createTempDirectory(coverageDir, "java_coverage");

    Files.createTempFile(ccCoverageDir, "tracefile1", ".dat");
    Files.createTempFile(javaCoverageDir, "tracefile2", ".dat");

    List<File> tracefiles = Main.getLcovTracefilesFromDir(coverageDir.toAbsolutePath().toString());
    assertThat(tracefiles).hasSize(2);
  }
}