展示 HN:一个适用于 Windows Shell 的“突击测试”脚本
Show HN: A "Cram tests" script for windows shells

原始链接: https://github.com/NyuB/craw

## craw:Windows 测试运行器摘要 `craw.py` 是一个 Windows 测试运行器,旨在执行在 `.t` 文件中定义的测试,使用 PowerShell 或 Cmd。它解释这些文件,生成 `.err` 输出以进行比较,并提供标准的测试框架行为——不为零的返回码以及差异显示。 主要功能包括:通过 `--shell` 选项支持 PowerShell 和 Cmd,沙盒测试目录,以及使用 `-i -y`(组合使用)自动将 `.err` 文件提升为 `.t` 文件的能力。`craw` 还处理环境变量,为 PowerShell 和标准变量访问复制它们。 目前,诸如预期输出的正则表达式匹配、通过 `.cramrc` 或环境变量进行配置以及原始 `cram` 的完整标志支持等功能*尚未*实现。测试依赖于由 `craw` 本身运行的端到端 `.t` 文件,未来的开发可能包括更强大的单元测试框架。

黑客新闻 新的 | 过去的 | 评论 | 提问 | 展示 | 工作 | 提交 登录 展示HN:一个用于Windows Shell的“Cram测试”脚本 (github.com/nyub) 3点 由 NyuB 2小时前 | 隐藏 | 过去的 | 收藏 | 讨论 功能有限,但能完成任务。我邀请任何不了解Cram测试的人尝试一下,无论是在Unix系统中使用原始的Cram,还是在Windows系统中使用这个脚本。 指南 | 常见问题 | 列表 | API | 安全 | 法律 | 申请YC | 联系 搜索:
相关文章

原文

Cram tests runnable on Windows Powershell and Cmd

(❌ means present in craM but not yet in craW)

  • ✅ Basics interpretation of .t and generation of corresponding .err
  • ✅ Powershell support (--shell=powershell)
  • ✅ Cmd support (--shell=cmd)
  • ✅ Sandboxed test directory
  • ✅ Promotion of .err to .t via -i -y flags (-y and -i are not supported in isolation)
  • ✅ Cram env variables (duplicated as powershell env items and proper variables)
  • ✅ 'Test framework behaviour', i.e. non-zero return code and diff display when .err differs from .t
  • ✅ Display error codes after command if non-zero
  • ❌ Regular expression for expected output
  • ❌ Options config via .cramrc
  • ❌ Options config via CRAM env variable
  • ❌ Full options and flags from cram (at least detected and noticed if not relevant)
  Usage: craw.py [OPTIONS] TESTS...
  OPTIONS:
  
    -h, --help                      show this help message and exit
    -i, --interactive               interactively merge changed test output
    -y, --yes                       answer yes to all questions
    --promote                       equivalent to -i -y: accept all changed test output
    --keep-tmpdir                   keep temporary directories
    --shell={cmd|powershell}        shell to use for running tests (default: powershell)
  
Non indented lines are just comments
Lines starting with '  $ ' are shell commands 
Lines starting with '  ' are the expected output of the shell commands above
  $ echo Youpi
  Youpi
  $ echo Content > test.txt
  $ cat test.txt
  Content
The env variable TESTDIR is set to the directory from which craw is executed
  $ cat $TESTDIR/test_resource.txt
  Lorem ipsum
If the shell command ends up failing, it's exit code is displayed between brackets after the command output
(here we swallow the error message to avoid flakiness of paths and windows error messages translation)
  $ cat non_existing_file.txt 2> swallow_error_message
  [False]
  • make test to test craw itself
  • make typecheck to ensure type soundness

Tests consist of end-to-end .t files ran by craw itself

Future work could necessitate a unittest harness for more involved testing (property tests, fuzzing or error handling will probably go there).

联系我们 contact @ memedata.com