From 33f6c67e1346a82526c43cfc8b0c12fc3da8f912 Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Sun, 12 Jul 2026 20:03:48 +0800 Subject: [PATCH] rename(tests): move aot tests directory to compiler - Renamed test directory from tests/aot/ to tests/compiler/ - Updated all references in documentation files to point to new location - Modified test runner commands to use new compiler test path - Updated guide documentation to reflect directory name change - Changed all test file paths in markdown documentation accordingly --- .github/copilot-instructions.md | 8 ++--- CLAUDE.md | 6 ++-- docs/HIGH_PRECISION_TYPES.md | 6 ++-- docs/QUICKSTART.md | 4 +-- docs/UNIVERSAL_METHODS.md | 10 +++---- docs/hhvm-review.md | 2 +- docs/kphp-review.md | 2 +- tests/compiler/RUN_TESTS_GUIDE.md | 38 ++++++++++++------------ tests/compiler/SKIP_TESTS.md | 12 ++++---- tests/compiler/TEST_SUPPLEMENT_REPORT.md | 18 +++++------ 10 files changed, 53 insertions(+), 53 deletions(-) diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md index 4b849a00..35666761 100644 --- a/.github/copilot-instructions.md +++ b/.github/copilot-instructions.md @@ -53,14 +53,14 @@ Run a single PHPUnit file or a single test method: Run PHPT integration tests: ```bash -php run-tests.php tests/aot/ -php run-tests.php tests/aot/arrays.phpt +php run-tests.php tests/compiler/ +php run-tests.php tests/compiler/arrays.phpt ``` For parser/runtime comparison without AOT compilation, there are docs using: ```bash -php run-tests.php --no-aot tests/aot/arrow-functions.phpt +php run-tests.php --no-aot tests/compiler/arrow-functions.phpt ``` ## Formatting @@ -87,4 +87,4 @@ Generated C++ is auto-formatted by the compiler itself when `clang-format` is av - PHPUnit tests for compiler internals should use `CompilerTest::create(ROOT_PATH)`, which enables test mode instead of normal fatal exits. - `phpunit/bootstrap.php` exposes a `BaseTest::exec()` helper that expects compilation failures to surface as `TypePhp\Exception\TestError`. -- PHPT end-to-end tests live in `tests/aot/`; existing guidance and examples generally put executable test logic inside a `main()` function. +- PHPT end-to-end tests live in `tests/compiler/`; existing guidance and examples generally put executable test logic inside a `main()` function. diff --git a/CLAUDE.md b/CLAUDE.md index 117ae0e7..bf27066e 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -40,10 +40,10 @@ composer install ./vendor/bin/phpunit phpunit/src/AstNodeTypeTest.php # Run PHPT integration tests (all) -php run-tests.php tests/aot/ +php run-tests.php tests/compiler/ # Run a single PHPT test -php run-tests.php tests/aot/arrays.phpt +php run-tests.php tests/compiler/arrays.phpt ``` ## Architecture @@ -98,6 +98,6 @@ Generated `.cc` and `.o` files land in `build/` directory. The compiled binary i ### Test Infrastructure - **PHPUnit tests** (`phpunit/src/`) — unit/integration tests for compiler internals. Bootstrap at `phpunit/bootstrap.php` defines a `BaseTest` class with an `exec()` helper that runs the compiler and expects a `TestError` exception containing a given string -- **PHPT tests** (`tests/aot/`) — end-to-end tests using the standard PHPT format (`run-tests.php`). Each `.phpt` contains PHP source and expected output sections +- **PHPT tests** (`tests/compiler/`) — end-to-end tests using the standard PHPT format (`run-tests.php`). Each `.phpt` contains PHP source and expected output sections When writing new compiler tests, use `CompilerTest::create(ROOT_PATH)` (in `src/CompilerTest.php`) which sets `forTest = true` to enable test-specific behavior without writing files to disk. diff --git a/docs/HIGH_PRECISION_TYPES.md b/docs/HIGH_PRECISION_TYPES.md index 68446963..e1f1803e 100644 --- a/docs/HIGH_PRECISION_TYPES.md +++ b/docs/HIGH_PRECISION_TYPES.md @@ -746,9 +746,9 @@ pi × 2: 6.2831800000000000 ## 进一步阅读 - **类型系统规范**:[`docs/NATIVE_TYPES.md`](NATIVE_TYPES.md) — 完整的类型提升规则、声明语法、C++ API 参考 -- **BigInt PHPT 测试**:[`tests/aot/bigint/`](../tests/aot/bigint/) — BigInt 各项功能的集成测试 -- **Decimal PHPT 测试**:[`tests/aot/decimal/`](../tests/aot/decimal/) — Decimal 各项功能的集成测试 -- **BigFloat 集成测试**:[`tests/aot/bignumber/bigfloat_operators.phpt`](../tests/aot/bignumber/bigfloat_operators.phpt) — BigFloat 运算符测试 +- **BigInt PHPT 测试**:[`tests/compiler/bigint/`](../tests/compiler/bigint/) — BigInt 各项功能的集成测试 +- **Decimal PHPT 测试**:[`tests/compiler/decimal/`](../tests/compiler/decimal/) — Decimal 各项功能的集成测试 +- **BigFloat 集成测试**:[`tests/compiler/bignumber/bigfloat_operators.phpt`](../tests/compiler/bignumber/bigfloat_operators.phpt) — BigFloat 运算符测试 - **C++ 运行时头文件**: - [`phpx/include/phpx_big_int.h`](../../phpx/include/phpx_big_int.h) — BigInt C++ API - [`phpx/include/phpx_decimal.h`](../../phpx/include/phpx_decimal.h) — Decimal C++ API diff --git a/docs/QUICKSTART.md b/docs/QUICKSTART.md index 61de2a00..8a1f874b 100644 --- a/docs/QUICKSTART.md +++ b/docs/QUICKSTART.md @@ -209,13 +209,13 @@ for ($i = 0; $i < 10; $i++) { // 错误! ### 运行单个测试 ```bash -PHPT=1 php run-tests.php tests/aot/arrow_fn/001.phpt +PHPT=1 php run-tests.php tests/compiler/arrow_fn/001.phpt ``` ### 运行所有测试 ```bash -PHPT=1 php run-tests.php tests/aot/ +PHPT=1 php run-tests.php tests/compiler/ ``` ### 查看测试结果 diff --git a/docs/UNIVERSAL_METHODS.md b/docs/UNIVERSAL_METHODS.md index 59f1b7dc..34ce4814 100644 --- a/docs/UNIVERSAL_METHODS.md +++ b/docs/UNIVERSAL_METHODS.md @@ -1105,8 +1105,8 @@ function main(): void { - **类型系统规范**:[`docs/NATIVE_TYPES.md`](NATIVE_TYPES.md) - **通用方法实现**:[`src/Parser/UniversalMethodCall.php`](../src/Parser/UniversalMethodCall.php) - **集成测试**: - - [`tests/aot/string_method/`](../tests/aot/string_method/) — String 通用方法测试 - - [`tests/aot/array_method/`](../tests/aot/array_method/) — Array 通用方法测试 - - [`tests/aot/stream_method/`](../tests/aot/stream_method/) — Stream 通用方法测试 - - [`tests/aot/bigint/`](../tests/aot/bigint/) — BigInt 通用方法测试 - - [`tests/aot/decimal/`](../tests/aot/decimal/) — Decimal 通用方法测试 + - [`tests/compiler/string_method/`](../tests/compiler/string_method/) — String 通用方法测试 + - [`tests/compiler/array_method/`](../tests/compiler/array_method/) — Array 通用方法测试 + - [`tests/compiler/stream_method/`](../tests/compiler/stream_method/) — Stream 通用方法测试 + - [`tests/compiler/bigint/`](../tests/compiler/bigint/) — BigInt 通用方法测试 + - [`tests/compiler/decimal/`](../tests/compiler/decimal/) — Decimal 通用方法测试 diff --git a/docs/hhvm-review.md b/docs/hhvm-review.md index 3998309b..b250325a 100644 --- a/docs/hhvm-review.md +++ b/docs/hhvm-review.md @@ -422,7 +422,7 @@ HHVM 有庞大的测试体系: - Zend 测试:直接复用 php-src 官方测试,验证 PHP 兼容性 **AOT 借鉴:** -- Quick/Slow 分层测试策略——将现有 `tests/aot/` 按运行时间分类 +- Quick/Slow 分层测试策略——将现有 `tests/compiler/` 按运行时间分类 - 直接复用 php-src 官方 PHPT 测试——验证 AOT 编译器的 PHP 行为兼容性 - HHBBC 内部单元测试太少(仅 3 个),不应效仿——AOT 的 PHPUnit 测试覆盖更好 diff --git a/docs/kphp-review.md b/docs/kphp-review.md index 12aef345..be0b4ab0 100644 --- a/docs/kphp-review.md +++ b/docs/kphp-review.md @@ -293,7 +293,7 @@ KPHP 有三层测试体系: - 增量编译支持(nocc 分布式编译) **AOT 借鉴**: -- 当前 AOT 只有 `phpunit/` (PHPUnit) 和 `tests/aot/` (PHPT) 两层,缺少编译器内部单元测试和集成测试 +- 当前 AOT 只有 `phpunit/` (PHPUnit) 和 `tests/compiler/` (PHPT) 两层,缺少编译器内部单元测试和集成测试 - 标签机制比纯 PHPT 更灵活——可以标记预期编译失败、预期警告等 - Python 测试 runner 提供了更好的 CI 集成能力 diff --git a/tests/compiler/RUN_TESTS_GUIDE.md b/tests/compiler/RUN_TESTS_GUIDE.md index 7cebaee9..a6cac574 100644 --- a/tests/compiler/RUN_TESTS_GUIDE.md +++ b/tests/compiler/RUN_TESTS_GUIDE.md @@ -2,7 +2,7 @@ ## 测试文件位置 -所有测试文件位于 `tests/aot/` 目录下,使用 `.phpt` 扩展名。 +所有测试文件位于 `tests/compiler/` 目录下,使用 `.phpt` 扩展名。 ## 运行测试 @@ -10,39 +10,39 @@ ```bash # 运行特定测试文件 -php run-tests.php tests/aot/test-name.phpt +php run-tests.php tests/compiler/test-name.phpt # 示例:运行 match expression 测试 -php run-tests.php tests/aot/match-expression.phpt +php run-tests.php tests/compiler/match-expression.phpt ``` ### 运行多个测试 ```bash # 运行多个测试(使用通配符) -php run-tests.php tests/aot/pattern*.phpt +php run-tests.php tests/compiler/pattern*.phpt # 运行整个目录 -php run-tests.php tests/aot/ +php run-tests.php tests/compiler/ ``` ### 常用选项 ```bash # 显示详细信息 -php run-tests.php tests/aot/test-name.phpt -v +php run-tests.php tests/compiler/test-name.phpt -v # 并行运行测试(加快测试速度) -php run-tests.php tests/aot/ -j4 +php run-tests.php tests/compiler/ -j4 # 只显示失败的测试 -php run-tests.php tests/aot/ -g FAIL +php run-tests.php tests/compiler/ -g FAIL # 保持测试生成的文件 -php run-tests.php tests/aot/test-name.phpt --keep-all +php run-tests.php tests/compiler/test-name.phpt --keep-all # 显示内存使用情况 -php run-tests.php tests/aot/test-name.phpt -m +php run-tests.php tests/compiler/test-name.phpt -m ``` ## 新增测试用例说明 @@ -89,7 +89,7 @@ php run-tests.php tests/aot/test-name.phpt -m ### 基本步骤 -1. 在 `tests/aot/` 目录创建新文件,如 `my-feature.phpt` +1. 在 `tests/compiler/` 目录创建新文件,如 `my-feature.phpt` 2. 添加测试头部: ``` @@ -151,7 +151,7 @@ string(6) "result" ### 查看差异 ```bash -php run-tests.php tests/aot/failed-test.phpt -v +php run-tests.php tests/compiler/failed-test.phpt -v ``` 输出会显示期望值和实际值的差异: @@ -168,20 +168,20 @@ string(7) "results" ```bash # 保持生成的 C++ 文件 -php run-tests.php tests/aot/test-name.phpt --keep-all +php run-tests.php tests/compiler/test-name.phpt --keep-all # 查看生成的 C++ 代码 -cat build/tests/aot/test-name.cc +cat build/tests/compiler/test-name.cc ``` ### 手动编译和运行 ```bash # 1. 生成 stub 文件 -php bin/gen_stub.php -f tests/aot/test-name.php +php bin/gen_stub.php -f tests/compiler/test-name.php # 2. 转换为 C++ -php bin/compiler.php tests/aot/test-name.php +php bin/compiler.php tests/compiler/test-name.php # 3. 编译 C++ 代码 cd build && make test-name @@ -196,13 +196,13 @@ cd build && make test-name ```bash # 统计测试文件数量 -ls tests/aot/*.phpt | wc -l +ls tests/compiler/*.phpt | wc -l # 查看所有测试文件 -ls tests/aot/*.phpt | sort +ls tests/compiler/*.phpt | sort # 查看测试覆盖总结 -cat tests/aot/README_TEST_COVERAGE.md +cat tests/compiler/README_TEST_COVERAGE.md ``` ## 常见问题 diff --git a/tests/compiler/SKIP_TESTS.md b/tests/compiler/SKIP_TESTS.md index 85809e99..80aa0dd1 100644 --- a/tests/compiler/SKIP_TESTS.md +++ b/tests/compiler/SKIP_TESTS.md @@ -79,17 +79,17 @@ echo "skip 不支持的原因"; ### 方法 2: 运行测试时观察 ```bash -php run-tests.php tests/aot/generators.phpt +php run-tests.php tests/compiler/generators.phpt ``` 输出会显示: ``` -TEST /home/swoole/workspace/aot/tests/aot/generators.phpt -SKIP Generator syntax not supported in AOT [tests/aot/generators.phpt] +TEST /home/swoole/workspace/aot/tests/compiler/generators.phpt +SKIP Generator syntax not supported in AOT [tests/compiler/generators.phpt] ``` ### 方法 3: 统计 Skip 测试数量 ```bash -grep -l "^--SKIPIF--" tests/aot/*.phpt | wc -l +grep -l "^--SKIPIF--" tests/compiler/*.phpt | wc -l ``` --- @@ -148,7 +148,7 @@ grep -l "^--SKIPIF--" tests/aot/*.phpt | wc -l 2. **运行测试验证** ```bash - php run-tests.php tests/aot/test-name.phpt -v + php run-tests.php tests/compiler/test-name.phpt -v ``` 3. **确认测试通过** @@ -210,7 +210,7 @@ A: 保留这些测试可以作为未来的开发参考,并且可以在功能 A: 不会。Skip 测试会被正确识别并单独统计,不会影响 pass/fail 的比例。 ### Q: 如何查看所有 skip 测试? -A: 运行 `php run-tests.php tests/aot/ -g SKIP` 可以查看所有 skip 测试及其原因。 +A: 运行 `php run-tests.php tests/compiler/ -g SKIP` 可以查看所有 skip 测试及其原因。 ### Q: 什么时候会移除 skip 标记? A: 当对应的语法被实现并通过测试验证后,会移除 skip 标记。 diff --git a/tests/compiler/TEST_SUPPLEMENT_REPORT.md b/tests/compiler/TEST_SUPPLEMENT_REPORT.md index d1803ef3..e3cf6015 100644 --- a/tests/compiler/TEST_SUPPLEMENT_REPORT.md +++ b/tests/compiler/TEST_SUPPLEMENT_REPORT.md @@ -2,7 +2,7 @@ ## 📋 概述 -本次 review 了 `tests/aot/` 目录下的所有单测文件,分析了 PHP 语法覆盖情况,并新增了多个重要测试场景。 +本次 review 了 `tests/compiler/` 目录下的所有单测文件,分析了 PHP 语法覆盖情况,并新增了多个重要测试场景。 --- @@ -379,10 +379,10 @@ function sumTree(array $tree): int { ### 新增文件位置 -所有新增测试文件位于 `tests/aot/` 目录: +所有新增测试文件位于 `tests/compiler/` 目录: ``` -tests/aot/ +tests/compiler/ ├── readonly-class.phpt # Readonly 类测试 ├── backed-enum.phpt # Backed 枚举测试 ├── first-class-callable.phpt # 一类可调用语法测试 @@ -393,16 +393,16 @@ tests/aot/ ```bash # 运行单个测试 -php run-tests.php tests/aot/readonly-class.phpt +php run-tests.php tests/compiler/readonly-class.phpt # 运行所有新增测试 -php run-tests.php tests/aot/readonly-class.phpt \ - tests/aot/backed-enum.phpt \ - tests/aot/first-class-callable.phpt \ - tests/aot/deep-recursion.phpt +php run-tests.php tests/compiler/readonly-class.phpt \ + tests/compiler/backed-enum.phpt \ + tests/compiler/first-class-callable.phpt \ + tests/compiler/deep-recursion.phpt # 运行所有 AOT 测试 -php run-tests.php tests/aot/ +php run-tests.php tests/compiler/ ``` ---