Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

Greetings Monks!

Yes, I know I shouldn't have interactive tests. I'll make them all automated or optional or something later. Maybe I'll use expect.

Basically, I'm writing some stuff that will alter user accounts on a system and send them email to tell them what it did. I want the script to run vi so I can review the email and make edits before it gets sent.

In the test harness, vi gets all confused because STDOUT isn't a tty. I can see the text to edit and I can close vi by typing "<esc>:q!" but I can't see the cursor or anything I type. No, this is not a surprise.

I think I need a way to tell the test harness to give me back the TTY for a minute, to stop looking for TAP and then start again.

If I run system("vi $filename") it behaves like I describe. If I run system("vi $filename >&2") it works great (vi still complains, but I don't care.) If I redirect STDOUT to STDERR and back in the test script, it doesn't help. I guess that's what you'd expect because STDOUT is already screwed with before I get there so redirecting it after the fact isn't going to help.

Anyway, is there a good way to handle this? I'm interested not only to solve my problem but also to improve my understanding of all these interacting filehandles and whatnot.

Here's the shortest script I could think of that shows the situation. Obviously you need 'vi' in your path.

use Test::More; use File::Temp qw(tempfile); my $text = 'hi there'; my ($fh,$fname) = tempfile(); print $fh $text; close($fh); ok(!system("vi $fname"),'vi exit OK'); open($fh,'<',$fname) || die "Failed to re-open $fname\n"; local $/; $text = <$fh>; close($fh); unlink($fname); done_testing();

Thanks All!
--Pileofrogs


In reply to Test::More & interactive test by pileofrogs

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others meditating upon the Monastery: (10)
    As of 2015-07-31 04:07 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









      Results (274 votes), past polls