I have an existing function that checks if an input variable is defined, and returns true if it is equal to another variable, and returns false otherwise:
sub isVar1Valid {
my ($self, $var1) = @_;
my $var2 = "someValue";
return $var1 && $var1 eq $var2;
}
I'm writing unit tests for this function, and the expected output I'm looking for is false. In my unit test, I'm actually testing for 0. However, my test is failing because the above method is returning ' ', and that is not equal to 0.
My unit test looks something like.
my $actualOutput = isVar1Valid($input);
is($actualOutput, 0);
Should I be testing for ' ' as an expected output in my unit test instead? Or should I be returning 0 in my main function instead?
This is my first time working with Perl, so any guidance is appreciated.
''), not a single space (as produced by' '). The empty string is false, but a space is true.'', which was the value of$var1for some test cases.