diff --git a/docs/file_format/file.md b/docs/file_format/file.md index 6ae18e0..c847cde 100644 --- a/docs/file_format/file.md +++ b/docs/file_format/file.md @@ -331,7 +331,7 @@ segments: ### Valid values -A list of two-tuples of strings. +A non-empty list of two-tuples of strings. ## `include_if_all` @@ -363,7 +363,7 @@ segments: ### Valid values -A list of two-tuples of strings. +A non-empty list of two-tuples of strings. ## `exclude_if_any` @@ -395,7 +395,7 @@ segments: ### Valid values -A list of two-tuples of strings. +A non-empty list of two-tuples of strings. ## `exclude_if_all` @@ -427,4 +427,4 @@ segments: ### Valid values -A list of two-tuples of strings. +A non-empty list of two-tuples of strings. diff --git a/slinky/src/absent_nullable.rs b/slinky/src/absent_nullable.rs index 89d5590..b351bff 100644 --- a/slinky/src/absent_nullable.rs +++ b/slinky/src/absent_nullable.rs @@ -51,6 +51,28 @@ impl AbsentNullable { } } + pub fn get_non_null_not_empty(self, name: &str, default: F) -> Result + where + F: FnOnce() -> T, + T: Default + PartialEq, + { + match self { + AbsentNullable::Absent => Ok(default()), + AbsentNullable::Null => Err(SlinkyError::NullValueOnNonNull { + name: name.to_string(), + }), + AbsentNullable::Value(v) => { + if v == T::default() { + Err(SlinkyError::EmptyValue { + name: name.to_string(), + }) + } else { + Ok(v) + } + } + } + } + pub fn get_non_null_no_default(self, name: &str) -> Result, SlinkyError> { match self { AbsentNullable::Absent => Ok(None), diff --git a/slinky/src/file_info.rs b/slinky/src/file_info.rs index 4798b32..704a00e 100644 --- a/slinky/src/file_info.rs +++ b/slinky/src/file_info.rs @@ -252,16 +252,16 @@ impl FileInfoSerial { let include_if_any = self .include_if_any - .get_non_null("include_if_any", Vec::new)?; + .get_non_null_not_empty("include_if_any", Vec::new)?; let include_if_all = self .include_if_all - .get_non_null("include_if_all", Vec::new)?; + .get_non_null_not_empty("include_if_all", Vec::new)?; let exclude_if_any = self .exclude_if_any - .get_non_null("exclude_if_any", Vec::new)?; + .get_non_null_not_empty("exclude_if_any", Vec::new)?; let exclude_if_all = self .exclude_if_all - .get_non_null("exclude_if_all", Vec::new)?; + .get_non_null_not_empty("exclude_if_all", Vec::new)?; Ok(FileInfo { path, diff --git a/slinky/src/segment.rs b/slinky/src/segment.rs index 7698422..d8503b6 100644 --- a/slinky/src/segment.rs +++ b/slinky/src/segment.rs @@ -233,16 +233,16 @@ impl SegmentSerial { let include_if_any = self .include_if_any - .get_non_null("include_if_any", Vec::new)?; + .get_non_null_not_empty("include_if_any", Vec::new)?; let include_if_all = self .include_if_all - .get_non_null("include_if_all", Vec::new)?; + .get_non_null_not_empty("include_if_all", Vec::new)?; let exclude_if_any = self .exclude_if_any - .get_non_null("exclude_if_any", Vec::new)?; + .get_non_null_not_empty("exclude_if_any", Vec::new)?; let exclude_if_all = self .exclude_if_all - .get_non_null("exclude_if_all", Vec::new)?; + .get_non_null_not_empty("exclude_if_all", Vec::new)?; let alloc_sections = self .alloc_sections diff --git a/slinky/src/symbol_assignment.rs b/slinky/src/symbol_assignment.rs index 2ec7d9a..7276f74 100644 --- a/slinky/src/symbol_assignment.rs +++ b/slinky/src/symbol_assignment.rs @@ -68,16 +68,16 @@ impl SymbolAssignmentSerial { let include_if_any = self .include_if_any - .get_non_null("include_if_any", Vec::new)?; + .get_non_null_not_empty("include_if_any", Vec::new)?; let include_if_all = self .include_if_all - .get_non_null("include_if_all", Vec::new)?; + .get_non_null_not_empty("include_if_all", Vec::new)?; let exclude_if_any = self .exclude_if_any - .get_non_null("exclude_if_any", Vec::new)?; + .get_non_null_not_empty("exclude_if_any", Vec::new)?; let exclude_if_all = self .exclude_if_all - .get_non_null("exclude_if_all", Vec::new)?; + .get_non_null_not_empty("exclude_if_all", Vec::new)?; Ok(SymbolAssignment { name, diff --git a/tests/panics/file_exclude_if_all_empty.yaml b/tests/panics/file_exclude_if_all_empty.yaml new file mode 100644 index 0000000..53e8b83 --- /dev/null +++ b/tests/panics/file_exclude_if_all_empty.yaml @@ -0,0 +1,4 @@ +segments: + - name: main + files: + - { path: main.o, exclude_if_all: [] } diff --git a/tests/panics/file_exclude_if_any_empty.yaml b/tests/panics/file_exclude_if_any_empty.yaml new file mode 100644 index 0000000..47bd5f7 --- /dev/null +++ b/tests/panics/file_exclude_if_any_empty.yaml @@ -0,0 +1,4 @@ +segments: + - name: main + files: + - { path: main.o, exclude_if_any: [] } diff --git a/tests/panics/file_include_if_all_empty.yaml b/tests/panics/file_include_if_all_empty.yaml new file mode 100644 index 0000000..d50954c --- /dev/null +++ b/tests/panics/file_include_if_all_empty.yaml @@ -0,0 +1,4 @@ +segments: + - name: main + files: + - { path: main.o, include_if_all: [] } diff --git a/tests/panics/file_include_if_any_empty.yaml b/tests/panics/file_include_if_any_empty.yaml new file mode 100644 index 0000000..531b2ae --- /dev/null +++ b/tests/panics/file_include_if_any_empty.yaml @@ -0,0 +1,4 @@ +segments: + - name: main + files: + - { path: main.o, include_if_any: [] } diff --git a/tests/panics/segment_exclude_if_all_empty.yaml b/tests/panics/segment_exclude_if_all_empty.yaml new file mode 100644 index 0000000..ea0d3ea --- /dev/null +++ b/tests/panics/segment_exclude_if_all_empty.yaml @@ -0,0 +1,5 @@ +segments: + - name: main + exclude_if_all: [] + files: + - { path: main.o } diff --git a/tests/panics/segment_exclude_if_any_empty.yaml b/tests/panics/segment_exclude_if_any_empty.yaml new file mode 100644 index 0000000..99dea68 --- /dev/null +++ b/tests/panics/segment_exclude_if_any_empty.yaml @@ -0,0 +1,5 @@ +segments: + - name: main + exclude_if_any: [] + files: + - { path: main.o } diff --git a/tests/panics/segment_include_if_all_empty.yaml b/tests/panics/segment_include_if_all_empty.yaml new file mode 100644 index 0000000..c3ea854 --- /dev/null +++ b/tests/panics/segment_include_if_all_empty.yaml @@ -0,0 +1,5 @@ +segments: + - name: main + include_if_all: [] + files: + - { path: main.o } diff --git a/tests/panics/segment_include_if_any_empty.yaml b/tests/panics/segment_include_if_any_empty.yaml new file mode 100644 index 0000000..968e58c --- /dev/null +++ b/tests/panics/segment_include_if_any_empty.yaml @@ -0,0 +1,5 @@ +segments: + - name: main + include_if_any: [] + files: + - { path: main.o } diff --git a/tests/panics/symbol_assignment_exclude_if_all_empty.yaml b/tests/panics/symbol_assignment_exclude_if_all_empty.yaml new file mode 100644 index 0000000..7ce1546 --- /dev/null +++ b/tests/panics/symbol_assignment_exclude_if_all_empty.yaml @@ -0,0 +1,9 @@ +segments: + - name: main + files: + - { path: main.o } + +symbol_assignments: + - name: dummy_test + value: 0x80801234 + exclude_if_all: [] diff --git a/tests/panics/symbol_assignment_exclude_if_any_empty.yaml b/tests/panics/symbol_assignment_exclude_if_any_empty.yaml new file mode 100644 index 0000000..93fc709 --- /dev/null +++ b/tests/panics/symbol_assignment_exclude_if_any_empty.yaml @@ -0,0 +1,9 @@ +segments: + - name: main + files: + - { path: main.o } + +symbol_assignments: + - name: dummy_test + value: 0x80801234 + exclude_if_any: [] diff --git a/tests/panics/symbol_assignment_include_if_all_empty.yaml b/tests/panics/symbol_assignment_include_if_all_empty.yaml new file mode 100644 index 0000000..d9fb8ce --- /dev/null +++ b/tests/panics/symbol_assignment_include_if_all_empty.yaml @@ -0,0 +1,9 @@ +segments: + - name: main + files: + - { path: main.o } + +symbol_assignments: + - name: dummy_test + value: 0x80801234 + include_if_all: [] diff --git a/tests/panics/symbol_assignment_include_if_any_empty.yaml b/tests/panics/symbol_assignment_include_if_any_empty.yaml new file mode 100644 index 0000000..038d582 --- /dev/null +++ b/tests/panics/symbol_assignment_include_if_any_empty.yaml @@ -0,0 +1,9 @@ +segments: + - name: main + files: + - { path: main.o } + +symbol_assignments: + - name: dummy_test + value: 0x80801234 + include_if_any: []