File: errors.R

package info (click to toggle)
r-cran-parsetools 0.1.3-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 780 kB
  • sloc: sh: 13; makefile: 2
file content (31 lines) | stat: -rw-r--r-- 1,189 bytes parent folder | download | duplicates (2)
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

line_error <- function(id, msg, ..., pd=get('pd', parent.frame()))
    stop(filename(pd), ':', start_line(id, pd), ':  ', msg, ...)

line_error_if <- function(test, id, msg, ..., pd=get('pd', parent.frame()))
    if (force(test))
        stop(filename(pd), ':', start_line(id, pd), ':  ', msg, ...)

col_error <- function(id, msg, ..., pd=get('pd', parent.frame()))
    stop(filename(pd), ':', start_line(id, pd), ':', start_col(id, pd), ':  ', msg, ...)


if(FALSE){#@testing errors
    pd <- get_parse_data(parse(text='
    classDef <- setClass( "testClass"
         , slots = c( x="numeric" #< the x field
                    , y="matrix"  #< the y field
                    )
         )', keep.source=TRUE))

    id <- pd[pd$text == "#< the x field", 'id']

    expect_error(line_error(id, 'testing', pd=pd)
                , "<text>:3:  testing")
    expect_error(line_error_if(TRUE, id, 'testing', pd=pd)
                , "<text>:3:  testing")
    expect_error( col_error(id, 'testing col error', pd=pd)
                , "<text>:3:35:  testing col error")
    expect_silent(line_error_if(FALSE, id, 'testing', pd=pd))
    expect_null(line_error_if(FALSE, id, 'testing', pd=pd))
}