Skip to content

Commit b7ad22a

Browse files
committed
Begin unit testing effort
Begin unit testing effort. This required changes to much of the code to make it easier to test. Some parts were also updated to try and improve API consistency.
1 parent 9a0442e commit b7ad22a

File tree

14 files changed

+907
-90
lines changed

14 files changed

+907
-90
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ subprojects/clap-[0-9]*
77
subprojects/clap_builder-[0-9]*
88
subprojects/clap_lex-[0-9]*
99
subprojects/ignore-result-[0-9]*
10+
subprojects/indoc-[0-9]*
1011
subprojects/io-lifetimes-[0-9]*
1112
subprojects/itoa-[0-9]*
1213
subprojects/libc-[0-9]*
@@ -21,3 +22,4 @@ subprojects/serde_json-[0-9]*
2122
subprojects/syn-[0-9]*
2223
subprojects/terminal_size-[0-9]*
2324
subprojects/unicode-ident-[0-9]*
25+
subprojects/unindent-[0-9]*

meson.build

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ project(
22
'refivar',
33
'rust',
44
version: '0.1',
5-
meson_version: '>= 1.1.0',
5+
meson_version: '>= 1.2.0',
66
default_options: [
77
'warning_level=3',
88
'rust_std=2021'
@@ -13,14 +13,15 @@ fs = import('fs')
1313
rust = import('rust')
1414

1515
rustc = meson.get_compiler('rust')
16-
if rustc.version().version_compare('<1.69')
17-
error('rustc 1.69 required. Found ' + rustc.version())
16+
if rustc.version().version_compare('<1.70')
17+
error('rustc 1.70 required. Found ' + rustc.version())
1818
endif
1919

2020
clap_rs_dep = dependency('clap-rs', version: '>=4.1.13')
2121
ignore_result_rs_dep = dependency('ignore-result-rs', version: '>=0.2.0')
22-
serde_rs_dep = dependency('serde-rs', version: '>=1.0.160')
22+
indoc_rs_dep = dependency('indoc-rs', version: '>=2.0.3')
2323
serde_json_rs_dep = dependency('serde_json-rs', version: '>=1.0.96')
24+
serde_rs_dep = dependency('serde-rs', version: '>=1.0.160')
2425

2526
fqDataDir = get_option('prefix') / get_option('datadir') / 'refivar'
2627

@@ -84,8 +85,9 @@ lib_refivar = static_library(
8485
),
8586
rust_crate_type: 'lib',
8687
dependencies: [
88+
indoc_rs_dep,
8789
serde_json_rs_dep,
88-
serde_rs_dep
90+
serde_rs_dep,
8991
],
9092
install: false,
9193
)
@@ -102,10 +104,10 @@ executable(
102104
dependencies: [
103105
clap_rs_dep,
104106
ignore_result_rs_dep,
107+
serde_json_rs_dep,
105108
serde_rs_dep,
106-
serde_json_rs_dep
107109
],
108110
install: true
109111
)
110112

111-
rust.test('unit tests', lib_refivar)
113+
rust.test('unit tests', lib_refivar, rust_args:[])

src/bin/efivar.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ fn create_parser() -> clap::Command {
112112
}
113113

114114
fn list_variables(_parser_args: clap::ArgMatches) -> ExitCode {
115-
let mut efivar_fs_variables: efivar::efivarfs::EfiVariables = Default::default();
115+
let mut efivar_fs_variables: efivar::efivarfs::EfiVariables =
116+
efivar::efivarfs::EfiVariables::new();
116117

117118
match efivar_fs_variables.list() {
118119
Ok(variables) => {
@@ -122,7 +123,8 @@ fn list_variables(_parser_args: clap::ArgMatches) -> ExitCode {
122123
return std::process::ExitCode::from(0);
123124
}
124125
Err(_) => {
125-
let efivar_variables: efivar::efivar::EfiVariables = Default::default();
126+
let efivar_variables: efivar::efivar::EfiVariables =
127+
efivar::efivar::EfiVariables::new();
126128
match efivar_variables.list() {
127129
Ok(variables) => {
128130
for v in variables {
@@ -142,7 +144,8 @@ fn list_variables(_parser_args: clap::ArgMatches) -> ExitCode {
142144
fn print_variable(parser_args: clap::ArgMatches, print_mode: efivar::types::PrintMode) -> ExitCode {
143145
match parser_args.get_one::<String>("name") {
144146
Some(name) => {
145-
let efivar_fs_variables: efivar::efivarfs::EfiVariables = Default::default();
147+
let efivar_fs_variables: efivar::efivarfs::EfiVariables =
148+
efivar::efivarfs::EfiVariables::new();
146149
match efivar_fs_variables.get_variable(name) {
147150
Ok(var) => {
148151
match print_mode {
@@ -152,7 +155,8 @@ fn print_variable(parser_args: clap::ArgMatches, print_mode: efivar::types::Prin
152155
return std::process::ExitCode::from(0);
153156
}
154157
Err(_) => {
155-
let efivar_variables: efivar::efivar::EfiVariables = Default::default();
158+
let efivar_variables: efivar::efivar::EfiVariables =
159+
efivar::efivar::EfiVariables::new();
156160
match efivar_variables.get_variable(name) {
157161
Ok(var) => {
158162
match print_mode {

src/lib/efivar/efi_variable_attributes.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
use crate::types::EfiVariableAttribute;
22
use std::collections::HashSet;
33

4-
pub static NON_VOLATILE: EfiVariableAttribute = EfiVariableAttribute::init("Non-Volatile", 0x1);
4+
pub static NON_VOLATILE: EfiVariableAttribute = EfiVariableAttribute::new("Non-Volatile", 0x1);
55
pub static BOOTSERVICE_ACCESS: EfiVariableAttribute =
6-
EfiVariableAttribute::init("Boot Service Access", 0x2);
6+
EfiVariableAttribute::new("Boot Service Access", 0x2);
77
pub static RUNTIME_ACCESS: EfiVariableAttribute =
8-
EfiVariableAttribute::init("Runtime Service Access", 0x4);
8+
EfiVariableAttribute::new("Runtime Service Access", 0x4);
99
pub static HARDWARE_ERROR_RECORD: EfiVariableAttribute =
10-
EfiVariableAttribute::init("Hardware Error Record", 0x8);
10+
EfiVariableAttribute::new("Hardware Error Record", 0x8);
1111
pub static AUTHENTICATED_WRITE_ACCESS: EfiVariableAttribute =
12-
EfiVariableAttribute::init("Authenticated Write Access", 0x10);
12+
EfiVariableAttribute::new("Authenticated Write Access", 0x10);
1313
pub static TIME_BASED_AUTHENTICATED_WRITE_ACCESS: EfiVariableAttribute =
14-
EfiVariableAttribute::init("Time-Based Authenticated Write Access", 0x20);
15-
pub static APPEND_WRITE: EfiVariableAttribute = EfiVariableAttribute::init("Append Write", 0x40);
14+
EfiVariableAttribute::new("Time-Based Authenticated Write Access", 0x20);
15+
pub static APPEND_WRITE: EfiVariableAttribute = EfiVariableAttribute::new("Append Write", 0x40);
1616
pub static ENHANCED_AUTHENTICATED_ACCESS: EfiVariableAttribute =
17-
EfiVariableAttribute::init("Enhanced Authenticated Access", 0x80);
17+
EfiVariableAttribute::new("Enhanced Authenticated Access", 0x80);
1818

1919
pub static EFI_VARIABLE_ATTRIBUTES: &'static [&EfiVariableAttribute] = &[
2020
&NON_VOLATILE,

0 commit comments

Comments
 (0)