LCOV - code coverage report
Current view: top level - tests - catch_isatty.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 18 22 81.8 %
Date: 2022-07-09 19:51:09 Functions: 3 3 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : // Copyright (c) 2018-2022  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 2 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 along
      17             : // with this program; if not, write to the Free Software Foundation, Inc.,
      18             : // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
      19             : 
      20             : /** \file
      21             :  * \brief Verify that the mkdir_p() function works.
      22             :  *
      23             :  * This file implements tests for the mkdir_p() function.
      24             :  */
      25             : 
      26             : // self
      27             : //
      28             : #include    <snapdev/isatty.h>
      29             : 
      30             : #include    "catch_main.h"
      31             : 
      32             : 
      33             : // C
      34             : //
      35             : //#include    <unistd.h>
      36             : 
      37             : 
      38             : // last include
      39             : //
      40             : #include    <snapdev/poison.h>
      41             : 
      42             : 
      43             : 
      44             : 
      45           5 : CATCH_TEST_CASE("isatty", "[os]")
      46             : {
      47           6 :     CATCH_START_SECTION("isatty: stringstream")
      48             :     {
      49           2 :         std::stringstream ss;
      50           1 :         CATCH_REQUIRE_FALSE(snapdev::isatty(ss));
      51             :     }
      52             :     CATCH_END_SECTION()
      53             : 
      54           6 :     CATCH_START_SECTION("isatty: cout/cerr/clog/cin")
      55             :     {
      56             :         // while running in a console, these work as expected (u.e. they
      57             :         // are TTYs) but when running the coverage test, we also pipe the
      58             :         // output to a file and it means stdout and stderr are not TTYs
      59             :         //
      60           1 :         if(isatty(fileno(stdin)))
      61             :         {
      62           1 :             CATCH_REQUIRE(snapdev::isatty(std::cin));
      63             :         }
      64             :         else
      65             :         {
      66           0 :             CATCH_REQUIRE_FALSE(snapdev::isatty(std::cin));
      67             :         }
      68           1 :         if(isatty(fileno(stdout)))
      69             :         {
      70           0 :             CATCH_REQUIRE(snapdev::isatty(std::cout));
      71             :         }
      72             :         else
      73             :         {
      74           1 :             CATCH_REQUIRE_FALSE(snapdev::isatty(std::cout));
      75             :         }
      76           1 :         if(isatty(fileno(stderr)))
      77             :         {
      78           0 :             CATCH_REQUIRE(snapdev::isatty(std::cerr));
      79           0 :             CATCH_REQUIRE(snapdev::isatty(std::clog));
      80             :         }
      81             :         else
      82             :         {
      83           1 :             CATCH_REQUIRE_FALSE(snapdev::isatty(std::cerr));
      84           1 :             CATCH_REQUIRE_FALSE(snapdev::isatty(std::clog));
      85             :         }
      86             :     }
      87             :     CATCH_END_SECTION()
      88             : 
      89           6 :     CATCH_START_SECTION("isatty: /dev/tty")
      90             :     {
      91           2 :         std::fstream out;
      92           1 :         out.open("/dev/tty");
      93           1 :         CATCH_REQUIRE(out.is_open());
      94           1 :         CATCH_REQUIRE(snapdev::isatty(out));
      95             :     }
      96             :     CATCH_END_SECTION()
      97           9 : }
      98             : 
      99             : 
     100             : 
     101             : // vim: ts=4 sw=4 et

Generated by: LCOV version 1.13