For detailed information about the compiler testing framework, see the rustc-dev-guide testing section.
Test Suite Overview
The Rust compiler project includes multiple test suites, each serving different purposes:| Test Suite | Purpose | Location |
|---|---|---|
| ui | Compile-fail and run-pass tests with error output verification | tests/ui/ |
| run-make | Complex tests using Makefiles | tests/run-make/ |
| codegen | LLVM IR generation tests | tests/codegen-llvm/ |
| assembly | Assembly output tests | tests/assembly-llvm/ |
| mir-opt | MIR optimization tests | tests/mir-opt/ |
| debuginfo | Debug information tests | tests/debuginfo/ |
| rustdoc | Documentation generation tests | tests/rustdoc-html/, tests/rustdoc-ui/ |
| incremental | Incremental compilation tests | tests/incremental/ |
| coverage | Code coverage tests | tests/coverage/ |
Running Tests
Basic Test Commands
- All Tests
- Specific Suite
- Single Test
- Fast Check
Run the entire test suite (takes several hours):
Test Flags and Options
Writing UI Tests
UI tests are the most common type of test. They verify compiler output, including error messages.Basic UI Test Structure
Create a test file intests/ui/:
Test Directives
Use special comments to control test behavior:Compilation Behavior
Compilation Behavior
Error Checking
Error Checking
//~ markers indicate expected error locations://~- Error on the same line//~^- Error on the previous line//~|- Additional error message
Target Selection
Target Selection
Edition Specification
Edition Specification
Updating Test Expectations
When error messages change, update expectations with “bless”:.stderr or .stdout files to match the new output.
Writing Run-Make Tests
For complex scenarios requiring multiple files or build steps:Codegen and Assembly Tests
Codegen Tests
Verify the LLVM IR generated by rustc:Assembly Tests
Verify the generated assembly code:MIR Optimization Tests
Test the Middle Intermediate Representation (MIR) optimizations:Debugging Test Failures
Understanding Test Output
When a test fails, you’ll see:Common Debugging Strategies
- Isolate the Issue
- Check Compiler Output
- Use Debug Prints
- Compare Expected Output
Run just the failing test:
Incremental Testing
Test incremental compilation scenarios:Coverage Testing
Test code coverage instrumentation:CI Testing Workflow
Local CI Simulation
Before pushing, simulate what CI will run:CI Job Matrix
The CI runs tests on multiple platforms defined in.github/workflows/ci.yml:
- Linux: x86_64-gnu-llvm, x86_64-gnu-tools, i686-gnu
- Windows: x86_64-msvc, i686-msvc, x86_64-gnu
- macOS: x86_64-darwin, aarch64-darwin
- Cross-compilation: Various embedded and tier 2 targets
You can see the job matrix definition in
src/ci/github-actions/jobs.yml, which is processed by the citool to calculate which jobs run.Performance Testing
For changes that might impact performance:Request Performance Run
On your PR, comment:Interpret Results
The bot will report:- Instruction count changes
- Wall-time changes
- Memory usage changes
- Binary size changes
Test Organization Best Practices
Name Tests Clearly
Use descriptive names like
issue-12345.rs or trait-bound-ice.rsKeep Tests Minimal
Reduce test cases to the smallest reproducing example
Add Comments
Explain what the test is checking and why
Link to Issues
Reference the issue or RFC in test comments
Use Correct Suite
Put tests in the appropriate suite (ui, run-make, etc.)
Update Expectations
Run with
--bless when error messages changeCommon Test Patterns
Regression Tests
For bug fixes, add a regression test:Feature Tests
For new features (behind feature gates):Troubleshooting
Test Won’t Run
Stage Issues
Stage Issues
Ensure you’re using the right stage:
Platform-Specific Tests
Platform-Specific Tests
Some tests only run on specific platforms. Check the directives:You may need to skip these locally.
Outdated Build Artifacts
Outdated Build Artifacts
Clean and rebuild:
Additional Resources
rustc-dev-guide: Tests
Comprehensive testing documentation
compiletest Documentation
Details on the test harness
Adding New Tests
Step-by-step guide for new tests
CI Configuration
View the CI workflow definition
Summary
Back to Workflow
Return to the contribution workflow guide