Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Testing 我可以测试ELisp函数吗?_Testing_Elisp_Regression Testing - Fatal编程技术网

Testing 我可以测试ELisp函数吗?

Testing 我可以测试ELisp函数吗?,testing,elisp,regression-testing,Testing,Elisp,Regression Testing,我喜欢单独测试函数的doctests的Python特性。Emacs Lisp是否有类似的功能,或者我是否可以以某种方式模拟它 例如,此函数从组织模式时钟段获取时间戳: (defun组织获取时间戳(第行) “解析时钟段线并返回列表中的第一个和最后一个时间戳。” (let*((org-clock-regexp(concat“clock:”org-ts-regexp3“-”org-ts-regexp3)) (t1(如果字符串匹配组织时钟regexp行) (匹配字符串1行) (用户错误“参数必须具有有效

我喜欢单独测试函数的doctests的Python特性。Emacs Lisp是否有类似的功能,或者我是否可以以某种方式模拟它

例如,此函数从组织模式时钟段获取时间戳:

(defun组织获取时间戳(第行)
“解析时钟段线并返回列表中的第一个和最后一个时间戳。”
(let*((org-clock-regexp(concat“clock:”org-ts-regexp3“-”org-ts-regexp3))
(t1(如果字符串匹配组织时钟regexp行)
(匹配字符串1行)
(用户错误“参数必须具有有效的时钟范围”))
(t2(匹配字符串9行)))
(cons t1(cons t2)((()))
我想要一个文档测试,例如:

(org-get-timestamps "CLOCK: [2019-09-26 Thu 00:29]--[2019-09-26 Thu 01:11] => 0:42") ("2019-09-26 Thu 00:29" "2019-09-26 Thu 01:11") (组织获取时间戳“时钟:[2019-09-26周四00:29]--[2019-09-26周四01:11]=>0:42”) (“2019-09-26周四00:29”“2019-09-26周四01:11”) 测试
用户错误
也不错

我还想确保任何重构都通过了doc测试,因此它也是一个回归测试


存在吗?

Python doctest的一个重要特性是其输入看起来像Python交互式REPL会话,如中所述:

doctest模块搜索看起来像 交互式Python会话,然后将这些会话执行到 验证它们是否完全如图所示工作

我不知道有任何像这样的elisp工具,但我认为您可以使用实现您想要的功能,它支持交互式和批处理测试执行

要测试
org get timestamps
函数,可以定义如下测试:

(require 'ert)

(ert-deftest org-timestamp-test ()
  (should (equal
           (org-get-timestamps "CLOCK: [2019-09-26 Thu 00:29]--[2019-09-26 Thu 01:11] => 0:42")
           '("2019-09-26 Thu 00:29" "2019-09-26 Thu 01:11"))))
要以交互方式运行测试,您可以键入M-x ert,按enter键,然后再次按enter键以使用默认的
t
参数选择所有测试,或者键入要运行的测试的名称并按enter键,测试结果将显示在
*ert*
缓冲区中:

Selector: org-timestamp-test
Passed:  1
Failed:  0
Skipped: 0
Total:   1/1

Started at:   2019-09-27 08:44:57-0400
Finished.
Finished at:  2019-09-27 08:44:57-0400

.
上面末尾的点字符表示运行的测试。如果执行多个测试,将有多个点

要以批处理模式运行测试,请将其保存到文件
org timestamp test.el
,并假设
org get timestamps
函数位于文件
org timestamps.el
中,从shell命令行按如下方式运行:

emacs -batch -l ert -l org-timestamps.el -l org-timestamp-test.el -f ert-run-tests-batch-and-exit
然后在外壳输出上显示测试结果:

运行1次测试(2019-09-27 06:03:09-0700)通过1/1 组织时间戳测试

按预期进行了1次测试,1次结果(2019-09-27 06:03:09-0700)


很不错的!我喜欢测试可以以交互方式或批处理方式运行。