Disallow using set outside of tests, minor fixes

This commit is contained in:
Henrik Hørlück Berg 2023-07-10 02:56:57 +02:00 committed by Peter Ammon
parent 726819e8ee
commit f1cd43d58b
2 changed files with 9 additions and 10 deletions

View file

@ -180,10 +180,10 @@ const LONG_OPTIONS: &[woption] = &[
fn print_features(streams: &mut io_streams_t) {
// TODO: move this to features.rs
let mut max_len = i32::MIN;
for md in &features::METADATA {
for md in features::METADATA {
max_len = max_len.max(md.name.len() as i32);
}
for md in &features::METADATA {
for md in features::METADATA {
let set = if feature_test(md.flag) {
L!("on")
} else {
@ -433,7 +433,7 @@ pub fn status(
}
use TestFeatureRetVal::*;
let mut retval = Some(TEST_FEATURE_NOT_RECOGNIZED as c_int);
for md in &features::METADATA {
for md in features::METADATA {
if md.name == args[0] {
retval = match feature_test(md.flag) {
true => Some(TEST_FEATURE_ON as c_int),

View file

@ -71,7 +71,7 @@ pub struct FeatureMetadata {
/// The metadata, indexed by flag.
#[widestrs]
pub const METADATA: [FeatureMetadata; 4] = [
pub const METADATA: &[FeatureMetadata] = &[
FeatureMetadata {
flag: FeatureFlag::stderr_nocaret,
name: "stderr-nocaret"L,
@ -114,12 +114,11 @@ pub fn test(flag: FeatureFlag) -> bool {
FEATURES.test(flag)
}
pub fn feature_test(flag: FeatureFlag) -> bool {
test(flag)
}
pub use test as feature_test;
/// Set a flag.
pub fn set(flag: FeatureFlag, value: bool) {
#[cfg(any(test, feature = "fish-ffi-tests"))]
pub(self) fn set(flag: FeatureFlag, value: bool) {
FEATURES.set(flag, value);
}
@ -182,7 +181,7 @@ impl Features {
self.set(md.flag, value);
}
} else {
for md in &METADATA {
for md in METADATA {
if md.groups == name || name == "all"L {
if !md.read_only {
self.set(md.flag, value);
@ -205,7 +204,7 @@ fn test_feature_flags() {
// Ensure every metadata is represented once.
let mut counts: [usize; METADATA.len()] = [0; METADATA.len()];
for md in &METADATA {
for md in METADATA {
counts[md.flag.repr as usize] += 1;
}
for count in counts {