C 应用程序的功能测试。如何使用数据驱动的 TSV 将标准输入传递给 Robot Framework 中的进程?
Functional testing of C aplication. How do I pass standard input to process in Robot Framework using data-driven TSV?
我想测试一个控制台应用程序(用 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
keyword (using the Process
库将数据传递到 stdin
。但是,我设法使用 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
还是我做错了?
机器人框架的进程库或我所知道的任何 built-in 库都无法与进程的标准输入进行交互。看看 https://github.com/robotframework/robotframework/issues/2166
我想测试一个控制台应用程序(用 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
keyword (using the Process
库将数据传递到 stdin
。但是,我设法使用 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
还是我做错了?
机器人框架的进程库或我所知道的任何 built-in 库都无法与进程的标准输入进行交互。看看 https://github.com/robotframework/robotframework/issues/2166