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:

#include <stdio.h> #include <stdlib.h> #include <string.h> #define COMP_SIZE 265 #define COMP_TYPES_SIZE 428 int main() { FILE *input_file; char comp_file[13] = "list_comp.txt"; char comp_types_file[19] = "list_comp_types.txt"; char command[30]; while(1) { printf("srvrmgr> "); fgets(command, sizeof(command), stdin); /*removes new line*/ command[ strlen(command) - 1] = '\0'; switch(strlen(command)) { /*list comp*/ case 9 : { char comp_line[COMP_SIZE]; input_file = fopen(comp_file, "r"); if (input_file == NULL) { printf("Error reading %s\n", comp_file); perror(comp_file); exit(1); } while(fgets(comp_line, COMP_SIZE, input_file)) { printf("%s", comp_line); } fclose(input_file); break; } /*list comp types*/ case 15 : { char comp_types_line[COMP_TYPES_SIZE]; input_file = fopen(comp_types_file, "r"); if (input_file == NULL) { printf("Error reading %s\n", comp_types_file); perror(comp_types_file); exit(1); } while(fgets(comp_types_line, COMP_TYPES_SIZE, input_fi +le)) { printf("%s", comp_types_line); } fclose(input_file); break; } /*exit*/ case 4 : { printf("Disconnecting...\n"); exit(0); } default : { printf("Invalid command\n"); break; } } /*end of switch...case*/ } /*end of while(1)*/ exit(0); }

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

In reply to Re^2: CPAN automated tests for IPC by glasswalk3r
in thread CPAN automated tests for IPC by glasswalk3r

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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, details, 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, summary, 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.