LCOV - code coverage report
Current view: top level - backend/engine/semantic - error_test.cc (source / functions) Coverage Total Hit
Test: _coverage_report.dat Lines: 100.0 % 44 44
Test Date: 2026-07-02 21:01:18 Functions: 100.0 % 7 7

            Line data    Source code
       1              : // Tests for the semantic-executor structured error surface.
       2              : //
       3              : // The error surface is consumed by the coordinator / gateway to
       4              : // map evaluation failures onto BigQuery REST error envelopes, so
       5              : // the tests pin the public contracts (status code per reason,
       6              : // payload round-trip, REST reason token spelling) the gateway
       7              : // depends on.
       8              : 
       9              : #include "backend/engine/semantic/error.h"
      10              : 
      11              : #include "absl/status/status.h"
      12              : #include "gtest/gtest.h"
      13              : 
      14              : namespace bigquery_emulator {
      15              : namespace backend {
      16              : namespace engine {
      17              : namespace semantic {
      18              : namespace {
      19              : 
      20            1 : TEST(SemanticErrorTest, MakeSemanticErrorEncodesReasonPayload) {
      21            1 :   absl::Status status =
      22            1 :       MakeSemanticError(SemanticErrorReason::kDivisionByZero, "1 / 0");
      23            1 :   EXPECT_EQ(status.code(), absl::StatusCode::kInvalidArgument);
      24            1 :   EXPECT_EQ(GetSemanticErrorReason(status),
      25            1 :             SemanticErrorReason::kDivisionByZero);
      26            1 :   EXPECT_EQ(status.message(), "1 / 0");
      27            1 : }
      28              : 
      29            1 : TEST(SemanticErrorTest, NotImplementedReasonUsesUnimplementedCode) {
      30            1 :   absl::Status status = MakeSemanticError(SemanticErrorReason::kNotImplemented,
      31            1 :                                           "unimplemented op");
      32            1 :   EXPECT_EQ(status.code(), absl::StatusCode::kUnimplemented);
      33            1 :   EXPECT_EQ(GetSemanticErrorReason(status),
      34            1 :             SemanticErrorReason::kNotImplemented);
      35            1 : }
      36              : 
      37            1 : TEST(SemanticErrorTest, OverflowReasonRoundTrips) {
      38            1 :   absl::Status status =
      39            1 :       MakeSemanticError(SemanticErrorReason::kOverflow, "int64 overflow");
      40            1 :   EXPECT_EQ(GetSemanticErrorReason(status), SemanticErrorReason::kOverflow);
      41            1 : }
      42              : 
      43            1 : TEST(SemanticErrorTest, InvalidArgumentReasonRoundTrips) {
      44            1 :   absl::Status status =
      45            1 :       MakeSemanticError(SemanticErrorReason::kInvalidArgument, "bad operand");
      46            1 :   EXPECT_EQ(GetSemanticErrorReason(status),
      47            1 :             SemanticErrorReason::kInvalidArgument);
      48            1 : }
      49              : 
      50            1 : TEST(SemanticErrorTest, GetReasonOnOkStatusDefaultsToInvalidArgument) {
      51            1 :   EXPECT_EQ(GetSemanticErrorReason(absl::OkStatus()),
      52            1 :             SemanticErrorReason::kInvalidArgument);
      53            1 : }
      54              : 
      55            1 : TEST(SemanticErrorTest, GetReasonOnNonSemanticStatusDefaultsToInvalidArgument) {
      56            1 :   EXPECT_EQ(GetSemanticErrorReason(absl::InvalidArgumentError("plain status")),
      57            1 :             SemanticErrorReason::kInvalidArgument);
      58            1 : }
      59              : 
      60            1 : TEST(SemanticErrorTest, BigQueryReasonTokensAreStable) {
      61            1 :   EXPECT_EQ(BigQueryReasonToken(SemanticErrorReason::kInvalidArgument),
      62            1 :             "invalidQuery");
      63            1 :   EXPECT_EQ(BigQueryReasonToken(SemanticErrorReason::kDivisionByZero),
      64            1 :             "invalidQuery");
      65            1 :   EXPECT_EQ(BigQueryReasonToken(SemanticErrorReason::kOverflow),
      66            1 :             "invalidQuery");
      67            1 :   EXPECT_EQ(BigQueryReasonToken(SemanticErrorReason::kNotImplemented),
      68            1 :             "notImplemented");
      69            1 : }
      70              : 
      71              : }  // namespace
      72              : }  // namespace semantic
      73              : }  // namespace engine
      74              : }  // namespace backend
      75              : }  // namespace bigquery_emulator
        

Generated by: LCOV version 2.0-1