@@ -9,10 +9,9 @@ namespace fs = std::filesystem;
99
1010static void test_minimal_config () {
1111 common_params params;
12-
1312 fs::path temp_dir = fs::temp_directory_path () / " llama_test" ;
1413 fs::create_directories (temp_dir);
15-
14+
1615 std::string config_content = R"(
1716model:
1817 path: test_model.gguf
@@ -24,47 +23,45 @@ prompt: "Test prompt"
2423n_predict: 64
2524simple_io: true
2625)" ;
27-
26+
2827 fs::path config_path = temp_dir / " test_config.yaml" ;
2928 std::ofstream config_file (config_path);
3029 config_file << config_content;
3130 config_file.close ();
32-
31+
3332 bool result = common_load_yaml_config (config_path.string (), params);
3433 assert (result);
3534 (void )result;
36-
35+
3736 assert (params.model .path == (temp_dir / " test_model.gguf" ).string ());
3837 assert (params.n_ctx == 512 );
3938 assert (params.sampling .seed == 123 );
4039 assert (params.sampling .temp == 0 .5f );
4140 assert (params.prompt == " Test prompt" );
4241 assert (params.n_predict == 64 );
4342 assert (params.simple_io == true );
44-
4543 fs::remove_all (temp_dir);
46-
44+
4745 std::cout << " test_minimal_config: PASSED\n " ;
4846}
4947
5048static void test_unknown_key_error () {
5149 common_params params;
52-
5350 fs::path temp_dir = fs::temp_directory_path () / " llama_test" ;
5451 fs::create_directories (temp_dir);
55-
52+
5653 std::string config_content = R"(
5754model:
5855 path: test_model.gguf
5956unknown_key: "should fail"
6057n_ctx: 512
6158)" ;
62-
59+
6360 fs::path config_path = temp_dir / " test_config.yaml" ;
6461 std::ofstream config_file (config_path);
6562 config_file << config_content;
6663 config_file.close ();
67-
64+
6865 bool threw_exception = false ;
6966 try {
7067 common_load_yaml_config (config_path.string (), params);
@@ -74,45 +71,42 @@ n_ctx: 512
7471 assert (error_msg.find (" Unknown YAML keys" ) != std::string::npos);
7572 assert (error_msg.find (" valid keys are" ) != std::string::npos);
7673 }
77-
74+
7875 assert (threw_exception);
7976 (void )threw_exception;
80-
8177 fs::remove_all (temp_dir);
82-
78+
8379 std::cout << " test_unknown_key_error: PASSED\n " ;
8480}
8581
8682static void test_relative_path_resolution () {
8783 common_params params;
88-
8984 fs::path temp_dir = fs::temp_directory_path () / " llama_test" ;
9085 fs::path config_dir = temp_dir / " configs" ;
9186 fs::create_directories (config_dir);
92-
87+
9388 std::string config_content = R"(
9489model:
9590 path: ../models/test_model.gguf
9691prompt_file: prompts/test.txt
9792)" ;
98-
93+
9994 fs::path config_path = config_dir / " test_config.yaml" ;
10095 std::ofstream config_file (config_path);
10196 config_file << config_content;
10297 config_file.close ();
103-
98+
10499 bool result = common_load_yaml_config (config_path.string (), params);
105100 assert (result);
106101 (void )result;
107-
102+
108103 fs::path expected_model = temp_dir / " models" / " test_model.gguf" ;
109104 fs::path expected_prompt = config_dir / " prompts" / " test.txt" ;
110-
105+
111106 assert (params.model .path == expected_model.lexically_normal ().string ());
112107 assert (params.prompt_file == expected_prompt.lexically_normal ().string ());
113-
114108 fs::remove_all (temp_dir);
115-
109+
116110 std::cout << " test_relative_path_resolution: PASSED\n " ;
117111}
118112
@@ -121,7 +115,7 @@ int main() {
121115 test_minimal_config ();
122116 test_unknown_key_error ();
123117 test_relative_path_resolution ();
124-
118+
125119 std::cout << " All tests passed!\n " ;
126120 return 0 ;
127121 } catch (const std::exception & e) {
0 commit comments