LCOV - code coverage report
Current view: top level - tests/src - prepare.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 63 63
Test Date: 2026-07-12 01:01:34 Functions: 100.0 % 1 1
Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : #include "sute.h"
       2                 :             : 
       3                 :             : /**
       4                 :             :  * @brief Prepare the test environment
       5                 :             :  *
       6                 :             :  * Initializes the temporary workspace and required environment variables
       7                 :             :  * so the test suite can run against a consistent isolated setup
       8                 :             :  *
       9                 :             :  * @return SUCCESS on success, FAILURE on error
      10                 :             :  */
      11                 :           1 : Return prepare(void)
      12                 :             : {
      13                 :             :         /* This function was reviewed line by line by a human and is not AI-generated
      14                 :             :            Any change to this function requires separate explicit approval */
      15                 :             : 
      16                 :           1 :         INITTEST;
      17                 :             : 
      18                 :           1 :         const char *environment_name = NULL;
      19                 :           1 :         struct utsname utsname = {0};
      20                 :             : 
      21                 :           1 :         m_create(char,path,MEMORY_STRING);
      22                 :           1 :         m_create(char,environment_build_path,MEMORY_STRING);
      23                 :           1 :         m_create(char,environment_precizer_path,MEMORY_STRING);
      24                 :             : 
      25                 :           1 :         ASSERT(SUCCESS == determine_origin_dir(path));
      26                 :           1 :         ASSERT(SUCCESS == set_environment_variable("ORIGIN_DIR",m_text(path)));
      27                 :           1 :         call(m_del(path));
      28                 :             : 
      29                 :           1 :         ASSERT(SUCCESS == create_tmpdir(path));
      30                 :           1 :         ASSERT(SUCCESS == set_environment_variable("TMPDIR",m_text(path)));
      31                 :           1 :         ASSERT(SUCCESS == set_environment_variable("BINDIR",m_text(path)));
      32                 :           1 :         call(m_del(path));
      33                 :             : 
      34                 :           1 :         ASSERT(SUCCESS == extract_current_executable_directory_name(path));
      35                 :           1 :         ASSERT(SUCCESS == set_environment_variable("ENVIRONMENT",m_text(path)));
      36                 :           1 :         call(m_del(path));
      37                 :             : 
      38                 :           1 :         ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
      39                 :           1 :         environment_name = getenv("ENVIRONMENT");
      40                 :           1 :         ASSERT(environment_name != NULL);
      41                 :             : 
      42                 :             :         // Build the expected default DB name from the same hostname source as the application
      43                 :           1 :         ASSERT(uname(&utsname) == 0);
      44                 :           1 :         ASSERT(SUCCESS == m_copy_string(path,utsname.nodename));
      45                 :           1 :         ASSERT(SUCCESS == m_concat_literal(path,".db"));
      46                 :           1 :         ASSERT(SUCCESS == set_environment_variable("DBNAME",m_text(path)));
      47                 :           1 :         call(m_del(path));
      48                 :             : 
      49                 :           1 :         ASSERT(SUCCESS == create_directory("tests/fixtures/diffs"));
      50                 :           1 :         ASSERT(SUCCESS == create_directory("tests/templates"));
      51                 :           1 :         ASSERT(SUCCESS == create_directory(".builds"));
      52                 :           1 :         ASSERT(SUCCESS == copy_from_origin("tests/fixtures/diffs/diff1","tests/fixtures/diffs/diff1",REQUIRE_SOURCE_EXISTS));
      53                 :           1 :         ASSERT(SUCCESS == copy_from_origin("tests/fixtures/diffs/diff2","tests/fixtures/diffs/diff2",REQUIRE_SOURCE_EXISTS));
      54                 :           1 :         ASSERT(SUCCESS == copy_from_origin("tests/fixtures/'apostrophe","tests/fixtures/'apostrophe",REQUIRE_SOURCE_EXISTS));
      55                 :           1 :         ASSERT(SUCCESS == copy_from_origin("tests/fixtures/apostrophe'","tests/fixtures/apostrophe'",REQUIRE_SOURCE_EXISTS));
      56                 :           1 :         ASSERT(SUCCESS == copy_from_origin("tests/fixtures/levels","tests/fixtures/levels",REQUIRE_SOURCE_EXISTS));
      57                 :           1 :         ASSERT(SUCCESS == copy_from_origin("tests/fixtures/4","tests/fixtures/4",REQUIRE_SOURCE_EXISTS));
      58                 :           1 :         ASSERT(SUCCESS == copy_from_origin("tests/fixtures/ignore_include_cases","tests/fixtures/ignore_include_cases",REQUIRE_SOURCE_EXISTS));
      59                 :           1 :         ASSERT(SUCCESS == copy_from_origin("tests/templates/0015_database_v0.db","tests/templates/0015_database_v0.db",REQUIRE_SOURCE_EXISTS));
      60                 :           1 :         ASSERT(SUCCESS == copy_from_origin("tests/templates/0015_database_v1.db","tests/templates/0015_database_v1.db",REQUIRE_SOURCE_EXISTS));
      61                 :           1 :         ASSERT(SUCCESS == copy_from_origin("tests/templates/0015_database_v2.db","tests/templates/0015_database_v2.db",REQUIRE_SOURCE_EXISTS));
      62                 :           1 :         ASSERT(SUCCESS == copy_from_origin("tests/templates/0015_database_v3 это база данных с пробелами и символами UTF-8.db","tests/templates/0015_database_v3 это база данных с пробелами и символами UTF-8.db",REQUIRE_SOURCE_EXISTS));
      63                 :           1 :         ASSERT(SUCCESS == copy_from_origin("tests/templates/0015_database_v4 это база данных с пробелами и символами UTF-8.db","tests/templates/0015_database_v4 это база данных с пробелами и символами UTF-8.db",REQUIRE_SOURCE_EXISTS));
      64                 :           1 :         ASSERT(SUCCESS == copy_from_origin("tests/fixtures/long","tests/fixtures/long",ALLOW_MISSING_SOURCE));
      65                 :           1 :         ASSERT(SUCCESS == m_copy_literal(environment_build_path,".builds/"));
      66                 :           1 :         ASSERT(SUCCESS == m_concat_string(environment_build_path,environment_name));
      67                 :           1 :         ASSERT(SUCCESS == copy_from_origin(m_text(environment_build_path),m_text(environment_build_path),ALLOW_MISSING_SOURCE));
      68                 :           1 :         ASSERT(SUCCESS == m_copy(environment_precizer_path,environment_build_path));
      69                 :           1 :         ASSERT(SUCCESS == m_concat_literal(environment_precizer_path,"/precizer"));
      70                 :           1 :         ASSERT(SUCCESS == copy_from_origin(m_text(environment_precizer_path),"precizer",ALLOW_MISSING_SOURCE));
      71                 :             : 
      72                 :           1 :         call(m_del(environment_precizer_path));
      73                 :           1 :         call(m_del(environment_build_path));
      74                 :             : 
      75                 :             :         // Bump diff2 fixture mtime relative to diff1 for stat-only test coverage
      76                 :           1 :         ASSERT(SUCCESS == touch_file_mtime_with_reference_delta_ns("tests/fixtures/diffs/diff1/1/AAA/BCB/CCC/a.txt","tests/fixtures/diffs/diff2/1/AAA/BCB/CCC/a.txt",999));
      77                 :           1 :         ASSERT(SUCCESS == touch_file_mtime_with_reference_delta_ns("tests/fixtures/diffs/diff1/1/AAA/ZAW/A/b/c/a_file.txt","tests/fixtures/diffs/diff2/1/AAA/ZAW/A/b/c/a_file.txt",999));
      78                 :           1 :         ASSERT(SUCCESS == touch_file_mtime_with_reference_delta_ns("tests/fixtures/diffs/diff1/1/AAA/ZAW/D/e/f/b_file.txt","tests/fixtures/diffs/diff2/1/AAA/ZAW/D/e/f/b_file.txt",999));
      79                 :           1 :         ASSERT(SUCCESS == touch_file_mtime_with_reference_delta_ns("tests/fixtures/diffs/diff1/path1/AAA/BCB/CCC/a.txt","tests/fixtures/diffs/diff2/path1/AAA/BCB/CCC/a.txt",999));
      80                 :           1 :         ASSERT(SUCCESS == touch_file_mtime_with_reference_delta_ns("tests/fixtures/diffs/diff1/path1/AAA/ZAW/A/b/c/a_file.txt","tests/fixtures/diffs/diff2/path1/AAA/ZAW/A/b/c/a_file.txt",999));
      81                 :           1 :         ASSERT(SUCCESS == touch_file_mtime_with_reference_delta_ns("tests/fixtures/diffs/diff1/path2/AAA/ZAW/A/b/c/a_file.txt","tests/fixtures/diffs/diff2/path2/AAA/ZAW/A/b/c/a_file.txt",999));
      82                 :             : 
      83                 :           1 :         bool file_exists = false;
      84                 :             : 
      85                 :           1 :         m_create(char,absolute_path,MEMORY_STRING);
      86                 :             : 
      87                 :           1 :         const char *filename = "precizer";
      88                 :             : 
      89                 :           1 :         ASSERT(SUCCESS == construct_path(filename,absolute_path));
      90                 :             : 
      91                 :           1 :         ASSERT(SUCCESS == check_file_exists(&file_exists,m_text(absolute_path)));
      92                 :             : 
      93                 :           1 :         call(m_del(absolute_path));
      94                 :             : 
      95                 :           1 :         ASSERT(file_exists == true);
      96                 :             : 
      97                 :             :         /* Enable UTF-8 */
      98                 :             : #if 0
      99                 :             :         ASSERT(SUCCESS == set_environment_variable("LC_ALL","C.UTF-8"));
     100                 :             :         ASSERT(SUCCESS == set_environment_variable("LANG","C.UTF-8"));
     101                 :             : #endif
     102                 :             : 
     103                 :           1 :         RETURN_STATUS;
     104                 :             : }
        

Generated by: LCOV version 2.0-1