gpt4 book ai didi

c - C 应用程序的功能测试。如何使用数据驱动的 TSV 将标准输入传递给 Robot Framework 中的进程?

转载 作者:太空宇宙 更新时间:2023-11-03 23:44:17 25 4
gpt4 key购买 nike

我想测试一个控制台应用程序(用 C 编写),它只是从键盘获取输入并写入标准输出。

为简单起见,应用程序取自 K&R 书籍并模仿标准 wc 实用程序:

#include <stdio.h>

#define IN 1
#define OUT 0

int main(void)
{
int c, nl, nw, nc, state;

state = OUT;
nl = nw = nc = 0;
while ((c = getchar()) != EOF) {
++nc;
if (c == '\n')
++nl;
if (c == ' ' || c == '\n' || c == '\t')
state = OUT;
else if (state == OUT) {
state = IN;
++nw;
}
}
printf("%d %d %d\n", nl, nw, nc);
}

我找不到任何工具可以使用 Run Process 将数据传递到 stdin关键字(使用 Process 库)。但是,我设法使用了 echo 和管道,如下所示:

*** Settings ***
Library Process
Test Template Test Output

*** Variables ***
${PROGRAM} ./a.out

*** Test Cases *** INPUT OUTPUT
Empty input '' 0 0 0
One-letter word 'a\n' 1 1 2
Two-letter word 'ab\n' 1 1 3
Two one-letter words 'a b\n' 1 2 4
Two lines with one-letter word 'a\nb\n' 2 2 4

*** Keywords ***
Test Output
[Arguments] ${input} ${output}
Run Process echo -n ${input} | ${PROGRAM} shell=true alias=myproc
${stdout}= Get Process Result myproc stdout=true
Log ${stdout}
Should Be Equal ${stdout} ${output}

然而,这种方法不可移植。是否有一些更通用的工具可以使用已经准备好的输入启动 Run Process 还是我做错了?

最佳答案

机器人框架的进程库或我所知道的任何内置库都无法与进程的标准输入进行交互。看看https://github.com/robotframework/robotframework/issues/2166

关于c - C 应用程序的功能测试。如何使用数据驱动的 TSV 将标准输入传递给 Robot Framework 中的进程?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37949238/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com