c - 如何在 Windows 上的 Eclipse 中对 C 项目运行 .pl 测试?

标签 c eclipse perl testing

我必须按照老师给出的规范制作一个 C(不是 C++)项目。 为了让我们测试这个项目,他给了我们一个应该测试项目的 .pl 文件和一个充满 .in 和 .out 文件的文件夹。

我在 Win10 机器上工作并安装了 Eclipse for C (Kepler)。

如何设置我的项目以运行提供的测试? 由于我不是在 Linux 上工作,也不是从 cmdl 工作,因此我需要更改测试中的任何内容吗?

该程序是一个火车旅行计划器。

这是 .pl 文件:

#!/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";
        };
    };
    };
}

有些名字是丹麦语,抱歉。 Koereplan = 时间表,slut = 结束。

.in 文件示例:

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

这只是车站名称和出发时间。

.out 文件只包含一个数字,即相应行程所需的分钟数。

脚手架项目也附带了 makefile 文件,但我无法在我的环境中使用它们,我只是将“业务文件”带到另一个在 Eclipse 中制作的项目中,这对于编译和在 Eclipse 中运行项目。但这不允许我使用测试脚本(目前我什至无法在 Eclipse 中打开)。

如果您觉得有帮助,这里是作业:assignment on course website

但我认为我可以自己解决作业,它正在使用我不确定如何做的教师测试。

最佳答案

要启动 Eclipse CDT,请选择以下方法之一:

  1. 从可用的终端启动 eclipse,例如:

    $/path/to/eclipse.exe &

  2. 确保 msys 和 mingw 的 bin 目录在 PATH 中并以“正常”方式启动 eclipse

然后您可以将您的项目作为新的 C 项目导入,并照常在 CDT 中构建/调试/运行:

  1. 选择文件菜单 | | 使用现有代码的 Makefile 项目

enter image description here

  1. 输入您的项目路径和名称。但将索引器设置保留为 <none> * 然后按完成

enter image description here

  1. 打开 Make Target查看
  2. 右键单击该项目并选择新建...

enter image description here

  1. 填写你要搭建的目标
  2. 双击新的绿色图标,构建将运行,并在控制台 View 中输出。

enter image description here

  • 在 CDT 中有些事情似乎很奇怪,如果我使用 MinGW GCC 的明显设置作为索引器设置,那么我无法正确地进行 make,因为 CDT 坚持使用内部构建器。

关于c - 如何在 Windows 上的 Eclipse 中对 C 项目运行 .pl 测试?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35598924/

相关文章:

eclipse PDT : put my workspace under htdocs or is there a "move files" build directive?

r - R与Perl的map和grep等价的是什么?

c - 是否可以用一个简单的宏在 C 中创建 N 个变量?

java - 如何使 Java 项目成为 Eclipse 中的默认项目

c - 如何在 lua 中创建接受多个参数的 C 函数?

eclipse - Gradle: “Refresh All”删除Java构建路径中的链接项目

perl - 学习Perl的最佳在线资源是什么?

regex - Perl 正则表达式 : non-capturing group seems not to be working

c++ - 非阻塞连接 OpenSSL

c - 为什么 bool isFull 不更新为 false?