in reply to CPAN automated tests for IPC

I thought creating a "mock" of this same program that expects an input and just print some output....

The mock that I created is a very simple C program that would need to be compiled before running the tests using a Makefile already available.

If all the mock program needs to do is accept some input and produce some output, why woudl you use C to write that?

I use Perl one-liners for similar purposes al the time:

my $mockedReturn = `perl -E"say 'fred' if $ARGV[0] eq 'bill'`;

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

The start of some sanity?

Replies are listed 'Best First'.
Re^2: CPAN automated tests for IPC
by glasswalk3r (Friar) on Mar 17, 2012 at 15:54 UTC

    The C code is interactive, so my mock test should "interact" with the program, giving commands to it and expecting output. Again, I'm not sure if using another Perl script would have any issue (only thing that comes to my mind is that I need print buffering).

    Here is the C code anyway:

    I'm sure I could write something better in pure Perl, but I'm confident that it wouldn't compromisse the testing results.

    Alceu Rodrigues de Freitas Junior
    ---------------------------------
    "You have enemies? Good. That means you've stood up for something, sometime in your life." - Sir Winston Churchill

      This is a pretty literal translation of your C file, that should perform exactly the same way (barring typos):

      #! perl -slw use strict; use constant { COMP_FILE => "list_comp.txt", COMP_TYPES_FILE => "list_comp_types.txt", }; while( 1 ) { printf "svrmgr> "; chomp( my $command = <STDIN> ); if( $command eq COMP_FILE ) { open my $in, '<', COMP_FILE or printf("Error reading %s\n", COMP_FILE ) and next; print while <$in>; } elsif( $command eq COMP_TYPES_FILE ) { open my $in, '<', COMP_TYPES_FILE or printf("Error reading %s\n", COMP_TYPES_FILE ) and next; print while <$in>; } else if( $command eq 'EXIT' ) { print "Disconnecting...\n"; last; } else { print "Invalid command\n"; } } exit 0;

      Easier to maintain?

      (Also, just an aside. Are the blank lines in your C code an artifact of posting, or your preferred style?)


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

      The start of some sanity?

        I believe it may work too, so I should consider using Perl instead of C just because it's easier to maintain. I'll put both of them to testing and if the results are the same I'll stick with the Perl version.

        I believe I might have put the blank lines by hand, not sure if it was the editor that I'm using (Anjuta). But it was not the posting.

        Alceu Rodrigues de Freitas Junior
        ---------------------------------
        "You have enemies? Good. That means you've stood up for something, sometime in your life." - Sir Winston Churchill