@@ -693,7 +693,7 @@ fn expand_variables_cmake(
693
693
}
694
694
695
695
const key = contents [curr + 1 .. close_pos ];
696
- const value = values .get (key ) orelse return error . MissingValue ;
696
+ const value = values .get (key ) orelse .undef ;
697
697
const missing = contents [source_offset .. curr ];
698
698
try result .appendSlice (missing );
699
699
switch (value ) {
@@ -748,10 +748,7 @@ fn expand_variables_cmake(
748
748
749
749
const key_start = open_pos .target + open_var .len ;
750
750
const key = result .items [key_start .. ];
751
- if (key .len == 0 ) {
752
- return error .MissingKey ;
753
- }
754
- const value = values .get (key ) orelse return error .MissingValue ;
751
+ const value = values .get (key ) orelse .undef ;
755
752
result .shrinkRetainingCapacity (result .items .len - key .len - open_var .len );
756
753
switch (value ) {
757
754
.undef , .defined = > {},
@@ -952,8 +949,8 @@ test "expand_variables_cmake simple cases" {
952
949
// line with misc content is preserved
953
950
try testReplaceVariablesCMake (allocator , "no substitution" , "no substitution" , values );
954
951
955
- // empty ${} wrapper leads to an error
956
- try std . testing . expectError ( error . MissingKey , testReplaceVariablesCMake (allocator , "${}" , "" , values ) );
952
+ // empty ${} wrapper is removed
953
+ try testReplaceVariablesCMake (allocator , "${}" , "" , values );
957
954
958
955
// empty @ sigils are preserved
959
956
try testReplaceVariablesCMake (allocator , "@" , "@" , values );
@@ -1016,9 +1013,9 @@ test "expand_variables_cmake simple cases" {
1016
1013
try testReplaceVariablesCMake (allocator , "undef@" , "undef@" , values );
1017
1014
try testReplaceVariablesCMake (allocator , "undef}" , "undef}" , values );
1018
1015
1019
- // unknown key leads to an error
1020
- try std . testing . expectError ( error . MissingValue , testReplaceVariablesCMake (allocator , "@bad@" , "" , values ) );
1021
- try std . testing . expectError ( error . MissingValue , testReplaceVariablesCMake (allocator , "${bad}" , "" , values ) );
1016
+ // unknown key is removed
1017
+ try testReplaceVariablesCMake (allocator , "@bad@" , "" , values );
1018
+ try testReplaceVariablesCMake (allocator , "${bad}" , "" , values );
1022
1019
}
1023
1020
1024
1021
test "expand_variables_cmake edge cases" {
@@ -1063,17 +1060,17 @@ test "expand_variables_cmake edge cases" {
1063
1060
try testReplaceVariablesCMake (allocator , "@dollar@{@string@}" , "${text}" , values );
1064
1061
1065
1062
// when expanded variables contain invalid characters, they prevent further expansion
1066
- try std . testing . expectError ( error . MissingValue , testReplaceVariablesCMake (allocator , "${${string_var}}" , "" , values ) );
1067
- try std . testing . expectError ( error . MissingValue , testReplaceVariablesCMake (allocator , "${@string_var@}" , "" , values ) );
1063
+ try testReplaceVariablesCMake (allocator , "${${string_var}}" , "" , values );
1064
+ try testReplaceVariablesCMake (allocator , "${@string_var@}" , "" , values );
1068
1065
1069
1066
// nested expanded variables are expanded from the inside out
1070
1067
try testReplaceVariablesCMake (allocator , "${string${underscore}proxy}" , "string" , values );
1071
1068
try testReplaceVariablesCMake (allocator , "${string@underscore@proxy}" , "string" , values );
1072
1069
1073
1070
// nested vars are only expanded when ${} is closed
1074
- try std . testing . expectError ( error . MissingValue , testReplaceVariablesCMake (allocator , "@nest@underscore@proxy@" , "" , values ) );
1071
+ try testReplaceVariablesCMake (allocator , "@nest@underscore@proxy@" , "underscore " , values );
1075
1072
try testReplaceVariablesCMake (allocator , "${nest${underscore}proxy}" , "nest_underscore_proxy" , values );
1076
- try std . testing . expectError ( error . MissingValue , testReplaceVariablesCMake (allocator , "@nest@@nest_underscore@underscore@proxy@@proxy@" , "" , values ) );
1073
+ try testReplaceVariablesCMake (allocator , "@nest@@nest_underscore@underscore@proxy@@proxy@" , "underscore " , values );
1077
1074
try testReplaceVariablesCMake (allocator , "${nest${${nest_underscore${underscore}proxy}}proxy}" , "nest_underscore_proxy" , values );
1078
1075
1079
1076
// invalid characters lead to an error
@@ -1099,5 +1096,5 @@ test "expand_variables_cmake escaped characters" {
1099
1096
try testReplaceVariablesCMake (allocator , "$\\ {string}" , "$\\ {string}" , values );
1100
1097
1101
1098
// backslash is skipped when checking for invalid characters, yet it mangles the key
1102
- try std . testing . expectError ( error . MissingValue , testReplaceVariablesCMake (allocator , "${string\\ }" , "" , values ) );
1099
+ try testReplaceVariablesCMake (allocator , "${string\\ }" , "" , values );
1103
1100
}
0 commit comments