我正在尝试在Meson中创建单元测试目标的列表,每个测试用例都是从单个源文件构建的。源文件是通过子目录中的files()命令定义的:
Traceback (most recent call last):
File "C:\\Users\\sergi\\AppData\\Local\\Programs\\Python\\Python35\\lib\\site-packages\\telegram\\vendor\\ptb_urllib3\\urllib3\\connectionpool.py", line 398, in _make_request
httplib_response = conn.getresponse()
File "C:\\Users\\sergi\\AppData\\Local\\Programs\\Python\\Python35\\lib\\http\\client.py", line 1198, in getresponse
response.begin()
File "C:\\Users\\sergi\\AppData\\Local\\Programs\\Python\\Python35\\lib\\http\\client.py", line 297, in begin\n version, status, reason = self._read_status()
File "C:\\Users\\sergi\\AppData\\Local\\Programs\\Python\\Python35\\lib\\http\\client.py", line 258, in _read_status\n line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
File "C:\\Users\\sergi\\AppData\\Local\\Programs\\Python\\Python35\\lib\\socket.py", line 576, in readinto\n return self._sock.recv_into(b)
File "C:\\Users\\sergi\\AppData\\Local\\Programs\\Python\\Python35\\lib\\ssl.py", line 937, in recv_into
return self.read(nbytes, buffer)\n File "C:\\Users\\sergi\\AppData\\Local\\Programs\\Python\\Python35\\lib\\ssl.py", line 799, in read
return self._sslobj.read(len, buffer)\n File "C:\\Users\\sergi\\AppData\\Local\\Programs\\Python\\Python35\\lib\\ssl.py", line 583, in read
v = self._sslobj.read(len, buffer)\nsocket.timeout: The read operation timed out
During handling of the above exception, another exception occurred:
Traceback (most recent call last)
File "c:\\Users\\sergi\\.vscode\\extensions\\ms-python.python-2019.3.6558\\pythonFiles\\lib\\python\\ptvsd\\_vendored\\pydevd\\_pydevd_bundle\\pydevd_resolver.py", line 213, in _get_py_dictionary
attr = getattr(var, name)
AttributeError: characters_written
我想做的是在顶层构建中进行如下操作:
my_test_files = files(['test_foo.c','test_bar.c','test_baz.c'])
如果文件名是纯字符串,我知道可以执行此操作,但是上述方法失败,并显示“文件对象不可调用”错误。
还有更多的“ Mesonic”方法可以从源文件名中导出可执行文件/测试名吗?
答案 0 :(得分:1)
如果您将变量简单地定义为数组,则应该起作用,例如:
my_test_files = ['test_foo.c','test_bar.c','test_baz.c']
循环保持不变,除了某些错字已通过以下方式修复:
foreach t_file : my_test_files
t_name = t_file.split('.')[0]
test( t_name, executable(t_name, t_file, ...))
endforeach
代替构建文件对象的数组。这是因为execute()accepts input files in many forms:作为文件对象(您尝试做过)和作为字符串(源文件(应编译)或目标文件(要链接))-通过文件扩展名检测。 / p>
为了获得更大的灵活性和更好的控制,可以使用数组数组(当然,数组可以扩展,并且可以包含生成测试所需的任何内容):
foo_files = files('test_foo.c')
bar_files = files('test_bar.c')
baz_files = files('test_baz.c')
test_files = [
['foo', foo_files, foo_deps],
['bar', bar_files, []],
['baz', baz_files, baz_deps]]
foreach t : test_files
test( t[0], executable(t[0], t[1], dependencies=t[2], ...))
endforeach