Skip to content

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

Closed
wants to merge 2 commits into from

Conversation

duffee
Copy link
Contributor

@duffee duffee commented Jul 22, 2022

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.

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 #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

duffee added 2 commits July 21, 2022 22:35
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
@duffee
Copy link
Contributor Author

duffee commented Jul 22, 2022

@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 check_score in units/basic_parser.t and cos(90) the todo block at the end of contexts/trig_degrees.t. Any help would be welcome.

@pstaabp
Copy link
Member

pstaabp commented Jul 22, 2022

@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 check_score issue.

Copy link
Member

@drgrice1 drgrice1 left a 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.

Comment on lines +20 to +23


# Unit Tests

Copy link
Member

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.

Comment on lines +90 to +93


# Integration tests

Copy link
Member

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.

Comment on lines +100 to +102


# Test Dependencies
Copy link
Member

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?
Copy link
Member

@drgrice1 drgrice1 Aug 12, 2022

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.

Comment on lines +22 to +30
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.
Copy link
Member

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
Copy link
Member

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
Copy link
Member

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?

Comment on lines +16 to +20
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.
Copy link
Member

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.

Comment on lines +32 to +41
=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
Copy link
Member

@drgrice1 drgrice1 Aug 12, 2022

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',
Copy link
Member

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:

Suggested change
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';
Copy link
Member

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.

Copy link
Member

@drgrice1 drgrice1 left a 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';
Copy link
Member

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.

@drdrew42
Copy link
Member

Closed in favor of #726

@drdrew42 drdrew42 closed this Oct 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants