Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^2: [RFC] Module code and POD for CPAN

by Bod (Parson)
on Apr 14, 2021 at 22:36 UTC ( [id://11131301]=note: print w/replies, xml ) Need Help??


in reply to Re: [RFC] Module code and POD for CPAN
in thread [RFC] Module code and POD for CPAN

OK, so I have followed the instructions and used module-starter to create a package directories. I've them edited Makefile.PL and MANIFEST.

gmake test revealed an error under Perl v5.32 which didn't show up in v5.16 where I was testing:

Error: Experimental splice on scalar is now forbidden at C:\Users\use +r\Perl\Business-Stripe-WebCheckout\blib\lib/Business/Stripe/WebChecko +ut.pm line 127, near "1;"
Now corrected changing this line to explicitly dereference the array:
splice $self->{'trolley'}, $i, 1; splice @{$self->{'trolley'}}, $i, 1;
It installs locally with gmake install

Is this a good test result or do I need to be adding in more tests?

C:\Users\user\Perl\Business-Stripe-WebCheckout>gmake test "C:\Strawberry\perl\bin\perl.exe" "-MExtUtils::Command::MM" "-MTest::H +arness" "-e" "undef *Test::Harness::Switches; test_harness(0, 'blib\l +ib', 'blib\arch')" t/*.t t/00-load.t ....... 1/? # Testing Business::Stripe::WebCheckout 0.11, +Perl 5.032001, C:\Strawberry\perl\bin\perl.exe t/00-load.t ....... ok t/manifest.t ...... skipped: Author tests not required for installatio +n t/pod-coverage.t .. skipped: Author tests not required for installatio +n t/pod.t ........... skipped: Author tests not required for installatio +n All tests successful. Files=4, Tests=1, 0 wallclock secs ( 0.06 usr + 0.01 sys = 0.08 CPU +) Result: PASS

But...I am getting an error at the gmake dist stage.

C:\Users\user\Perl\Business-Stripe-WebCheckout>gmake dist "C:\Strawberry\perl\bin\perl.exe" -MExtUtils::Command -e rm_rf -- Busi +ness-Stripe-WebCheckout-0.1_1 "C:\Strawberry\perl\bin\perl.exe" "-MExtUtils::Manifest=manicopy,manir +ead" \ -e "manicopy(maniread(),'Business-Stripe-WebCheckout-0.1_1', ' +best');" mkdir Business-Stripe-WebCheckout-0.1_1 mkdir Business-Stripe-WebCheckout-0.1_1/t mkdir Business-Stripe-WebCheckout-0.1_1/lib mkdir Business-Stripe-WebCheckout-0.1_1/lib/Business mkdir Business-Stripe-WebCheckout-0.1_1/lib/Business/Stripe Generating META.yml Generating META.json tar cvf Business-Stripe-WebCheckout-0.1_1.tar Business-Stripe-WebCheck +out-0.1_1 a Business-Stripe-WebCheckout-0.1_1 a Business-Stripe-WebCheckout-0.1_1/Changes a Business-Stripe-WebCheckout-0.1_1/lib a Business-Stripe-WebCheckout-0.1_1/LICENSE a Business-Stripe-WebCheckout-0.1_1/Makefile.PL a Business-Stripe-WebCheckout-0.1_1/MANIFEST a Business-Stripe-WebCheckout-0.1_1/META.json a Business-Stripe-WebCheckout-0.1_1/META.yml a Business-Stripe-WebCheckout-0.1_1/README a Business-Stripe-WebCheckout-0.1_1/t a Business-Stripe-WebCheckout-0.1_1/t/00-load.t a Business-Stripe-WebCheckout-0.1_1/t/manifest.t a Business-Stripe-WebCheckout-0.1_1/t/pod-coverage.t a Business-Stripe-WebCheckout-0.1_1/t/pod.t a Business-Stripe-WebCheckout-0.1_1/lib/Business a Business-Stripe-WebCheckout-0.1_1/lib/Business/Stripe a Business-Stripe-WebCheckout-0.1_1/lib/Business/Stripe/WebCheckout.pm "C:\Strawberry\perl\bin\perl.exe" -MExtUtils::Command -e rm_rf -- Busi +ness-Stripe-WebCheckout-0.1_1 gzip -9f Business-Stripe-WebCheckout-0.1_1.tar process_begin: CreateProcess(NULL, gzip -9f Business-Stripe-WebCheckou +t-0.1_1.tar, ...) failed. make (e=2): The system cannot find the file specified. gmake: *** [Makefile:612: Business-Stripe-WebCheckout-0.1_1.tar.gz] Er +ror 2
I've check the tar file and everything appears to be in there so I take it the error is packing the tar file into a .gz archive. But I'm not sure what to try next...

Replies are listed 'Best First'.
Re^3: [RFC] Module code and POD for CPAN
by hippo (Bishop) on Apr 14, 2021 at 22:53 UTC
    Is this a good test result or do I need to be adding in more tests?

    Both! It is good in that the stock tests pass but they are only testing for very basic things - have a read of t/00-load.t to see how little it actually does. What you should do next is write your own tests which actually test your code to show that it does what it is supposed to do and that it handles edge cases as intended, etc.

    Also, the skipped: Author tests not required for installation is great for end users but not for you as author. You want to run those yourself so be sure to set the AUTHOR_TESTING environment variable to get them to run for you.


    🦛

      The documentation has now been updated taking into consideration all the feedback people have kindly provided.

      I've gone through the documentation and written several tests for each method. Some time ago I read an article about writing tests and cannot find it now. But the one thing that stood out from it was to start writing tests based on the documentation...so that is about what I have done. However, I cannot see a way to test getting an intent as that requires a valid API key. Something that will not be available to the installation scripts. So I have called the method and checked that the success method returns false. Is there a better way to handle the lack of API key?

      This has generated some more questions:

      There are 30 tests I have created but gmake test says there are 31. Does diag count as a test or does something else account for the discrepancy?

      If plan tests => 31 is included I get the error Parse errors: Plan (1..31) must be at the beginning or end of the TAP output. However, plan tests => 31 was autogenerated. I have to use Test::More tests => 31; to get rid of the error. I cannot find any explanation of the error so what does it actually mean?

      Are there any other glaringly obvious tests that should be included, but that have been left out?

      00-load.t

      Also just to note in case anyone else finds this in future - the environment variable (on Strawberry Perl at least) is RELEASE_TESTING and not AUTHOR_TESTING

        the environment variable (on Strawberry Perl at least) is RELEASE_TESTING and not AUTHOR_TESTING

        These are both useful environment variables and they have subtly different uses.

        AUTHOR_TESTING should be set only by the author (or maintainer). There are any number of reasons to run author-only tests but these might include tests which run against some sample data set or server application to which only the author has access, etc. But they can also be used for simple tests which the users don't care about such as POD coverage, POD spell checks, etc..

        RELEASE_TESTING is for tests run just prior to release. Usually by the author again but these may be the sorts of things that even the author doesn't care about when hacking on the actual code. It is handy for meta-data tests: did you remember to bump the version number, is the Kwalitee OK, etc.

        There is also AUTOMATED_TESTING which allows skipping of anything requiring user interaction - handy for CI and the smoke testers.

        These three along with NONINTERACTIVE_TESTING and EXTENDED_TESTING are explained in the Lancaster Consensus. It is well worth a read through.

        In your case here there is also the important NO_NETWORK_TESTING which, if set, should prohibit anything relying on internet access such as real communications with the Stripe servers.


        🦛

        > Is there a better way to handle the lack of API key?

        Coincidentally, I blogged about mocking when I was improving the tests of Net::Stripe.

        map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
        There are 30 tests I have created but gmake test says there are 31. Does diag count as a test or does something else account for the discrepancy?

        No, diag is not a test, but use_ok is - were you including that in your count?

        If plan tests => 31 is included I get the error Parse errors: Plan (1..31) must be at the beginning or end of the TAP output. However, plan tests => 31 was autogenerated. I have to use Test::More tests => 31; to get rid of the error. I cannot find any explanation of the error so what does it actually mean?

        Again, this is down to use_ok but this time it is because the use_ok is in the BEGIN block and therefore happens before the plan.

        You also have lots of tests like this:

        ok( scalar( $stripe->list_products ) == 3, 'Third product added to Tr +olley' );

        But I would write this instead as:

        is scalar( $stripe->list_products ), 3, 'Third product added to Trolle +y';

        as that will give you better diagnostics if it fails. The ok test should really be used sparingly as all it can test is the truth of its argument. Much better to have something either quantitative or qualitative.

        Also, I wouldn't necessarily put all these in 00-load.t as very few of them are to do with loading. You can have as many separate test scripts as you want and by making each one topic-sensitive you can make each one reasonably self-contained and hopefully more manageable.

        Are there any other glaringly obvious tests that should be included, but that have been left out?

        Too hard to tell without going through your code in detail, but that's why we have Devel::Cover. This will show what you are (and more importantly are not) testing.

        However, I cannot see a way to test getting an intent as that requires a valid API key. Something that will not be available to the installation scripts. So I have called the method and checked that the success method returns false. Is there a better way to handle the lack of API key?

        You have 2 options here. Firstly you can make the key available to the installation scripts via the environment. This is good because it really tests the interaction with the remote service but may be bad (for some services) because it may require an actual transaction to occur to test your code. Hopefully any remote service you have to deal with will have a testbed.

        The other option is mocking. Conversely to the previous option, this is good because it does not require a valid key nor an actual interaction with the remote service but is bad (for you as maintainer) because you will have to work to keep it in step with any interface changes made by the remote service provider. I rather like Test::MockModule for this but there are plenty of other options on CPAN to help you with it.


        🦛

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11131301]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2024-04-25 12:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found