Skip to content

Test/suite names use underscores (violates GoogleTest naming rule; ~39+ generate reserved identifiers / UB) #857

Description

@IvanaGyro

(Issue written by Claude on behalf of @IvanaGyro.)

Summary

GoogleTest's own FAQ says test suite names and test names must not contain underscores (googletest FAQ — "Why should test suite names and test names not contain underscore?"). Our test suite violates this very widely, and a subset of the violations produce reserved C++ identifiers (undefined behavior), not just style problems.

Why it matters (from the FAQ)

TEST(SuiteName, TestName) expands to a class named SuiteName_TestName_Test (the macro joins the parts with _ and appends _Test). Two failure modes follow:

  1. Reserved identifiers (UB). The C++ standard reserves "any identifier that starts with _ followed by an upper-case letter, and any identifier that contains two consecutive underscores (__) anywhere." So a TestName that ends in _ (→ ..._ + _Test = ..__Test), or that already contains __, makes the generated class name a reserved identifier — undefined behavior.
  2. Name collisions. Even when not reserved, different underscore placements collapse to the same class name. The FAQ's example:
    TEST(Time,       Flies_Like_An_Arrow) { ... }
    TEST(Time_Flies, Like_An_Arrow)       { ... }
    both generate Time_Flies_Like_An_Arrow_Test → conflict.

Scope in this repo (master @ 24e8cc6)

Counting TEST / TEST_F / TEST_P / TYPED_TEST macros under tests/:

  • 877 of 1020 test names contain an underscore.
  • 123 suite/fixture names contain an underscore (e.g. linalg_Test).
  • Of the test names, the reserved-identifier (UB) subset:
    • ~39 test names end with _ → generated class has __. Examples: Trace_, Trace__str, Transpose_, Pow_, Tensor_Gemm_, Tensor_Inv_, DenseUt_InvM_, contiguous_, get_block_, get_blocks_, gpu_Tensor_Gemm_, gpu_DenseUt_Pow_, Conj__.
    • ~68 test names contain __ directly.

(Combined with underscore-containing suite names, many more class names embed __ even when the individual name doesn't end in one — e.g. suite linalg_Test + name Tensor_InvM_ → linalg_Test_Tensor_InvM__Test.)

Suggested action

  • Longer term, migrate test/suite names to underscore-free CamelCase to comply with the FAQ and avoid the collision class entirely.
  • This is mechanical but large (877 names); it can be done incrementally per test file. A CI lint (grep for TEST*\(.*_.*, / names with _) could prevent regressions once cleaned.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions