File: test-gcov.R

package info (click to toggle)
r-cran-covr 3.5.1%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 984 kB
  • sloc: javascript: 238; cpp: 54; ansic: 48; xml: 41; sh: 18; makefile: 11
file content (59 lines) | stat: -rw-r--r-- 2,057 bytes parent folder | download | duplicates (3)
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
context("gcov")
test_that("parse_gcov parses files properly", {
  mockery::stub(parse_gcov, "file.exists", TRUE)
  mockery::stub(normalize_path, "normalizePath", "simple.c")
  mockery::stub(parse_gcov, "line_coverages", function(source_file, matches, values, ...) values)


  mockery::stub(parse_gcov, "readLines",
"        -:    0:Source:simple.c")
  expect_equal(parse_gcov("hi.c.gcov"), numeric())

  mockery::stub(parse_gcov, "readLines", c(
"        -:    0:Source:simple.c",
"        -:    1:#define USE_RINTERNALS"))
  expect_equal(parse_gcov("hi.c.gcov"), numeric())

  mockery::stub(parse_gcov, "readLines", c(
"        -:    0:Source:simple.c",
"        -:    0:Graph:simple.gcno",
"        -:    0:Data:simple.gcda",
"        -:    0:Runs:1",
"        -:    0:Programs:1",
"        -:    1:#define USE_RINTERNALS",
"        -:    2:#include <R.h>",
"        -:    3:#include <Rdefines.h>",
"        -:    4:#include <R_ext/Error.h>",
"        -:    5:",
"        4:    6:SEXP simple_(SEXP x) {"))
  expect_equal(parse_gcov("hi.c.gcov"), 4)

  mockery::stub(parse_gcov, "readLines", c(
"        -:    0:Source:simple.c",
"        -:    0:Graph:simple.gcno",
"        -:    0:Data:simple.gcda",
"        -:    0:Runs:1",
"        -:    0:Programs:1",
"        -:    1:#define USE_RINTERNALS",
"        -:    2:#include <R.h>",
"        -:    3:#include <Rdefines.h>",
"        -:    4:#include <R_ext/Error.h>",
"        -:    5:",
"        4:    6:SEXP simple_(SEXP x) {",
"        -:    7:  }",
"    #####:    8:    pout[0] = 0;" # nolint
    ))
    expect_equal(parse_gcov("hi.c.gcov"), c(4, 0))
})

test_that("clean_gcov correctly clears files", {

  dir <- file.path(tempfile(), "src")

  dir.create(dir, recursive = TRUE)
  file.create(file.path(dir, c("simple.c", "Makevars", "simple.c.gcov", "simple.gcda", "simple.gcno")))
  expect_identical(list.files(dir), sort(c("simple.c", "Makevars", "simple.c.gcov", "simple.gcda", "simple.gcno")))

  clean_gcov(dirname(dir))
  expect_identical(list.files(dir), sort(c("simple.c", "Makevars")))
})