Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re^2: RFC: How did I do writing my first test?

by Lady_Aleena (Curate)
on Sep 26, 2020 at 01:59 UTC ( #11122226=note: print w/replies, xml ) Need Help??


in reply to Re: RFC: How did I do writing my first test?
in thread RFC: How did I do writing my first test?

After all of the talk about final newlines, and a problem just hit me in the head. I did not take into consideration blank lines in files. What if a file has a blank line or two in the middle? If there is a blank line it currently, the before and after still get put on the list without any other value.

test.txt (file)
red orange yellow spring green teal cyan azure blue violet magenta pink white black gray
Code
perl -E ' use lib "mods/lib"; use Fancy::Open qw(fancy_open); my @array=fancy_open("test.txt", { before => "solid ", after => " bead +" }); say $_ for @array; '
Result
solid red bead solid orange bead solid yellow bead solid spring bead solid green bead solid teal bead solid cyan bead solid azure bead solid bead solid blue bead solid violet bead solid magenta bead solid pink bead solid white bead solid black bead solid gray bead

So, I am now three steps back from being ready to package this module. *sighs*

I didn't feel like fighting with splice right now to add an empty line in the test script.

My OS is Debian 10 (Buster); my perl versions are 5.28.1 local and 5.16.3 or 5.30.0 on web host depending on the shebang.

No matter how hysterical I get, my problems are not time sensitive. So, relax, have a cookie, and a very nice day!
Lady Aleena

Replies are listed 'Best First'.
Re^3: RFC: How did I do writing my first test?
by jcb (Vicar) on Sep 27, 2020 at 02:33 UTC

    This is why you should write full-coverage testsuites — in the course of testing every path, you are likely to find edge cases that you had not recognized before.

    For this particular problem, the easiest solution, assuming that you chomp each input line is to put the code that adds before and after strings in an unless (m/^$/) block. (If you do not chomp the input, change the regex match to m[^$/$], quickly tested here with perl -e 'while (<>) { print "empty\n" if m[^$/$] }' and typing some sample input.)

      "This is why you should write full-coverage testsuites in the course of testing every path, you are likely to find edge cases that you had not recognized before."

      An API (or any code) should have tests written before, during and after completion. Especially after the documentation is completed, to verify.

      You're right about the edge cases. They get found in testing, and then become tests themselves.

      If one doesn't find issues when running their test suites against their code after significant updates, the test suite is insufficient.

Re^3: RFC: How did I do writing my first test?
by Arunbear (Prior) on Sep 26, 2020 at 18:06 UTC
    What does the documentation say about how it handles blank lines? :)

    i.e. this may well be the correct behaviour (but you'd need to think about and document that).

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (12)
As of 2020-11-24 10:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?