gitout

A static git page generator
git clone https://git.bracken.jp/gitout.git
Log | Files | Refs | README | LICENSE

main.c (3459B)


      1 // This is free and unencumbered software released into the public domain.
      2 //
      3 // Anyone is free to copy, modify, publish, use, compile, sell, or
      4 // distribute this software, either in source code form or as a compiled
      5 // binary, for any purpose, commercial or non-commercial, and by any
      6 // means.
      7 //
      8 // In jurisdictions that recognize copyright laws, the author or authors
      9 // of this software dedicate any and all copyright interest in the
     10 // software to the public domain. We make this dedication for the benefit
     11 // of the public at large and to the detriment of our heirs and
     12 // successors. We intend this dedication to be an overt act of
     13 // relinquishment in perpetuity of all present and future rights to this
     14 // software under copyright law.
     15 //
     16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
     17 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
     18 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
     19 // IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
     20 // OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
     21 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
     22 // OTHER DEALINGS IN THE SOFTWARE.
     23 //
     24 // For more information, please refer to <http://unlicense.org/>
     25 
     26 #include "utest.h"
     27 
     28 // TODO: Fix in subprocess.h!
     29 #if defined(__clang__)
     30 #if __has_warning("-Wunsafe-buffer-usage")
     31 #pragma clang diagnostic push
     32 #pragma clang diagnostic ignored "-Wunsafe-buffer-usage"
     33 #endif
     34 #endif
     35 
     36 #include "subprocess.h"
     37 
     38 // TODO: Broken under MINGW for some reason.
     39 #if !(defined(__MINGW32__) || defined(__MINGW64__))
     40 UTEST(utest_cmdline, filter_with_list) {
     41   struct subprocess_s process;
     42   const char *command[3] = {"utest_test", "--list-tests", 0};
     43   int return_code;
     44   FILE *stdout_file;
     45   size_t index, kndex;
     46   char *hits;
     47 
     48 // 64k should be enough for anyone
     49 #define MAX_CHARS (64 * 1024)
     50   char buffer[MAX_CHARS] = {0};
     51 
     52   hits = (char *)malloc(utest_state.tests_length);
     53   memset(hits, 0, utest_state.tests_length);
     54 
     55   ASSERT_EQ(0,
     56             subprocess_create(command, subprocess_option_combined_stdout_stderr,
     57                               &process));
     58 
     59   stdout_file = subprocess_stdout(&process);
     60 
     61   for (index = 0; index < utest_state.tests_length; index++) {
     62     if (buffer != fgets(buffer, MAX_CHARS, stdout_file)) {
     63       break;
     64     }
     65 
     66 #if defined(__clang__)
     67 #if __has_warning("-Wdisabled-macro-expansion")
     68 #pragma clang diagnostic push
     69 #pragma clang diagnostic ignored "-Wdisabled-macro-expansion"
     70 #endif
     71 #endif
     72 
     73     // First wipe out the newlines from the fgets.
     74     for (kndex = 0;; kndex++) {
     75       if ((buffer[kndex] == '\r') || (buffer[kndex] == '\n')) {
     76         buffer[kndex] = '\0';
     77         break;
     78       }
     79     }
     80 
     81     // Record the hit for listed test.
     82     for (kndex = 0; kndex < utest_state.tests_length; kndex++) {
     83       if (0 == strcmp(buffer, utest_state.tests[kndex].name)) {
     84         ASSERT_EQ(hits[kndex], 0);
     85         hits[kndex] = 1;
     86         break;
     87       }
     88     }
     89 
     90 #if defined(__clang__)
     91 #if __has_warning("-Wdisabled-macro-expansion")
     92 #pragma clang diagnostic pop
     93 #endif
     94 #endif
     95   }
     96 
     97   ASSERT_EQ(0, subprocess_join(&process, &return_code));
     98   ASSERT_EQ(0, return_code);
     99 
    100   ASSERT_EQ(0, subprocess_destroy(&process));
    101 
    102   // Run through all the hits and make sure we got exactly one for each.
    103   for (kndex = 0; kndex < utest_state.tests_length; kndex++) {
    104     ASSERT_EQ(hits[kndex], 1);
    105   }
    106 
    107   free(hits);
    108 }
    109 #endif
    110 
    111 UTEST_MAIN()