在Perl中,如何在__LINE__中插入行号? [英] How do I interpolate a line number from __LINE__ into the name of a test in Perl?

查看:278
本文介绍了在Perl中,如何在__LINE__中插入行号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试这个测试用例时:

When I try this test case:

$sel->is_text_present_ok("foo", ("$testname: line ", __LINE__));

我想在日志中获取它:

ok 1 - is_text_present, "foo", Testcase-881: line 54

但是我在命令行中被责备:

But I get chided on the command line:

您将测试命名为"54".您不应该在考试中使用数字 名称.非常令人困惑.

You named your test '54'. You shouldn't use numbers for your test names. Very confusing.

我认为我应该以某种方式将该文字插值到字符串中,但是我无法深入了解它.我已经尝试了各种使用逗号和引号的配置.

I figure I should be interpolating that literal into the string somehow, but I can't get to the bottom of it. I've tried all sorts of configurations with the comma and quotation marks.

有什么方法可以得到我想要的结果吗?

Is there any way to get the result I'm looking for?

推荐答案

只需使用串联运算符 .:

$sel->is_text_present_ok("foo", "$testname: line " . __LINE__);

仅供参考,您可以像这样插值:"$testname: line ${\(__LINE__)}"

Just FYI, you can interpolate it like this: "$testname: line ${\(__LINE__)}"

这篇关于在Perl中,如何在__LINE__中插入行号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆