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(".builds"));
51 : 1 : ASSERT(SUCCESS == copy_from_origin("tests/fixtures/diffs/diff1","tests/fixtures/diffs/diff1",REQUIRE_SOURCE_EXISTS));
52 : 1 : ASSERT(SUCCESS == copy_from_origin("tests/fixtures/diffs/diff2","tests/fixtures/diffs/diff2",REQUIRE_SOURCE_EXISTS));
53 : 1 : ASSERT(SUCCESS == copy_from_origin("tests/fixtures/'apostrophe","tests/fixtures/'apostrophe",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/levels","tests/fixtures/levels",REQUIRE_SOURCE_EXISTS));
56 : 1 : ASSERT(SUCCESS == copy_from_origin("tests/fixtures/4","tests/fixtures/4",REQUIRE_SOURCE_EXISTS));
57 : 1 : ASSERT(SUCCESS == copy_from_origin("tests/fixtures/ignore_include_cases","tests/fixtures/ignore_include_cases",REQUIRE_SOURCE_EXISTS));
58 : 1 : ASSERT(SUCCESS == copy_from_origin("tests/templates","tests/templates",REQUIRE_SOURCE_EXISTS));
59 : 1 : ASSERT(SUCCESS == copy_from_origin("tests/fixtures/long","tests/fixtures/long",ALLOW_MISSING_SOURCE));
60 : 1 : ASSERT(SUCCESS == m_copy_literal(environment_build_path,".builds/"));
61 : 1 : ASSERT(SUCCESS == m_concat_string(environment_build_path,environment_name));
62 : 1 : ASSERT(SUCCESS == copy_from_origin(m_text(environment_build_path),m_text(environment_build_path),ALLOW_MISSING_SOURCE));
63 : 1 : ASSERT(SUCCESS == m_copy(environment_precizer_path,environment_build_path));
64 : 1 : ASSERT(SUCCESS == m_concat_literal(environment_precizer_path,"/precizer"));
65 : 1 : ASSERT(SUCCESS == copy_from_origin(m_text(environment_precizer_path),"precizer",ALLOW_MISSING_SOURCE));
66 : :
67 : 1 : call(m_del(environment_precizer_path));
68 : 1 : call(m_del(environment_build_path));
69 : :
70 : 1 : bool file_exists = false;
71 : :
72 : 1 : m_create(char,absolute_path,MEMORY_STRING);
73 : :
74 : 1 : const char *filename = "precizer";
75 : :
76 : 1 : ASSERT(SUCCESS == construct_path(filename,absolute_path));
77 : :
78 : 1 : ASSERT(SUCCESS == check_file_exists(&file_exists,m_text(absolute_path)));
79 : :
80 : 1 : call(m_del(absolute_path));
81 : :
82 : 1 : ASSERT(file_exists == true);
83 : :
84 : : /* Enable UTF-8 */
85 : : #if 0
86 : : ASSERT(SUCCESS == set_environment_variable("LC_ALL","C.UTF-8"));
87 : : ASSERT(SUCCESS == set_environment_variable("LANG","C.UTF-8"));
88 : : #endif
89 : :
90 : 1 : RETURN_STATUS;
91 : : }
|