Tc – 西奥多·卡尔文的语言无关测试框架
Tc – Theodore Calvin's language-agnostic testing framework

原始链接: https://github.com/ahoward/tc

## tc:一种与语言无关的测试框架 tc 是一个精简的、与语言无关的测试框架,专为“人工智能时代”设计,其中测试被认为是权威规范,代码是可丢弃的。它允许你编写一次测试,并将其应用于用任何语言编写的代码(Bash、Python、Rust、Go 等)。 **工作原理:** 测试被组织为目录。每个测试从标准输入读取 `input.json`,并将 `expected.json` 写入标准输出。依赖项很少——只需要 `jq`。 **主要特性:** * **语言无关性:** 使用统一的测试套件测试任何语言。 * **简单结构:** 测试组织为具有 JSON 输入/输出的目录。 * **模式匹配:** 支持在 `expected.json` 中进行动态值验证(UUID、时间戳、数字、字符串)。 * **并行执行:** 并行运行测试以获得更快的结果。 * **测试生成:** 包括 `tc new` 用于创建测试套件,以及通过 `tc-kit` 进行实验性 AI 驱动的测试生成。 **入门:** 克隆仓库,将 `tc/bin` 目录添加到你的 `PATH`(关键是避免与 Unix `tc` 命令冲突),并使用 `tc new` 创建你的第一个测试套件。 **愿景:** 实现快速的语言移植,并在实现演进时保持测试的稳定性。

## 简单的基于差异的测试受到认可 一篇 Hacker News 的讨论强调了简单、基于差异的测试框架的有效性,以“tc”(github.com/ahoward)为例,这是一种与语言无关的测试工具。用户分享了经验,表明将程序输出与预定义的预期结果进行比较——通常通过文件比较——即使对于内部编程语言,也证明出奇的强大。 虽然看似基础,但这种方法侧重于验证*结果*,而不是复杂的代码级断言,使其具有普遍适用性。评论员强调,核心原则——实际输出匹配预期输出——即使在增加图像差异或改进测试运行器扩展性等复杂情况下,仍然很有价值。 一位用户甚至分享了“clitest”(github.com/mmastrac/clitest),一个基于类似原理构建的 CLI 测试工具,承认虽然有效,但每个测试用例一个文件的做法在更大规模上可能会变得笨拙。对话表明,这种直接的测试方法是许多开发人员经常首选的默认方法。
相关文章

原文

language-agnostic testing for unix hackers

Theodore Calvin - the man, the legend
theodore "tc" calvin - helicopter pilot, testing framework namesake, legend

|=o=o=o=o=o=o=o=o=o=o=o=|      tc v1.0.0 - island hopper
           |                   testing any language, anywhere
       ___/ \___      (o)       🚁 fly safe, test well
     (( tc      ))======\
       \_______/        (o)
         ^   ^
      ^-----------^

What: Language-agnostic test framework. Write tests once, run against any language (bash, python, rust, go, whatever).

How: Tests are directories. Your code reads input.json from stdin, writes expected.json to stdout. That's it.

Get Started:

# clone and install
git clone https://github.com/ahoward/tc.git
cd tc

# IMPORTANT: Add to PATH (avoids conflict with Unix traffic control command)
export PATH="$PWD/tc/bin:$PATH"

# verify
tc --version

# try the hello-world example
tc examples/hello-world

# create your first test
tc new tests/my-feature

That's it. See full docs for advanced features.


⚠️ PATH Setup (avoid Unix tc conflict)

tc conflicts with the Unix traffic control command. You MUST add this project's tc to your PATH.

# Add to PATH for current session
export PATH="$PWD/tc/bin:$PATH"

# Add to shell config for persistence (optional)
echo 'export PATH="$PWD/tc/bin:$PATH"' >> ~/.bashrc  # or ~/.zshrc

Verify:

which tc        # should show: ./tc/bin/tc (NOT /usr/sbin/tc)
tc --version    # should show: tc v1.0.0 - island hopper

tc is a dead-simple testing framework that lets you:

  • test any language with the same test suite
  • organize tests as directories with json input/output
  • run tests with zero dependencies (just jq)
  • port code between languages without rewriting tests

simpleportablelanguage-agnosticunixspec-driven

🤖 In the AI age, specifications and tests are permanent while implementations are disposable.

Tests are the spec. Code is a build artifact. Port languages freely, keep tests forever.

🔬 experimental: multi-language dao demo

See projects/ and examples/multi-lang-dao/ for a working example of identical DAO interfaces in 5 languages (Ruby, Go, Python, JavaScript, Rust) all passing the same test suite.

Vision: Disposable applications. Swap languages freely, keep tests forever.

See docs/THEORY.md for the full system adapter pattern vision.

# test execution
tc                          # run all tests (KISS!)
tc <suite-path>             # run single test suite
tc <path> --all             # run all suites in directory tree
tc <path> --tags TAG        # run suites matching tag
tc <path> --parallel        # run all suites in parallel (auto CPU detection)
tc <path> --parallel N      # run with N parallel workers

# test generation
tc new <test-path>          # generate new test suite
tc init [directory]         # initialize test directory with README

# discovery & metadata
tc list [path]              # list all test suites with metadata
tc tags [path]              # show all available tags
tc explain <suite>          # explain what a test suite does

# info
tc --version                # show version
tc --help                   # show help

TTY mode (terminal): Clean single-line status with 🚁 spinner, fail-fast behavior Non-TTY mode (CI/CD): Traditional verbose output with full logs Override: TC_FANCY_OUTPUT=true/false

→ full docs | → tc new guide | → system adapter theory (WIP)

my-feature/
├── run                    # executable: reads input.json, writes json to stdout
└── data/
    └── scenario-1/
        ├── input.json     # test input
        └── expected.json  # expected output
tc my-feature  # ✓ pass or ✗ fail

tc supports simple pattern matching in expected.json for dynamic values:

{
  "id": "<uuid>",
  "status": "pending",
  "created_at": "<timestamp>",
  "count": "<number>",
  "message": "<string>"
}

Patterns:

  • <uuid> - validates UUID v4 format
  • <timestamp> - validates ISO 8601 timestamp (YYYY-MM-DDTHH:MM:SS)
  • <number> - any JSON number
  • <string> - any string value
  • <boolean> - true or false
  • <null> - null value
  • <any> - matches anything

Works everywhere:

  • Nested objects
  • Array elements
  • Mixed with exact values

No configuration needed - patterns are auto-detected.

Define your own patterns via TC_CUSTOM_PATTERNS:

export TC_CUSTOM_PATTERNS="email:^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$
ipv4:^([0-9]{1,3}\.){3}[0-9]{1,3}$
phone:^\+?[0-9]{10,15}$"

Then use in expected.json:

{
  "email": "<email>",
  "server": "<ipv4>",
  "contact": "<phone>"
}

Format: pattern_name:regex (one per line, standard regex syntax)

test execution:

test generation:

discovery & metadata:

quality:

roadmap:

→ tc-kit: AI-driven testing ⚠️ EXPERIMENTAL

tc-kit integrates with spec-kit for automatic test generation from specifications. Perfect for AI-assisted development workflows where specs and tests are permanent while implementations are disposable.

Quick start:

# Generate tests from spec
/tc.specify

# Implement to pass tests
edit tc/tests/my-feature/user-story-01/run

# Validate & refine
/tc.validate
/tc.refine

See AI.md for full documentation.

Prerequisites: bash 4.0+, jq

# Install jq
brew install jq                     # macOS
sudo apt-get install jq             # Ubuntu/Debian

# Clone tc
git clone https://github.com/ahoward/tc.git
cd tc

# Add to PATH
export PATH="$PWD/tc/bin:$PATH"

# Verify
tc --version

See the TL;DR section above for PATH setup details.

mit license - see LICENSE


made with ☕ and helicopters

"the chopper's fueled up and ready to go. let's test some code." — tc

🚁 fly safe, test well

an #n5 joint 🚬

联系我们 contact @ memedata.com