Skip to content

No prints to stdout when using --report-json#108

Merged
ThoSe1990 merged 5 commits into
mainfrom
fix/json-prints
Jan 15, 2026
Merged

No prints to stdout when using --report-json#108
ThoSe1990 merged 5 commits into
mainfrom
fix/json-prints

Conversation

@ThoSe1990
Copy link
Copy Markdown
Owner

@ThoSe1990 ThoSe1990 commented Jan 15, 2026

In order to pipe the json output, disable prints to stdout when using --report-json. Only the json result should be on stdout. For simplification, when printing the output to a file, no output is on stdout from Cucumber.

Summary by CodeRabbit

  • Bug Fixes

    • When using --report-json, stdout now contains only the JSON report; no extra output is printed alongside it.
    • Writing results to stdout (empty filepath) now emits raw JSON/plain output directly to stdout.
  • Behavior Changes

    • Logging is automatically suppressed when JSON reporting is requested so reports remain clean.
  • Tests

    • Added tests verifying suppressed logging and JSON-only stdout behavior.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jan 15, 2026

📝 Walkthrough

Walkthrough

Logging and stdout handling were changed so that when --report-json is used normal logger output is suppressed and only the JSON report is emitted to stdout; API additions include log::report, log::disable() / log::enable(), and log::to_stdout(). Tests and build flags for JSON support were added.

Changes

Cohort / File(s) Summary
Logging API Redesign
src/log.hpp
Replaced level::always with level::report; renamed logger::always()logger::report(); added logger::disable() / logger::enable() and private m_disabled; added free helpers disable(), enable(), and to_stdout()
Logging Integration
src/cucumber.cpp
Switched log::always(...) calls to log::report(...) in print_failed_scenarios() and print_results() to use the new report-level API
Option Handling
src/options.cpp
When --report-json is set, call cuke::log::disable() during argument initialization to suppress normal logger output
Output Routing
src/util.hpp
Empty-filepath case now writes with cuke::log::to_stdout(...) (direct stdout) instead of cuke::log::info(...)
Test Coverage
gtest/stdout_print.cc
Added tests log_disabled() and log_disabled_w_json_output() (JSON parsing under WITH_JSON); adjusted TearDown to reset logging; removed direct printing of captured stdout in one test path
Build Configuration
gtest/CMakeLists.txt
Added find_package(nlohmann_json); linked nlohmann_json::nlohmann_json; added add_compile_definitions(WITH_JSON) to enable JSON test paths
Changelog
CHANGELOG.md
Added Fixed entry documenting that --report-json causes only the JSON report to be printed to stdout (no additional stdout prints)

Sequence Diagram(s)

sequenceDiagram
  actor User
  participant CLI
  participant Options
  participant Logger
  participant App
  participant Stdout

  User->>CLI: invoke with --report-json
  CLI->>Options: parse args
  Options->>Logger: disable()
  App->>Logger: emit report-level logs (suppressed)
  App->>Stdout: write JSON via to_stdout() (or write to file)
  Stdout-->>User: only JSON printed to stdout
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related issues

Poem

🐰
I nibbled through logs at break of day,
When JSON's asked, the chatter hopped away.
Only tidy bytes now bound for stdout's shore,
No extra rustle—just data galore. 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'No prints to stdout when using --report-json' directly and clearly summarizes the main change: disabling stdout output when the --report-json option is used, which is the core purpose of this PR.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings


📜 Recent review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8946767 and 3b29b08.

📒 Files selected for processing (1)
  • gtest/stdout_print.cc
🚧 Files skipped from review as they are similar to previous changes (1)
  • gtest/stdout_print.cc
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: Windows
  • GitHub Check: Mac
  • GitHub Check: Linux (clang-17, clang++-17, -pr clang)
  • GitHub Check: Linux (gcc, g++)

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@ThoSe1990 ThoSe1990 marked this pull request as ready for review January 15, 2026 06:44
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@CHANGELOG.md`:
- Line 11: Fix the typo in the CHANGELOG entry by replacing "Cuucmber" with
"Cucumber" in the line that reads "Removed Cuucmber prints to `stdout` when
using `--report-json`..." so the sentence reads "Removed Cucumber prints to
`stdout` when using `--report-json`..." and keep the rest of the text unchanged.
🧹 Nitpick comments (3)
gtest/CMakeLists.txt (2)

4-4: Consider adding REQUIRED or handling missing dependency gracefully.

If nlohmann_json is not found, the build will fail with a confusing linker error. Either mark it as REQUIRED to get a clear error message, or wrap the JSON-dependent functionality in a conditional.

💡 Suggested fix
-find_package(nlohmann_json)
+find_package(nlohmann_json REQUIRED)

45-45: add_compile_definitions without target scope affects all targets.

add_compile_definitions(WITH_JSON) applies globally to all targets in this directory and below. Use target_compile_definitions to scope it to the test target only.

💡 Suggested fix
  target_link_libraries(${target} cucumber-no-main GTest::gtest_main nlohmann_json::nlohmann_json)
-  add_compile_definitions(WITH_JSON)
+  target_compile_definitions(${target} PRIVATE WITH_JSON)
gtest/stdout_print.cc (1)

6-9: Inconsistent include path for report.hpp.

The include at line 9 uses "report.hpp" while lines 6-7 use "../src/log.hpp" and "../src/options.hpp". For consistency with the rest of the file, consider using the full relative path.

♻️ Suggested fix
 `#include` "../src/log.hpp"
 `#include` "../src/options.hpp"

-#include "report.hpp"
+#include "../src/report.hpp"
 `#include` "test_paths.hpp"
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6fcb51d and 0052ca1.

📒 Files selected for processing (7)
  • CHANGELOG.md
  • gtest/CMakeLists.txt
  • gtest/stdout_print.cc
  • src/cucumber.cpp
  • src/log.hpp
  • src/options.cpp
  • src/util.hpp
🧰 Additional context used
🧬 Code graph analysis (5)
src/util.hpp (1)
src/log.hpp (2)
  • to_stdout (144-147)
  • to_stdout (144-144)
src/log.hpp (1)
gtest/stdout_print.cc (1)
  • args (19-24)
src/options.cpp (1)
src/log.hpp (2)
  • disable (107-107)
  • disable (107-107)
src/cucumber.cpp (2)
src/log.hpp (10)
  • report (66-69)
  • report (66-66)
  • report (118-121)
  • report (118-118)
  • red (164-167)
  • red (164-164)
  • black (172-175)
  • black (172-172)
  • reset (152-155)
  • reset (152-152)
src/test_results.cpp (4)
  • scenarios_to_string (107-154)
  • scenarios_to_string (107-107)
  • steps_to_string (156-216)
  • steps_to_string (156-156)
gtest/stdout_print.cc (5)
src/options.cpp (2)
  • get_program_args (252-261)
  • get_program_args (252-253)
src/options.hpp (2)
  • get_program_args (168-169)
  • argc (145-145)
src/log.hpp (6)
  • enable (47-47)
  • enable (47-47)
  • enable (108-108)
  • enable (108-108)
  • disable (107-107)
  • disable (107-107)
gtest/run_scenarios_continue.cc (1)
  • maybe_unused (39-44)
src/report.cpp (2)
  • print_json_to_sink (142-146)
  • print_json_to_sink (142-142)
🪛 LanguageTool
CHANGELOG.md

[grammar] ~11-~11: Ensure spelling is correct
Context: ...r/pull/107))

Fixed

  • Removed Cuucmber prints to stdout when using `--report...

(QB_NEW_EN_ORTHOGRAPHY_ERROR_IDS_1)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: Linux (clang-17, clang++-17, -pr clang)
  • GitHub Check: Windows
  • GitHub Check: Mac
  • GitHub Check: Linux (gcc, g++)
🔇 Additional comments (9)
src/log.hpp (2)

44-45: Thread safety consideration for m_disabled flag.

If the logger is accessed from multiple threads, reads/writes to m_disabled could race. For this use case (set once at startup before concurrent logging), it's likely fine, but consider using std::atomic<bool> if thread safety is a concern.

Also applies to: 103-103


141-147: Clean design for bypassing logger settings.

The to_stdout() function correctly writes directly to stdout without checking the disabled state, which is exactly what's needed for JSON output when logging is disabled. This enables the PR goal of clean JSON piping.

src/util.hpp (1)

30-33: Correct use of to_stdout() for stdout output path.

This change ensures that when outputting to stdout (empty filepath), the data bypasses the logger's disabled state, enabling JSON output to work correctly when --report-json is used without a file path.

src/options.cpp (1)

137-148: Logic for --report-json disabling logs looks correct.

When --report-json is set, logging is disabled before any level adjustments. This means --quiet or --verbose flags have no effect when --report-json is active, which aligns with the PR goal of producing only JSON output.

src/cucumber.cpp (2)

27-35: LGTM!

The migration from log::always to log::report is consistent with the PR objectives. The separate calls maintain the existing pattern and allow the logger's disabled state to suppress all output when --report-json is active.


68-80: LGTM!

The branching logic correctly separates JSON output (via report::print_json_to_sink()) from human-readable output (via log::report). When --report-json is set, only JSON is produced; otherwise, the failed scenarios and summary statistics are printed.

gtest/stdout_print.cc (3)

19-24: Good addition to restore logging state in TearDown.

Calling cuke::log::enable() ensures tests that disable logging don't affect subsequent tests. This prevents test pollution and maintains test isolation.


432-449: LGTM!

The test correctly verifies that cuke::log::disable() suppresses all stdout output during test execution. The TearDown will re-enable logging for subsequent tests.


450-488: LGTM!

The test verifies two key behaviors:

  1. When --report-json is set, regular logging output is suppressed (empty stdout during test run)
  2. Calling print_json_to_sink() produces valid, parseable JSON

The approach of capturing stdout twice (once for the test run, once for JSON output) cleanly validates both requirements.

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.

Comment thread CHANGELOG.md Outdated
@ThoSe1990 ThoSe1990 merged commit 034982d into main Jan 15, 2026
6 checks passed
@ThoSe1990 ThoSe1990 deleted the fix/json-prints branch January 15, 2026 12:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant