diff --git a/DESCRIPTION b/DESCRIPTION index 61fab39..7124211 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -10,3 +10,6 @@ Roxygen: list(markdown = TRUE) RoxygenNote: 7.2.3 Config/rextendr/version: 0.3.1.9000 SystemRequirements: Cargo (Rust's package manager), rustc +Suggests: + testthat (>= 3.0.0) +Config/testthat/edition: 3 diff --git a/osinfo.Rproj b/osinfo.Rproj index aaa62a5..69fafd4 100644 --- a/osinfo.Rproj +++ b/osinfo.Rproj @@ -5,8 +5,13 @@ SaveWorkspace: No AlwaysSaveHistory: Default EnableCodeIndexing: Yes +UseSpacesForTab: Yes +NumSpacesForTab: 2 Encoding: UTF-8 +RnwWeave: Sweave +LaTeX: pdfLaTeX + AutoAppendNewline: Yes StripTrailingWhitespace: Yes LineEndingConversion: Posix diff --git a/src/rust/src/lib.rs b/src/rust/src/lib.rs index 1149a5b..b7a06b0 100644 --- a/src/rust/src/lib.rs +++ b/src/rust/src/lib.rs @@ -1,4 +1,5 @@ use extendr_api::prelude::*; +use std::env; #[derive(Debug, PartialEq, IntoDataFrameRow)] struct OsInfo { @@ -13,8 +14,10 @@ fn os_info_impl() -> List { list!( version = info.version().to_string(), os_type = info.os_type().to_string(), + edition = info.edition(), architecture = info.architecture(), - codename = info.codename() + codename = info.codename(), + os = env::consts::OS, ) } diff --git a/tests/testthat.R b/tests/testthat.R new file mode 100644 index 0000000..897f9ae --- /dev/null +++ b/tests/testthat.R @@ -0,0 +1,12 @@ +# This file is part of the standard setup for testthat. +# It is recommended that you do not modify it. +# +# Where should you do additional test configuration? +# Learn more about the roles of various files in: +# * https://r-pkgs.org/testing-design.html#sec-tests-files-overview +# * https://testthat.r-lib.org/articles/special-files.html + +library(testthat) +library(osinfo) + +test_check("osinfo") diff --git a/tests/testthat/test-os-info.R b/tests/testthat/test-os-info.R new file mode 100644 index 0000000..985c4bf --- /dev/null +++ b/tests/testthat/test-os-info.R @@ -0,0 +1,18 @@ +test_that("os_info runs", { + sys_info <- Sys.info() + osinfo <- os_info() + + expect_equal(osinfo$architecture, sys_info[["machine"]]) + # https://docs.rs/os_info/latest/os_info/enum.Type.html + if (sys_info[["sysname"]] == "Darwin") { + expect_true(osinfo$os_type == "Mac OS") + expect_true(osinfo$os == "macos") + } + if (sys_info[["sysname"]] == "linux") { + # this might not hold, but at least on our aws AMI see + # a version of "#18~22.04.1-Ubuntu SMP Wed Jan 10 22:54:16 UTC 2024" + # so the fact that osinfo$os_type is Ubuntu should match + expect_true(grepl(x = sys_info$version, osinfo$os_type, fixed = TRUE)) + expect_true(osinfo$os == "linux") + } +})