LCOV - code coverage report
Current view: top level - tests - catch_isatty.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 23 27 85.2 %
Date: 2024-01-13 16:46:58 Functions: 1 1 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : // Copyright (c) 2018-2024  Made to Order Software Corp.  All Rights Reserved
       2             : //
       3             : // https://snapwebsites.org/project/snapdev
       4             : // contact@m2osw.com
       5             : //
       6             : // This program is free software: you can redistribute it and/or modify
       7             : // it under the terms of the GNU General Public License as published by
       8             : // the Free Software Foundation, either version 3 of the License, or
       9             : // (at your option) any later version.
      10             : //
      11             : // This program is distributed in the hope that it will be useful,
      12             : // but WITHOUT ANY WARRANTY; without even the implied warranty of
      13             : // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14             : // GNU General Public License for more details.
      15             : //
      16             : // You should have received a copy of the GNU General Public License
      17             : // along with this program.  If not, see <https://www.gnu.org/licenses/>.
      18             : 
      19             : /** \file
      20             :  * \brief Verify that the mkdir_p() function works.
      21             :  *
      22             :  * This file implements tests for the mkdir_p() function.
      23             :  */
      24             : 
      25             : // self
      26             : //
      27             : #include    <snapdev/isatty.h>
      28             : 
      29             : #include    "catch_main.h"
      30             : 
      31             : 
      32             : // C
      33             : //
      34             : //#include    <unistd.h>
      35             : 
      36             : 
      37             : // last include
      38             : //
      39             : #include    <snapdev/poison.h>
      40             : 
      41             : 
      42             : 
      43             : 
      44           3 : CATCH_TEST_CASE("isatty", "[os]")
      45             : {
      46           3 :     CATCH_START_SECTION("isatty: stringstream")
      47             :     {
      48           1 :         std::stringstream ss;
      49           1 :         CATCH_REQUIRE_FALSE(snapdev::isatty(ss));
      50           1 :     }
      51           3 :     CATCH_END_SECTION()
      52             : 
      53           3 :     CATCH_START_SECTION("isatty: cout/cerr/clog/cin")
      54             :     {
      55             :         // while running in a console, these work as expected (u.e. they
      56             :         // are TTYs) but when running the coverage test, we also pipe the
      57             :         // output to a file and it means stdout and stderr are not TTYs
      58             :         //
      59           1 :         if(isatty(fileno(stdin)))
      60             :         {
      61           1 :             CATCH_REQUIRE(snapdev::isatty(std::cin));
      62             :         }
      63             :         else
      64             :         {
      65           0 :             CATCH_REQUIRE_FALSE(snapdev::isatty(std::cin));
      66             :         }
      67           1 :         if(isatty(fileno(stdout)))
      68             :         {
      69           0 :             CATCH_REQUIRE(snapdev::isatty(std::cout));
      70             :         }
      71             :         else
      72             :         {
      73           1 :             CATCH_REQUIRE_FALSE(snapdev::isatty(std::cout));
      74             :         }
      75           1 :         if(isatty(fileno(stderr)))
      76             :         {
      77           0 :             CATCH_REQUIRE(snapdev::isatty(std::cerr));
      78           0 :             CATCH_REQUIRE(snapdev::isatty(std::clog));
      79             :         }
      80             :         else
      81             :         {
      82           1 :             CATCH_REQUIRE_FALSE(snapdev::isatty(std::cerr));
      83           1 :             CATCH_REQUIRE_FALSE(snapdev::isatty(std::clog));
      84             :         }
      85             :     }
      86           3 :     CATCH_END_SECTION()
      87             : 
      88           3 :     CATCH_START_SECTION("isatty: /dev/tty")
      89             :     {
      90           1 :         std::fstream out;
      91           1 :         out.open("/dev/tty");
      92           1 :         CATCH_REQUIRE(out.is_open());
      93           1 :         CATCH_REQUIRE(snapdev::isatty(out));
      94           1 :     }
      95           3 :     CATCH_END_SECTION()
      96           3 : }
      97             : 
      98             : 
      99             : 
     100             : // vim: ts=4 sw=4 et

Generated by: LCOV version 1.14

Snap C++ | List of projects | List of versions