-
-
Notifications
You must be signed in to change notification settings - Fork 77
Migrate current tests to Test2 #702
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Squashed commits after messing up the rebase onto the latest develop branch. Recreated and these are the commit messages rescued from that. tableau.t PITA! The circular references in MathObjects made the deep comparisons impossible, so all MathObjects were stringified for comparisons. WARN and DEBUG message sub redefinitions were removed. A "validator" and a stringify sub were added to get around some of the comparison issues. Organized into subtests. math_objects_basics.t Convert `throws_ok` to the like/dies construct and the tests pass. Arranged sections in subtests Three test files migrated from Test::More to Test2 without modification (other than moving the environment setup from the script to Test::PG) This expands on the original t/README.md on the details of testing. t/context Minor changes to migrate tests in t/context from Test::More to Test2 There were few tests in these files. toltype_digits.t organized into subtests by topic Use the Test::PG environment with Test2 Find that the original test produced unexpected results and the tests that expose the incorrect behaviour have been wrapped in a TODO block Added unit tests for Units.pm Tests to validate the correctness of openwebwork#677 Unit tests for Units.pm electron volts Tests for parserNumberWithUnits.pl with basic energy conversions Adding a Test::PG module in t/lib/ to take the place of t/build_PG_envir.pl
Convert math_objects/factorial.t to using the Test2 framework Update the t/README.md to the new usage of Test2 and the boilerplate Test::PG module removed the execute permission from tableau.t
@pstaabp I've removed the check for PG-2.17 in t/units/electron_volts.t, updated t/README.md and your new test t/math_objects/factorial.t to use Test2. The whole test suite is now consistent and mostly organized. The only things that I can't seem to fix are the repeated calls to |
@duffee Now that 2.17 is official, we'll take a look at this for develop. I'll see if I can figure out the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This pull request needs some work. See my comments.
All tests in t/macros pass on the develop branch, but many are failing with this pull request. That will also need to be fixed before this can be merged.
|
||
|
||
# Unit Tests | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am seeing a couple of markdown lint errors here. First, no multiple blank lines, and second, multiple top level headings in the same file.
|
||
|
||
# Integration tests | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same errors here as before.
|
||
|
||
# Test Dependencies |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And again.
|
||
package main; | ||
# should I "use" Parser Value Parser::Legacy here instead? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Delete this comment. It is certainly not in the correct place in the code, and it not clear what this comment means.
The reason for the module is that There Is More Than One Way To Do It | ||
and people develop different styles. This is my coding style. | ||
Also we learn the underlying structures better by re-inventing the wheel. | ||
We just try to make a better wheel, but success is not guaranteed. | ||
|
||
This module strives for elegance in reducing boiler plate in test files, | ||
a minimum of duplicated code and adheres to the principle of least surprise | ||
by locating modules below the C<t/lib> directory. | ||
It does not make a decent cup of tea. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please delete these extraneous comments in the POD. Please do not use the first person in comments and please do not comment on "your coding style". POD should be informative as to what the module does and how to use it. It is not a narrative.
"There Is More Than One Way To Do It" and there are lots of incorrect ways to do it. The old perl slogan is hackish nowadays.
use lib "$main::pg_dir/lib"; | ||
|
||
require("$main::pg_dir/t/build_PG_envir.pl"); | ||
To test the reduction of fractions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please reword this as something like
Fraction context tests
I know the only test in here was labeled as testing reduce fractions. However, not only is that not what it is testing (it is testing that fractions with different representations are equal -- take note @pstaabp), but in the future this will have more tests that test things with fractions other than just reduction (maybe actually one of those too!).
Also, the first header in the POD should be head1.
|
||
# The following needs to include at the top of any testing down to END OF TOP_MATERIAL. | ||
To test for tolerances |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At least remove "To" from the beginning of this. Make it say just "Test tolerances". Either make it a proper statement or make it a complete sentence. "To test for tolerances" do what?
We test the basic functionality of the NumberWithUnits parser, | ||
F<macros/parserNumberWithUnits.pl>, to give us faith | ||
that the parser and its methods are working. | ||
Other test files will probe deeper into specific use cases of | ||
the NumberWithUnits macro and the L<Units> module. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove "we". Pronoun usage in POD and comments is bad. It can all be said without "we" and "I" and "you", and said much better. For example, reword this as
Test the basic functionality of the NumberWithUnits parser F<...>, to demonstrate that the parser and its methods are working.
No need to reference other test files, and what they will do. You don't know that is true yet.
=head3 Setup | ||
|
||
All the boilerplate code is loaded with Test::PG and assume that people run | ||
it from the root directory with C<prove -l>. | ||
Load your base modules before loading the macros which depend on them | ||
and set the Context, if appropriate. | ||
|
||
See the example in the documentation of L<Test::PG> | ||
|
||
perldoc t/lib/Test/PG.pm |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove this section. There is no need to explain how to use the Test::PG module in every test file. This explanation should be in none of the test files, otherwise it will be copied and will end up in many of them. It is the purpose of the POD in the Test::PG file to explain this.
degC => 0, degF => 0, degK => 0, | ||
}, | ||
isValue => T(), | ||
context => check_isa 'Parser::Context', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a syntax error here. Parentheses are needed around 'Parser::Context' in this situation as follows:
context => check_isa 'Parser::Context', | |
context => check_isa('Parser::Context'), |
Even without the syntax error this test is failing. It needs to be fixed.
ok($A == $B, 'test zeroLevel tolerance with ok'); | ||
|
||
my $real_object = object { | ||
prop isa => 'Value::Real'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realized that the reason some of these tests are failing is because you used isa
. isa
is not in the version of Test2::Suite that is included in the Ubuntu repositories (version 0.000129).
In any case, this should be using blessed
and not isa
as that is a more specific and accurate test (and is in version 0.000129). isa
only tells you if the given object is an instance of the given class (any class derived from the given class will pass the test). However, blessed
tells you more. It tells you that the object is specifically blessed as that class, not just derived from.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After looking at this closer I see that the lib/Test/PG.pm module that was added here should be dropped, and the method in build_PG_envir.pl should be used instead. The problem is that lib/Test/PG.pm module is not a proper module, and is a hack. The file declares the Test::PG package, and then improperly switches to the main namespace without actually defining anything that is worthy of being called a module in the Test::PG namespace.
The build_PG_envir.pl needs some work too, but it is closer to being correct. The main things that it does incorrectly is that it uses require
to load PG.pl
and the tests use require
to load it. Both of those should be done with do
. There are some other details that should be fixed with it as well though.
I have a branch built on top of #709 that does everything I have mentioned here, and gets the tests into order.
add_fundamental_unit add_unit string TeX / ], | ||
'Can we NumberWithUnits'; | ||
|
||
ok my $evaluator = $joule->cmp($Nm), 'Get an AnswerEvaluator'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is another problem here. The cmp
method does not take a single argument like this. It only takes hash key value pairs. I think you might be confusing the cmp
method with the evaluate
method of the AnwerHash class.
Closed in favor of #726 |
Squashed commits after messing up the rebase onto the latest develop branch for #692 .
Recreated the PR and these are the commit messages rescued from the original branch.
tableau.t
PITA! The circular references in MathObjects made
the deep comparisons impossible, so all MathObjects
were stringified for comparisons.
math_objects_basics.t
Convert
throws_ok
to the like/dies constructand the tests pass.
Arranged sections in subtests
Three test files migrated from Test::More to Test2 without modification
(other than moving the environment setup from the script to Test::PG)
This expands on the original t/README.md on the details of testing.
t/context
Minor changes to migrate tests in t/context from Test::More to Test2
There were few tests in these files.
Added unit tests for Units.pm
Tests to validate the correctness of #677
Unit tests for Units.pm electron volts
Tests for parserNumberWithUnits.pl with basic energy conversions