Skip to content

Commit d43156f

Browse files
committed
tock-register-interface: make std_unit_tests feature additive
As documented in the Cargo reference, features of a crate should always be additive due to the way feature unification works across transitive dependencies. This changes the `no_std_unit_tests` feature to a `std_unit_tests` feature, which is enabled by default. Signed-off-by: Leon Schuermann <leon@is.currently.online>
1 parent cb5becd commit d43156f

File tree

4 files changed

+13
-8
lines changed

4 files changed

+13
-8
lines changed

libraries/tock-register-interface/Cargo.toml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@ edition = "2018"
1515
travis-ci = { repository = "tock/tock", branch = "master" }
1616

1717
[features]
18-
default = [ "register_types" ]
18+
default = [ "register_types", "std_unit_tests" ]
1919

2020
# Include actual register types (except LocalRegisterCopy). Disabling
2121
# the feature makes this an interface-only library and removes all
2222
# usage of unsafe code
2323
register_types = []
2424

25-
no_std_unit_tests = []
25+
# Feature flag to enable generation of unit tests for the
26+
# registers. Enabling this may break compilation in
27+
# `custom-test-frameworks` environments.
28+
std_unit_tests = []

libraries/tock-register-interface/README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,15 @@ padding are consistent with the actual fields in the struct, and that alignment
9595
is correct.
9696

9797
Since those tests would break compilation in `custom-test-frameworks`
98-
environments, it is possible to opt out of the test generation. To do so, add
99-
the following cargo feature:
98+
environments, it is possible to opt out of the test generation. To do
99+
so, disable the default feature set containing the `std_unit_tests`
100+
feature:
100101

101102
```toml
102103
[dependencies.tock-registers]
103104
version = "0.4.x"
104-
features = ["no_std_unit_tests"]
105+
default-features = false
106+
features = ["register_types"]
105107
```
106108

107109
By default, the visibility of the generated structs and fields is private. You

libraries/tock-register-interface/src/fields.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ macro_rules! register_bitfields {
452452
}
453453
}
454454

455-
#[cfg(not(feature = "no_std_unit_tests"))]
455+
#[cfg(feature = "std_unit_tests")]
456456
#[cfg(test)]
457457
mod tests {
458458
#[derive(Debug, PartialEq, Eq)]

libraries/tock-register-interface/src/macros.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ macro_rules! test_fields {
195195
};
196196
}
197197

198-
#[cfg(not(feature = "no_std_unit_tests"))]
198+
#[cfg(feature = "std_unit_tests")]
199199
#[macro_export]
200200
macro_rules! register_structs {
201201
{
@@ -224,7 +224,7 @@ macro_rules! register_structs {
224224
};
225225
}
226226

227-
#[cfg(feature = "no_std_unit_tests")]
227+
#[cfg(not(feature = "std_unit_tests"))]
228228
#[macro_export]
229229
macro_rules! register_structs {
230230
{

0 commit comments

Comments
 (0)