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 : :
20 : 1 : create(char,path);
21 : 1 : create(char,environment_build_path);
22 : 1 : create(char,environment_precizer_path);
23 : :
24 : 1 : ASSERT(SUCCESS == get_origin_dir(path));
25 : 1 : ASSERT(SUCCESS == set_environment_variable("ORIGIN_DIR",getcstring(path)));
26 [ - + - + ]: 1 : call(del(path));
27 : :
28 : 1 : ASSERT(SUCCESS == create_tmpdir(path));
29 : 1 : ASSERT(SUCCESS == set_environment_variable("TMPDIR",getcstring(path)));
30 : 1 : ASSERT(SUCCESS == set_environment_variable("BINDIR",getcstring(path)));
31 [ - + - + ]: 1 : call(del(path));
32 : :
33 : 1 : ASSERT(SUCCESS == extract_current_executable_directory_name(path));
34 : 1 : ASSERT(SUCCESS == set_environment_variable("ENVIRONMENT",getcstring(path)));
35 [ - + - + ]: 1 : call(del(path));
36 : :
37 : 1 : ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
38 : 1 : environment_name = getenv("ENVIRONMENT");
39 : 1 : ASSERT(environment_name != NULL);
40 : :
41 : 1 : ASSERT(SUCCESS == execute_and_set_variable("DBNAME","echo \"$(hostname).db\"",0));
42 : :
43 : 1 : ASSERT(SUCCESS == create_directory("tests/fixtures/diffs"));
44 : 1 : ASSERT(SUCCESS == create_directory("tests/templates"));
45 : 1 : ASSERT(SUCCESS == create_directory(".builds"));
46 : 1 : ASSERT(SUCCESS == copy_from_origin("tests/fixtures/diffs/diff1","tests/fixtures/diffs/diff1",REQUIRE_SOURCE_EXISTS));
47 : 1 : ASSERT(SUCCESS == copy_from_origin("tests/fixtures/diffs/diff2","tests/fixtures/diffs/diff2",REQUIRE_SOURCE_EXISTS));
48 : 1 : ASSERT(SUCCESS == copy_from_origin("tests/fixtures/'apostrophe","tests/fixtures/'apostrophe",REQUIRE_SOURCE_EXISTS));
49 : 1 : ASSERT(SUCCESS == copy_from_origin("tests/fixtures/apostrophe'","tests/fixtures/apostrophe'",REQUIRE_SOURCE_EXISTS));
50 : 1 : ASSERT(SUCCESS == copy_from_origin("tests/fixtures/levels","tests/fixtures/levels",REQUIRE_SOURCE_EXISTS));
51 : 1 : ASSERT(SUCCESS == copy_from_origin("tests/fixtures/4","tests/fixtures/4",REQUIRE_SOURCE_EXISTS));
52 : 1 : ASSERT(SUCCESS == copy_from_origin("tests/fixtures/ignore_include_cases","tests/fixtures/ignore_include_cases",REQUIRE_SOURCE_EXISTS));
53 : 1 : ASSERT(SUCCESS == copy_from_origin("tests/templates/0015_database_v0.db","tests/templates/0015_database_v0.db",REQUIRE_SOURCE_EXISTS));
54 : 1 : ASSERT(SUCCESS == copy_from_origin("tests/templates/0015_database_v1.db","tests/templates/0015_database_v1.db",REQUIRE_SOURCE_EXISTS));
55 : 1 : ASSERT(SUCCESS == copy_from_origin("tests/templates/0015_database_v2.db","tests/templates/0015_database_v2.db",REQUIRE_SOURCE_EXISTS));
56 : 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));
57 : 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));
58 : 1 : ASSERT(SUCCESS == copy_from_origin("tests/fixtures/long","tests/fixtures/long",ALLOW_MISSING_SOURCE));
59 : 1 : ASSERT(SUCCESS == copy_literal(environment_build_path,".builds/"));
60 : 1 : ASSERT(SUCCESS == concat_literal(environment_build_path,environment_name));
61 : 1 : ASSERT(SUCCESS == copy_from_origin(getcstring(environment_build_path),getcstring(environment_build_path),ALLOW_MISSING_SOURCE));
62 : 1 : ASSERT(SUCCESS == copy(environment_precizer_path,environment_build_path));
63 : 1 : ASSERT(SUCCESS == concat_literal(environment_precizer_path,"/precizer"));
64 : 1 : ASSERT(SUCCESS == copy_from_origin(getcstring(environment_precizer_path),"precizer",ALLOW_MISSING_SOURCE));
65 : :
66 [ - + - + ]: 1 : call(del(environment_precizer_path));
67 [ - + - + ]: 1 : call(del(environment_build_path));
68 : :
69 : : // Bump diff2 fixture mtime relative to diff1 for stat-only test coverage
70 : 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));
71 : 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));
72 : 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));
73 : 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));
74 : 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));
75 : 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));
76 : :
77 : 1 : bool file_exists = false;
78 : :
79 : 1 : create(char,absolute_path);
80 : :
81 : 1 : const char *filename = "precizer";
82 : :
83 : 1 : ASSERT(SUCCESS == construct_path(filename,absolute_path));
84 : :
85 : 1 : ASSERT(SUCCESS == check_file_exists(&file_exists,getcstring(absolute_path)));
86 : :
87 [ - + - + ]: 1 : call(del(absolute_path));
88 : :
89 : 1 : ASSERT(file_exists == true);
90 : :
91 : : /* Enable UTF-8 */
92 : : #if 0
93 : : ASSERT(SUCCESS == set_environment_variable("LC_ALL","C.UTF-8"));
94 : : ASSERT(SUCCESS == set_environment_variable("LANG","C.UTF-8"));
95 : : #endif
96 : :
97 : 1 : RETURN_STATUS;
98 : : }
|