Skip to content

Commit

Permalink
[R-package] Added tests on LGBM_GetLastError_R (#3005)
Browse files Browse the repository at this point in the history
  • Loading branch information
jameslamb authored Apr 25, 2020
1 parent 22d6d1f commit 5304885
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions R-package/R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ lgb.encode.char <- function(arr, len) {

}

# [description] Raise an error. Before raising that error, check for any error message
# stored in a buffer on the C++ side.
lgb.last_error <- function() {
# Perform text error buffering
buf_len <- 200L
Expand Down
20 changes: 20 additions & 0 deletions R-package/tests/testthat/test_utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,23 @@ test_that("lgb.params2str() works as expected for a key in params with multiple
, "objective=magic metric=a,ab,abc,abcdefg nrounds=10 learning_rate=0.0000001"
)
})

context("lgb.last_error")

test_that("lgb.last_error() throws an error if there are no errors", {
expect_error({
lgb.last_error()
}, regexp = "Everything is fine")
})

test_that("lgb.last_error() correctly returns errors from the C++ side", {
data(agaricus.train, package = "lightgbm")
train <- agaricus.train
dvalid1 <- lgb.Dataset(
data = train$data
, label = as.matrix(rnorm(5L))
)
expect_error({
dvalid1$construct()
}, regexp = "[LightGBM] [Fatal] Length of label is not same with #data", fixed = TRUE)
})

0 comments on commit 5304885

Please sign in to comment.