Thanks to visit codestin.com
Credit goes to github.com

Skip to content

'UseMethod' used in an inappropriate fashion #392

@wlandau

Description

@wlandau

I am having problems with S3 and development covr (89029d4). CRAN covr appears unaffected.

# Example file with S3:
source <- quote({
  mtd <- function(x, ...) {
    UseMethod("mtd")
  }

  mtd.cls <- function(x, ...) {
    x[[1]]
  }
})

# A test:
test <- quote({
  library(testthat)
  test_that("", {
    x <- structure(list("x"), class = "cls")
    expect_equal(mtd(x), "x")
  })
})

# The test passes.
eval(source)
eval(test)

# The same test fails with https://github.com/r-lib/covr/commit/89029d4670c09a106bbadfb384eec8b7ed42e885.
# Passes with CRAN covr.
writeLines(deparse(source), "source.R")
writeLines(deparse(test), "test.R")
library(covr)
file_coverage("source.R", "test.R")
#> Error: Test failed: ''
#> * 'UseMethod' used in an inappropriate fashion
#> 1: expect_equal(mtd(x), "x") at test.R:5
#> 2: quasi_label(enquo(object), label, arg = "object")
#> 3: eval_bare(get_expr(quo), get_env(quo))
#> 4: mtd(x)
#> 5: identity({
#>        covr:::count("source.R:3:9:3:24:9:24:3:3")
#>        UseMethod("mtd")
#>    }) at source.R:3

Created on 2019-08-08 by the reprex package (v0.3.0)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions