LCOV - code coverage report
Current view: top level - tests/functional/pty - rl_harness.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 11 11
Test Date: 2026-04-20 19:54:22 Functions: 100.0 % 1 1

            Line data    Source code
       1              : /* SPDX-License-Identifier: GPL-3.0-or-later */
       2              : /* Copyright 2026 Peter Csaszar */
       3              : 
       4              : /**
       5              :  * @file rl_harness.c
       6              :  * @brief Minimal driver for rl_readline used by PTY-03 tests.
       7              :  *
       8              :  * Runs rl_readline in a loop until Ctrl-D / EOF.
       9              :  * Each accepted line is echoed as:  "ACCEPTED:<line>\n"
      10              :  * so the test can wait for that sentinel.
      11              :  *
      12              :  * Usage:  rl_harness
      13              :  *
      14              :  * The process exits 0 after Ctrl-D on an empty line.
      15              :  */
      16              : 
      17              : #include "readline.h"
      18              : 
      19              : #include <stdio.h>
      20              : #include <string.h>
      21              : #include <stdlib.h>
      22              : 
      23              : #define BUF_SIZE 256
      24              : 
      25           10 : int main(void) {
      26              :     LineHistory hist;
      27           10 :     rl_history_init(&hist);
      28              : 
      29              :     char buf[BUF_SIZE];
      30           10 :     for (;;) {
      31           20 :         int rc = rl_readline("rl> ", buf, sizeof(buf), &hist);
      32           20 :         if (rc < 0) {
      33              :             /* Ctrl-C or EOF on empty line */
      34           10 :             break;
      35              :         }
      36           10 :         if (rc > 0) {
      37           10 :             rl_history_add(&hist, buf);
      38              :         }
      39              :         /* Always print the accepted line so the test can observe it. */
      40           10 :         printf("ACCEPTED:%s\n", buf);
      41           10 :         fflush(stdout);
      42              :     }
      43           10 :     return 0;
      44              : }
        

Generated by: LCOV version 2.0-1