本文へ移動
cccskills
無料GitHub で公開日本語紹介

Toolchain tests

Carbonの`file_test`基盤を使い、toolchainのテストを作成・分割し、期待出力を自動更新する手順や命名規則を確認できます。

原文原文の説明を見る

Instructions for authoring, structuring, and running toolchain tests using the file_test infrastructure.

carbon-language/carbon-langスター 33,929(GitHub 33,929 + cccskills 0)

実行スコア 未検証

インストール方法を見る

こんなときに便利

  • toolchainのfile_testを書きたいとき
  • テストケースを分割したいとき
  • 失敗を検証するテストを作りたいとき
  • 期待出力を自動更新したいとき

日本語での紹介

できること

Carbonのtoolchain向けに、file_test基盤を使ったテストの作成、構成、実行方法を確認できます。テストファイルのライセンス表記や設定コメント、最小限のprelude指定、複数ケースに分ける方法、fail_やtodo_などの接頭辞の使い分けを説明します。SemIRの出力を必要な箇所に絞るマーカーや、期待される標準出力・標準エラーを自動更新するスクリプトの使い方も案内します。更新後の出力が意図した動作を示しているかは、別途確認する必要があります。

こんなときに便利

Carbonのコンパイラ機能を追加・変更し、対応するテストを新しく書くときに役立ちます。成功するケースと失敗を検証するケースを分けたい場合や、出力が大きくなりすぎないよう対象を絞りたい場合にも使えます。定数評価の境界値を含め、期待値の安定したテストを組み立てる際の指針も含まれます。

使い方の例

  • 「この機能のfile_testを、成功ケースと失敗ケースに分けて作ってください」
  • 「SemIRの出力を対象の宣言だけに絞るテストにしてください」
  • 「テストの期待出力を更新して、変更内容を確認してください」

注意点

対象はCarbonのtoolchainテストです。// CHECK:STDOUT:や// CHECK:STDERR:は手で編集せず、./toolchain/autoupdate_testdata.pyで更新します。更新された出力が正しいかどうかの判断は別途必要です。言語サーバーのテストは異なる規約を使うため、別のスキルを参照します。

この紹介文は、公開されている SKILL.md をもとに AI(OpenAI Codex)が作成しました。正確な仕様は下の原文を確認してください。

資料チェック

SKILL.md の記述から、注意が要る操作と導入の前提を AI が確認しました。点数は実際に動かした結果(実行検証)だけで付けています。

安全面送信・削除・コマンド実行などの扱いが明示されているか
B一部不足更新スクリプトで期待出力を書き換えるため、更新後の確認が必要です。
導入のしやすさ必要なツールや API キーが少ないか、書かれているか
B一部不足CarbonのリポジトリとPythonスクリプトを使いますが、導入手順は示されていません。

点数には入れていません。 2026年10月26日 時点で AI(OpenAI Codex)が判定しました。目安なので、入れる前に原文も確認してください。

評価が違うと思ったら、見直しを依頼する

どの項目が、なぜ違うと思うかを書いてください。ログインは不要です。内容を SKILL.md と照らし合わせて評価を作り直し、この欄に反映します。

このフォームは reCAPTCHA で保護されており、Google のプライバシーポリシーと利用規約が適用されます。

含まれるファイル(1)

  • SKILL.md8.2 KB

SKILL.md(原文)

インストールする前に、エージェントに与えられる指示の中身を確認できます。

Toolchain tests

<!-- Part of the Carbon Language project, under the Apache License v2.0 with LLVM Exceptions. See /LICENSE for license information. SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -->

Introduction

This skill provides guidelines and patterns for creating and updating tests for the Carbon toolchain, especially file tests in toolchain/*/testdata/ (for example, toolchain/check/testdata/).

Toolchain tests evaluate Carbon source files through Lexing, Parsing, Checking, and optionally Lowering. Output (for example SemIR dumps, Clang errors) is captured and validated using inline CHECK records.

Language server tests also use file_test, but with quite different conventions (an LSP message stream, AUTOUPDATE-SPLIT, FROM_FILE_SPLIT). Refer to the Language server skill (SKILL.md) for those.

Structure and Authoring

File Layout and Headers

Test files must start with the standard Carbon license, followed by configuration comments. Separate sections with blank comment lines (//).

// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// INCLUDE-FILE: toolchain/testing/testdata/min_prelude/...
//
// AUTOUPDATE
  • // AUTOUPDATE is mandatory for files using CHECK markers.
  • // TIP: lines are automatically generated by the autoupdater. You do not need to hand-write them. It is harmless to add them, but the script will handle it.

Minimized Preludes

When writing tests entirely unrelated to the Core package, specify a minimal prelude file using // INCLUDE-FILE. Usually, include toolchain/testing/testdata/min_prelude/ scripts, such as int.carbon or primitives.carbon. This significantly speeds up execution and minimizes STDOUT noise.

  • Builtin Primitive Testing: Standard operators (such as +, -, /, <, etc.) are not imported or available inside minimized preludes. To write tests with a minimal prelude footprint, call primitive builtins directly (e.g., float.negate, float.div) inside your test code to build expressions.

Split Tests and [[@TEST_NAME]]

A single physical file can test multiple scenarios using split constraints:

// --- passing_case.carbon
library "[[@TEST_NAME]]";

// ...

// --- fail_bad_case.carbon
library "[[@TEST_NAME]]";
// ...
  • Always use library "[[@TEST_NAME]]"; in each split rather than hardcoding the library name. This prevents name conflicts, avoids redefining the default library, and keeps the test code clean and templateable.
  • Exactly [[@TEST_NAME]] (including the brackets) must be used. The test infrastructure automatically replaces it with the split's filename minus todo_ and fail_ prefixes.
  • Do not put code that is expected to pass and code that is expected to fail into the same split. Validation relies on non-failing splits producing absolutely no errors and failing splits producing the correct compiler errors independently.

File Prefixing: fail_ and todo_

Expected failures must be differentiated from unexpected failures (and from bugs). Include prefixes to name individual split files or the main test:

  • fail_...: The test should and does produce compiler errors.
  • todo_fail_...: The test should produce errors but currently does not.
  • fail_todo_...: The test does produce errors or crashes, but it shouldn't (or produces the wrong errors or otherwise misbehaves with errors).
  • todo_...: The test has some incorrect behavior, but doesn't produce errors currently, and shouldn't.

Main File Naming: The main test file (and any split-files) must have a fail_ prefix if they have an associated error. Exception: The main file may omit fail_ if it contains a least one split that has a fail_ prefix.

Both the fail_ and todo_ prefixes are stripped from filename properties like [[@TEST_NAME]].

Constant Evaluation Validation

When testing constant evaluation in semantic checker tests, follow these conventions to ensure diagnostic stability and accuracy:

  • Literal Spelling Canonicalization: In Semantic IR, real literals (floating-point constants) with identical mathematical values can be assigned distinct internal representation identifiers based on spelling variations in source code. To completely prevent literal spelling mismatches in expected output checks, validation tests must be performed using canonical comparison methods (for example, passing converted values through an Expect(X as f64) function).
  • Generic Parameters Validation: To bypass compile-time constraints where local runtime variables are rejected as generic function arguments, test generic type conversions at runtime, and validate compile-time conversions by passing static literal values directly into primitive builtin calls.
  • Exhaustive Edge Case Verification: For complex mathematical algorithms (such as floating-point to integer truncation and rounding), map and execute test constraints covering every code branch, conditional exit, and fallback evaluation path.
  • Rounding Threshold Boundaries: Test cases that land extremely close to mathematical boundaries (for example, floating-point literals representing a tiny fraction above 1.0, such as $2^{30} \times 2^{-30}$ or $10^{10} \times 10^{-10}$, verifying correct exact truncation down to 1 or 0).
  • Precise Float Literal Spelling: Spell floating-point literals in test code with exact mathematical precision targeting target thresholds. For example, if testing the smallest fractional increment above 1.0, use the exact hex fractional representation (e.g. 0x1.0000000000001p0) or a highly precise decimal fractional spelling (e.g. 1.0000000000000001) instead of coarse fractions like 1.1 to ensure correct boundary assertions.
  • Representation Capacity Boundaries: Explicitly target edge cases near representation limits of target types. Test combinations of mantissas and exponents that yield values exactly on, just below, or just above the capacity limits of fixed-size destination types (e.g. signed/unsigned targets like i32 or u32).
  • Zero-Value Sizing Bounds: Verify boundary inputs of 0 and 0.0 explicitly. Assert that zero inputs are sized and simplified correctly without triggering calculation underflows, division-by-zero errors, or underestimating required bit allocations.

Test Code Comments

  • No agent thinking: Do not include comments describing your reasoning or "train of thought" (for example, "Wait, but...") inside the test files. Any comments left in tests should be concise and describe what the test itself is validating for human readers.

SemIR Dumps and Minimizing Output

Limit STDOUT checks to the logic under test. Always use //@dump-sem-ir-begin and //@dump-sem-ir-end around the specific declarations/blocks where SemIR output is desired. Only use these markers and not --dump-sem-ir-ranges=if-present or similar extra args—new tests use //@dump-sem-ir... to naturally filter output to the highlighted segments based on the default behavior.

//@dump-sem-ir-begin
fn F(x:? form(ref i32));
//@dump-sem-ir-end

Creating/Updating the Output

AI tools should never hand-write or manually touch // CHECK:STDOUT: or // CHECK:STDERR: comments.

Write your Carbon test code, headers, and // AUTOUPDATE then run the test updater:

./toolchain/autoupdate_testdata.py toolchain/PATH/TO/YOUR/TEST.carbon

Review the updated test outputs (for example, by way of git diff). Ensure logic paths are correctly tested rather than producing massive boilerplate blocks.

Autoupdating makes the tests pass whether or not the new behavior is correct, so deciding that the new output is the output you wanted is a separate step. See the Review testdata changes skill.

レビュー

まだレビューはありません。使ってみた感想をお寄せください。

コメント

ログインなしで書き込めます。使ってみた感想、質問、動かなかった環境などを気軽にどうぞ。

まだコメントはありません。最初のコメントを書いてみませんか。

送信するとすぐに公開されます。メールアドレスや電話番号などの個人情報は書かないでください。URL は 2 つまでです。

0 / 1000 文字

このフォームは reCAPTCHA で保護されており、Google のプライバシーポリシーと利用規約が適用されます。

同じリポジトリのスキル

Accessing GitHub issues

無料概要あり

コマンドラインからGitHub issueの本文やコメントを読み取り専用で確認し、URLや番号から対象リポジトリを指定する手順を案内します。

  • issueの本文とコメントを読みたいとき
  • URLからissueの内容を確認したいとき
  • 別リポジトリのissueを参照したいとき
carbon-language/carbon-lang3.4万2026年10月26日 更新

Agent tools

無料概要あり

AIアシスタントがCarbonのコードベースを扱う際に、専用ツールでファイルを閲覧・検索・編集し、一時ファイルを管理するためのルールを示します。

  • Carbonのファイルを規則に沿って検索したいとき
  • 専用ツールを使ったファイル編集を確認したいとき
  • 一時ファイルの置き場所と削除ルールを確認したいとき
carbon-language/carbon-lang3.4万2026年10月26日 更新

Bazel usage

無料概要あり

Bazeliskを使ったCarbonプロジェクトのビルド、テスト、実行、デバッグの基本手順を確認し、対象を絞った検証やASanの利用方法も把握できます。

  • Carbonのコードをビルドしたいとき
  • 変更箇所に関係するテストを実行したいとき
  • Bazelで作ったバイナリを起動したいとき
carbon-language/carbon-lang3.4万2026年10月26日 更新

Builtin functions

無料概要あり

Carbonコンパイラに組み込み関数を追加する際の登録、型シグネチャ検証、定数評価、LLVMコード生成、テスト方法を案内します。

  • 組み込み関数を登録したいとき
  • 定数評価の処理を実装したいとき
  • LLVM IRへの変換を追加したいとき
carbon-language/carbon-lang3.4万2026年10月26日 更新

Code style

無料概要あり

Carbonツールチェーンのコードを書く際に、言語ごとの整形方法やコメント、命名、ドキュメント、コミットメッセージの基準を確認できます。

  • Carbonコードの書式を整えたいとき
  • コメントやドキュメントを見直したいとき
  • コードの名前が意味に合うか確認したいとき
carbon-language/carbon-lang3.4万2026年10月26日 更新

Diagnostics

無料概要あり

Carbonコンパイラのエラーや警告を定義し、書式やソース位置のラベルを整え、テストで網羅性を確かめる方法を案内します。

  • 診断メッセージを追加したいとき
  • エラー位置にラベルを付けたいとき
  • 診断文の表記を統一したいとき
carbon-language/carbon-lang3.4万2026年10月26日 更新

carbon-language のスキルをすべて見る

このスキルの問題を報告する