mercredi 24 février 2016

How to run a .pl test on C project in Eclipse on Windows?

I have to make a C (not C++) project to the specifications given by my teacher. To allow us to test this project he has given us a .pl file that should test the project and a folder full of .in and .out files.

I work on a Win10 machine and has Eclipse for C installed (Kepler).

How can I set up my project to run the provided test? Do I need to change anything in the test since I don't work on Linux and not from a cmdl?

The program is a train travel planner.

Here is the .pl file:

#!/usr/bin/env perl

use warnings;
use strict;

my ( $createmode ) = @ARGV;
my $testdir = "./tests";

if( defined($createmode) ) {
    if($createmode cmp "create") {
    print "Brug:\n";
    print "\tcheck.pl         - tests if your programs output matches .out-filerne\n";
    print "\tcheck.pl create  - makes new .out-files (deletes the excisting files!)\n";
    exit();
    }
    $createmode=1;
}

# print "$testdir/tests.tst";
open(TESTS, "$testdir/tests.tst");


my $koereplan;
my $startst;
my $slutst;

while (<TESTS>) {

    /([\w\d]+)\.in\s+\"(.+)\"\s+\"(.+)\"/ && do {
    $koereplan="$testdir/$1";
    $startst=$2;
    $slutst=$3;

    # print $koereplan."\t".$startst."\t".$slutst."\n";

    open(RUN, "./travelplanning $koereplan.in '$startst' '$slutst' |");
    my $cost=0;
    while(<RUN>) {
        /^(\d+)\s+(\d+)$/ && do {
        $cost=$1+$2*15;
        }
    };

    #print "Cost fra programmet: $cost";

    my $outfile="$koereplan.$startst.$slutst.out";
    # print $outfile."\n";
    if($createmode) {
        open(OUT, ">$outfile") or die "Couldn't open '$outfile' for writing";
    } else {
        open(IN, "<$outfile") or die "Couldn't open '$outfile' for reading";
    }
    if($createmode) {
        print OUT "$cost\n";
    } else {
        my $facit=<IN>;
        if($facit cmp "$cost\n") {
        chomp $facit;
        print "ERROR: $koereplan.in $startst $slutst gav $cost og facit er $facit.\n";
        #last;
        } else {
        chomp $facit;
        print "SUCCES: $koereplan.in $startst $slutst gav $cost og facit er $facit.\n";
        };
    };
    };
}

Some names are in Danish, sorry about that. Koereplan = timetable, slut = end.

Excample of the .in files:

Esbjerg,    07:48
Bramming,   08:00
Vejen,      08:15
Kolding,    08:30
Middelfart, 08:45
Odense,     09:14
Nyborg,     09:29
Korsør,     09:42
Slagelse,   09:53
Sorø,       10:01
Ringsted,   10:10
Roskilde,   10:26
Høje Taastrup,  10:34
Valby,      10:42
København H,    10:48

This is just station names and departure times.

The .out files just contain one number each, the number of minutes the corresponding trip will take.

The scaffold project also came with makefile files, but I haven't been able to use them in my environment, I have simply taken the "business-files" to another project made in Eclipse, and that works fine for compiling and running the project in Eclipse. But that doesn't allow me to use the test script (that I currently can't even open in Eclipse).

If you feel it helps, here is the assignment: assignment on course website

But I think I can solve the assignment itself, it's using the teachers test I'm unsure about how to do.

Aucun commentaire:

Enregistrer un commentaire