Skip to content

Commit c4974c3

Browse files
committed
minitest v0.0.1
1 parent 98c3008 commit c4974c3

File tree

1 file changed

+29
-30
lines changed

1 file changed

+29
-30
lines changed

tests/tests.R

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
1-
# minitest - a minimal testing framework ---------------------------------------
1+
# minitest - a minimal testing framework v0.0.1 --------------------------------
22
test_library <- function(package) library(package = package, character.only = TRUE)
33
test_true <- function(x) invisible(isTRUE(x) || {print(x); stop("the above was returned instead of TRUE")})
4-
test_truew <- function(x) invisible(suppressWarnings(isTRUE(x)) || {print(x); stop("the above was returned instead of TRUE")})
54
test_null <- function(x) invisible(is.null(x) || {print(x); stop("the above was returned instead of NULL")})
6-
test_notnull <- function(x) invisible(!is.null(x) || stop("is NULL when expected to be not NULL"))
5+
test_notnull <- function(x) invisible(!is.null(x) || stop("returns NULL when expected to be not NULL"))
76
test_zero <- function(x) invisible(x == 0L || {print(x); stop("the above was returned instead of 0L")})
87
test_type <- function(type, x) invisible(typeof(x) == type || {stop("object of type '", typeof(x), "' was returned instead of '", type, "'")})
98
test_class <- function(class, x) invisible(inherits(x, class) || {stop("object of class '", paste(class(x), collapse = ", "), "' was returned instead of '", class, "'")})
109
test_equal <- function(a, b) invisible(a == b || {print(a); print(b); stop("the above expressions were not equal")})
1110
test_identical <- function(a, b) invisible(identical(a, b) || {print(a); print(b); stop("the above expressions were not identical")})
1211
test_print <- function(x) invisible(is.character(capture.output(print(x))) || stop("print output of expression cannot be captured as a character value"))
13-
test_error <- function(x, containing = "") inherits(x <- tryCatch(x, error = identity), "error") && grepl(containing, x[["message"]], fixed = TRUE) || stop("expected error message containing '", containing, "' was not generated")
12+
test_error <- function(x, containing = "") invisible(inherits(x <- tryCatch(x, error = identity), "error") && grepl(containing, x[["message"]], fixed = TRUE) || stop("expected error message containing '", containing, "' was not generated"))
1413
# ------------------------------------------------------------------------------
1514

1615
test_library("nanonext")
@@ -39,7 +38,7 @@ test_class("nano", n$opt("socket-name", "nano"))
3938
test_equal(n$opt("socket-name"), "nano")
4039
test_error(n$opt("socket-name", NULL), "argument")
4140
test_print(n$listener[[1]])
42-
test_true(inherits(n$listener[[1]], "nanoListener"))
41+
test_class("nanoListener", n$listener[[1]])
4342
test_equal(n$listener[[1]]$url, "inproc://nanonext")
4443
test_equal(n$listener[[1]]$state, "not started")
4544
test_class("nano", n$listener_opt("recv-size-max", 1024)[[1L]])
@@ -53,7 +52,7 @@ test_error(n$listener_opt("false", list()), "type")
5352
test_zero(n$listener_start())
5453
test_equal(n$listener[[1]]$state, "started")
5554
test_print(n1$dialer[[1]])
56-
test_true(inherits(n1$dialer[[1]], "nanoDialer"))
55+
test_class("nanoDialer", n1$dialer[[1]])
5756
test_equal(n1$dialer[[1]]$url, "inproc://nanonext")
5857
test_equal(n1$dialer[[1]]$state, "not started")
5958
test_class("nano", n1$dialer_opt("reconnect-time-min", 1000)[[1L]])
@@ -135,40 +134,40 @@ test_class("recvAio", rraio <- n1$recv_aio(mode = "int", timeout = 500))
135134
test_type("raw", call_aio(rraio)$data)
136135
test_class("sendAio", sraio <- n$send_aio(as.raw(0L), mode = "raw", timeout = 500))
137136
test_class("recvAio", rraio <- n1$recv_aio(mode = "logical", timeout = 500))
138-
test_truew(is.raw(collect_aio(rraio)))
137+
test_type("raw", collect_aio(rraio))
139138
test_class("sendAio", sraio <- n$send_aio(as.raw(0L), mode = "raw", timeout = 500))
140139
test_class("recvAio", rraio <- n1$recv_aio(mode = "numeric", timeout = 500))
141140
test_type("raw", rraio[])
142141
test_class("sendAio", sraio <- n$send_aio(as.raw(0L), mode = "raw", timeout = 500))
143142
test_class("recvAio", rraio <- n1$recv_aio(mode = "complex", timeout = 500))
144-
test_type("raw", collect_aio_(rraio))
143+
test_type("raw", suppressWarnings(collect_aio_(rraio)))
145144
test_error(opt(rraio[["aio"]], "false") <- 0L, "valid")
146145
test_error(subscribe(rraio[["aio"]], "false"), "valid")
147146
test_error(opt(rraio[["aio"]], "false"), "valid")
148147
test_error(stat(rraio[["aio"]], "pipes"), "valid")
149148

150149
test_zero(n$dial(url = "inproc://two", autostart = FALSE))
151150
test_zero(n$dialer_start())
152-
test_true(inherits(n$dialer[[1L]], "nanoDialer"))
151+
test_class("nanoDialer", n$dialer[[1L]])
153152
test_type("double", stat(n$dialer[[1L]], "id"))
154153
test_zero(n$listen(url = "inproc://three", autostart = FALSE))
155154
test_zero(n$listener_start())
156-
test_true(inherits(n$listener[[2L]], "nanoListener"))
155+
test_class("nanoListener", n$listener[[2L]])
157156
test_type("double", stat(n$listener[[2L]], "id"))
158157
test_zero(n$dial(url = "inproc://four"))
159158
test_zero(close(n$listener[[1]]))
160-
test_truew(close(n$listener[[1]]) == 12L)
159+
test_equal(suppressWarnings(close(n$listener[[1]])), 12L)
161160
test_zero(close(n1$dialer[[1]]))
162-
test_truew(close(n1$dialer[[1]]) == 12L)
161+
test_equal(suppressWarnings(close(n1$dialer[[1]])), 12L)
163162
test_zero(reap(n$listener[[2]]))
164163
test_zero(reap(n$dialer[[2]]))
165164
test_zero(n$close())
166165
test_zero(n1$close())
167-
test_truew(n1$close() == 7L)
166+
test_equal(suppressWarnings(n1$close()), 7L)
168167
test_equal(n$socket[["state"]], "closed")
169168
test_equal(n1$socket[state], "closed")
170169

171-
test_true(inherits(cv <- cv(), "conditionVariable"))
170+
test_class("conditionVariable", cv <- cv())
172171
test_print(cv)
173172
test_type("externalptr", cv2 <- cv())
174173
test_true(!until(cv, 10L))
@@ -189,8 +188,8 @@ test_class("nano", req$opt("req:resend-time", 1000))
189188
test_equal(req$opt("req:resend-time"), 1000L)
190189
test_error(req$opt("none"), "supported")
191190
test_type("externalptr", req$context_open())
192-
test_true(inherits(req$context, "nanoContext"))
193-
test_true(inherits(req$context, "nano"))
191+
test_class("nanoContext", req$context)
192+
test_class("nano", req$context)
194193
test_type("integer", req$context$id)
195194
test_equal(req$context$state, "opened")
196195
test_equal(req$context$protocol, "req")
@@ -311,7 +310,7 @@ rep$dialer <- NULL
311310
test_type("externalptr", rep$dialer[[1L]])
312311
test_zero(close(ctx))
313312
if (is_nano(p)) test_equal(reap(p), 12L)
314-
if (is_nano(p)) test_truew(close(p) == 12L)
313+
if (is_nano(p)) test_equal(suppressWarnings(close(p)), 12L)
315314

316315
test_class("nanoObject", pub <- nano("pub", listen = "inproc://ps"))
317316
test_class("nanoObject", sub <- nano("sub", dial = "inproc://ps", autostart = NA))
@@ -365,18 +364,18 @@ test_true(!wait(cv))
365364
test_true(!wait(cv2))
366365
test_class("errorValue", resp$recv())
367366

368-
test_true(inherits(bus <- socket(protocol = "bus"), "nanoSocket"))
369-
test_true(inherits(push <- socket(protocol = "push"), "nanoSocket"))
370-
test_true(inherits(pull <- socket(protocol = "pull"), "nanoSocket"))
371-
test_true(inherits(pair <- socket(protocol = "pair"), "nanoSocket"))
372-
test_true(inherits(poly <- socket(protocol = "poly"), "nanoSocket"))
367+
test_class("nanoSocket", bus <- socket(protocol = "bus"))
368+
test_class("nanoSocket", push <- socket(protocol = "push"))
369+
test_class("nanoSocket", pull <- socket(protocol = "pull"))
370+
test_class("nanoSocket", pair <- socket(protocol = "pair"))
371+
test_class("nanoSocket", poly <- socket(protocol = "poly"))
373372
test_class("nano", bus)
374-
test_truew(listen(bus, url = "test") == 3L)
375-
test_truew(dial(bus, url = "test") == 3L)
373+
test_equal(suppressWarnings(listen(bus, url = "test")), 3L)
374+
test_equal(suppressWarnings(dial(bus, url = "test")), 3L)
376375
test_error(listen(bus, url = "tls+tcp://localhost/:0", tls = "wrong"), "valid TLS")
377376
test_error(dial(bus, url = "tls+tcp://localhost/:0", tls = "wrong"), "valid TLS")
378377
test_zero(close(bus))
379-
test_truew(close(bus) == 7L)
378+
test_equal(suppressWarnings(close(bus)), 7L)
380379
test_zero(close(push))
381380
test_zero(close(pull))
382381
test_zero(reap(pair))
@@ -412,13 +411,13 @@ sess <- ncurl_session("https://postman-echo.com/post", method = "POST", headers
412411
test_true(is_ncurl_session(sess) || is_error_value(sess))
413412
if (is_ncurl_session(sess)) test_equal(length(transact(sess)), 3L)
414413
if (is_ncurl_session(sess)) test_zero(close(sess))
415-
if (is_ncurl_session(sess)) test_truew(close(sess) == 7L)
414+
if (is_ncurl_session(sess)) test_equal(suppressWarnings(close(sess)), 7L)
416415
sess <- ncurl_session("https://postman-echo.com/post", convert = FALSE, method = "POST", headers = c(`Content-Type` = "text/plain"), timeout = 3000)
417416
test_true(is_ncurl_session(sess) || is_error_value(sess))
418417
if (is_ncurl_session(sess)) test_equal(length(transact(sess)), 3L)
419418
if (is_ncurl_session(sess)) test_zero(close(sess))
420419
if (is_ncurl_session(sess)) test_equal(transact(sess)$data, 7L)
421-
test_truew(is_error_value(ncurl_session("https://i")))
420+
test_class("errorValue", suppressWarnings(ncurl_session("https://i")))
422421
test_error(ncurl_aio("https://", tls = "wrong"), "valid TLS")
423422
test_error(ncurl("https://www.example.com/", tls = "wrong"), "valid TLS")
424423
test_type("externalptr", etls <- tls_config())
@@ -603,7 +602,7 @@ test_equal(length(cert), 2L)
603602
test_type("character", cert[[1L]])
604603
test_identical(names(cert), c("server", "client"))
605604
test_type("externalptr", tls <- tls_config(client = cert$client))
606-
test_true(inherits(tls, "tlsConfig"))
605+
test_class("tlsConfig", tls)
607606
test_print(tls)
608607
test_class("errorValue", ncurl("https://www.example.com/", tls = tls)$status)
609608
test_class("errorValue", call_aio(ncurl_aio("https://www.example.com/", tls = tls))$data)
@@ -613,8 +612,8 @@ test_true(is_ncurl_session(sess) || is_error_value(sess))
613612
if (is_ncurl_session(sess)) test_class("errorValue", transact(sess)[["headers"]])
614613
test_type("externalptr", s <- socket(listen = "tls+tcp://127.0.0.1:5556", tls = tls_config(server = cert$server)))
615614
test_type("externalptr", s1 <- socket(dial = "tls+tcp://127.0.0.1:5556", tls = tls))
616-
test_truew(dial(s, url = "tls+tcp://.", tls = tls, error = FALSE) > 0)
617-
test_truew(listen(s, url = "tls+tcp://.", tls = tls, error = FALSE) > 0)
615+
test_true(suppressWarnings(dial(s, url = "tls+tcp://.", tls = tls, error = FALSE)) > 0)
616+
test_true(suppressWarnings(listen(s, url = "tls+tcp://.", tls = tls, error = FALSE)) > 0)
618617
test_zero(close(s1))
619618
test_zero(close(s))
620619
if (promises) test_class("nano", s <- socket(listen = "inproc://nanonext"))

0 commit comments

Comments
 (0)