Skip to content

Commit

Permalink
cleaning up unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mnr committed Apr 28, 2024
1 parent 52935a9 commit 1415e42
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 30 deletions.
19 changes: 6 additions & 13 deletions tests/testthat/test-is.R
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
test_that("is.rpi confirms/denies RPi", {
expect_true(
# if /etc/os-release exists,
# ...and it contains "Raspbian"
# then is.rpi() should == TRUE
# else !is.rpi() should == TRUE
if (file.exists("/etc/os-release")) {
if (any(grepl("Raspbian", readLines("/etc/os-release")))) {
is.rpi()
}
} else {
!is.rpi()
}
)
skip_on_os("mac", message = "This is a mac")
skip_on_os("windows", message = "this is windows")
skip_if_not( file.exists("/etc/os-release"), message = "missing /etc/os-release")
skip_if_not( any(grepl("Raspbian", readLines("/etc/os-release"))),
message = "Raspbian is not in /etc/os-release")
expect_true( is.rpi() )
})
5 changes: 3 additions & 2 deletions tests/testthat/test-rpi_get.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
test_that("multiplication works", {
expect_equal(2 * 2, 4)
test_that("rpi_get", {
skip_if_not(is.rpi(), message = "Not a Raspberry Pi")
skip("skip")
})
5 changes: 3 additions & 2 deletions tests/testthat/test-rpi_i2c_dump.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
test_that("multiplication works", {
expect_equal(2 * 2, 4)
test_that("rpi_i2c_dump", {
skip_if_not(is.rpi(), message = "Not a Raspberry Pi")
skip("skip")
})
6 changes: 3 additions & 3 deletions tests/testthat/test-rpi_i2c_get.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
test_that("rpi_i2c_get works", {
skip_if_not(is.rpi())
skip_if_not(is.rpi(), message = "Not a Raspberry Pi")
expect_no_error(rpi_i2c_get(
chip_address = 0x77,
data_address = 0xf0,
Expand All @@ -8,7 +8,7 @@ test_that("rpi_i2c_get works", {
})

test_that("rpi_i2c_get err chip address", {
skip_if_not(is.rpi())
skip_if_not(is.rpi(), message = "Not a Raspberry Pi")
expect_error(rpi_i2c_get(
chip_address = 0x07,
data_address = 0xf0,
Expand All @@ -17,7 +17,7 @@ test_that("rpi_i2c_get err chip address", {
})

test_that("rpi_i2c_get err data address", {
skip_if_not(is.rpi())
skip_if_not(is.rpi(), message = "Not a Raspberry Pi")
expect_error(rpi_i2c_get(
chip_address = 0x77,
data_address = 0xFFF,
Expand Down
5 changes: 3 additions & 2 deletions tests/testthat/test-rpi_i2c_set.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
test_that("multiplication works", {
expect_equal(2 * 2, 4)
test_that("rpi_i2c_set", {
skip_if_not(is.rpi(), message = "Not a Raspberry Pi")
skip("skip")
})
6 changes: 3 additions & 3 deletions tests/testthat/test-rpi_monitor.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
test_that("rpi_monitor works", {
skip_if_not(is.rpi())
expect_true(TRUE)
test_that("test rpi_monitor", {
skip_if_not(is.rpi(), message = "Not a Raspberry Pi")
skip("skip")
})
8 changes: 4 additions & 4 deletions tests/testthat/test-rpi_pwm.R
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
test_that("is pin_number valid for use with PWM?", {
skip_if_not(is.rpi())
skip_if_not(is.rpi(), message = "Not a Raspberry Pi")
expect_error(rpi_pwm(30, pwm_debug = TRUE))
})

test_that("Do two PWM pins collide?", {
skip_if_not(is.rpi())
skip_if_not(is.rpi(), message = "Not a Raspberry Pi")
expect_error(rpi_pwm(c(12, 32), pwm_debug = TRUE))
})

test_that("length(pin_number) > 3", {
skip_if_not(is.rpi())
skip_if_not(is.rpi(), message = "Not a Raspberry Pi")
expect_error(rpi_pwm(c(12, 32, 33), pwm_debug = TRUE))
})

test_that("real world test of pwm", {
skip_if_not(is.rpi())
skip_if_not(is.rpi(), message = "Not a Raspberry Pi")
message("Testing PWM in real world")
testPWM <- function() {
rpi_pwm(pin_number = 12, pwm_period = 50000, pwm_dutycycle = 10000)
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-rpi_set.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
test_that("Can we set a pin", {
message("Real world test of setting board pin 11")
skip_if_not(is.rpi())
skip_if_not(is.rpi(), message = "Not a Raspberry Pi")
expect_silent({
rpi_set(11, 1)
Sys.sleep(1)
Expand Down

0 comments on commit 1415e42

Please sign in to comment.