Skip to content

Commit

Permalink
add some additional os information and basic test
Browse files Browse the repository at this point in the history
  • Loading branch information
dpastoor committed May 26, 2024
1 parent afb70fc commit 1dc6a23
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 1 deletion.
3 changes: 3 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 5 additions & 0 deletions osinfo.Rproj
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion src/rust/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use extendr_api::prelude::*;
use std::env;

#[derive(Debug, PartialEq, IntoDataFrameRow)]
struct OsInfo {
Expand All @@ -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,
)
}

Expand Down
12 changes: 12 additions & 0 deletions tests/testthat.R
Original file line number Diff line number Diff line change
@@ -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")
18 changes: 18 additions & 0 deletions tests/testthat/test-os-info.R
Original file line number Diff line number Diff line change
@@ -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")
}
})

0 comments on commit 1dc6a23

Please sign in to comment.