Skip to content

Commit fa31d8c

Browse files
committed
Fix the unit test that attempts to construct a NumberWithUnits with no number.
1 parent 9b3f74c commit fa31d8c

File tree

2 files changed

+3
-7
lines changed

2 files changed

+3
-7
lines changed

lib/Parser/Legacy/NumberWithUnits.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ sub makeValue {
363363
my $value = shift;
364364
my %options = (context => $self->context, @_);
365365
my $num = Value::makeValue($value, %options);
366-
return bless $num, 'Parser::Legacy::FormulaWithUnits' if $num->classMatch('Formula');
366+
return bless $num, 'Parser::Legacy::FormulaWithUnits' if defined $num && $num->classMatch('Formula');
367367
Value::Error("A number with units must be a constant, not %s", lc(Value::showClass($num)))
368368
unless Value::isReal($num);
369369
bless $num, $options{class};

t/units/basic_parser.t

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,8 @@ subtest 'Test error handling' => sub {
9595
qr/Unrecognizable unit: \|$fake\|/,
9696
"No unit '$fake' defined in Units file"
9797
);
98-
like(dies { NumberWithUnits(1) }, qr/You must provide units for your number/, 'No unit given');
99-
like(
100-
dies { NumberWithUnits('J') },
101-
qr/You must provide units for your number/,
102-
'No value given, wants 2 arguments'
103-
);
98+
like(dies { NumberWithUnits(1) }, qr/You must provide units for your number/, 'No unit given');
99+
like(dies { NumberWithUnits('J') }, qr/A number with units must be a constant, not ''/, 'No value given');
104100
};
105101

106102
subtest 'Check parsing of arguments' => sub {

0 commit comments

Comments
 (0)