@@ -14,7 +14,7 @@ struct TestCase {
1414
1515static void test_cli_args_without_yaml () {
1616 std::cout << " Testing CLI arguments without YAML..." << std::endl;
17-
17+
1818 std::vector<TestCase> test_cases = {
1919 {{" test" , " -n" , " 100" }, " Basic n_predict" },
2020 {{" test" , " -p" , " Hello world" }, " Basic prompt" },
@@ -27,33 +27,33 @@ static void test_cli_args_without_yaml() {
2727 {{" test" , " -n" , " 50" , " -p" , " Test" , " --temp" , " 0.7" }, " Multiple arguments" },
2828 {{" test" , " --help" }, " Help flag (should exit)" },
2929 };
30-
30+
3131 for (const auto & test_case : test_cases) {
3232 if (test_case.description == " Help flag (should exit)" ) {
3333 continue ;
3434 }
35-
35+
3636 std::cout << " Testing: " << test_case.description << std::endl;
37-
37+
3838 common_params params;
3939 std::vector<char *> argv;
4040 for (const auto & arg : test_case.args ) {
4141 argv.push_back (const_cast <char *>(arg.c_str ()));
4242 }
43-
43+
4444 bool result = common_params_parse (argv.size (), argv.data (), params, LLAMA_EXAMPLE_COMMON);
45-
45+
4646 if (!result && test_case.description != " Help flag (should exit)" ) {
4747 std::cout << " Warning: " << test_case.description << " failed to parse" << std::endl;
4848 }
4949 }
50-
50+
5151 std::cout << " CLI arguments without YAML test completed!" << std::endl;
5252}
5353
5454static void test_equivalent_yaml_and_cli () {
5555 std::cout << " Testing equivalent YAML and CLI produce same results..." << std::endl;
56-
56+
5757 std::ofstream yaml_file (" equivalent_test.yaml" );
5858 yaml_file << R"(
5959n_predict: 100
@@ -68,16 +68,16 @@ prompt: "Test prompt"
6868 penalty_repeat: 1.1
6969)" ;
7070 yaml_file.close ();
71-
71+
7272 common_params yaml_params;
7373 const char * yaml_argv[] = {" test" , " --config" , " equivalent_test.yaml" };
7474 bool yaml_result = common_params_parse (3 , const_cast <char **>(yaml_argv), yaml_params, LLAMA_EXAMPLE_COMMON);
75-
75+
7676 common_params cli_params;
7777 const char * cli_argv[] = {
78- " test" ,
78+ " test" ,
7979 " -n" , " 100" ,
80- " --ctx-size" , " 2048" ,
80+ " --ctx-size" , " 2048" ,
8181 " -b" , " 512" ,
8282 " -p" , " Test prompt" ,
8383 " -s" , " 42" ,
@@ -87,12 +87,12 @@ prompt: "Test prompt"
8787 " --repeat-penalty" , " 1.1"
8888 };
8989 bool cli_result = common_params_parse (17 , const_cast <char **>(cli_argv), cli_params, LLAMA_EXAMPLE_COMMON);
90-
90+
9191 assert (yaml_result == true );
9292 assert (cli_result == true );
9393 (void )yaml_result; // Suppress unused variable warning
9494 (void )cli_result; // Suppress unused variable warning
95-
95+
9696 assert (yaml_params.n_predict == cli_params.n_predict );
9797 assert (yaml_params.n_ctx == cli_params.n_ctx );
9898 assert (yaml_params.n_batch == cli_params.n_batch );
@@ -102,20 +102,20 @@ prompt: "Test prompt"
102102 assert (yaml_params.sampling .top_k == cli_params.sampling .top_k );
103103 assert (yaml_params.sampling .top_p == cli_params.sampling .top_p );
104104 assert (yaml_params.sampling .penalty_repeat == cli_params.sampling .penalty_repeat );
105-
105+
106106 std::filesystem::remove (" equivalent_test.yaml" );
107107 std::cout << " Equivalent YAML and CLI test passed!" << std::endl;
108108}
109109
110110static void test_all_major_cli_options () {
111111 std::cout << " Testing all major CLI options still work..." << std::endl;
112-
112+
113113 struct CliTest {
114114 std::vector<std::string> args;
115115 std::string param_name;
116116 bool should_succeed;
117117 };
118-
118+
119119 std::vector<CliTest> cli_tests = {
120120 {{" test" , " -m" , " model.gguf" }, " model path" , true },
121121 {{" test" , " -n" , " 200" }, " n_predict" , true },
@@ -133,35 +133,35 @@ static void test_all_major_cli_options() {
133133 {{" test" , " --color" }, " color output" , true },
134134 {{" test" , " --verbose" }, " verbose mode" , true },
135135 };
136-
136+
137137 for (const auto & test : cli_tests) {
138138 std::cout << " Testing: " << test.param_name << std::endl;
139-
139+
140140 common_params params;
141141 std::vector<char *> argv;
142142 for (const auto & arg : test.args ) {
143143 argv.push_back (const_cast <char *>(arg.c_str ()));
144144 }
145-
145+
146146 bool result = common_params_parse (argv.size (), argv.data (), params, LLAMA_EXAMPLE_COMMON);
147-
147+
148148 if (result != test.should_succeed ) {
149- std::cout << " Unexpected result for " << test.param_name
149+ std::cout << " Unexpected result for " << test.param_name
150150 << " : expected " << test.should_succeed << " , got " << result << std::endl;
151151 }
152152 }
153-
153+
154154 std::cout << " Major CLI options test completed!" << std::endl;
155155}
156156
157157int main () {
158158 std::cout << " Running backward compatibility tests..." << std::endl;
159-
159+
160160 try {
161161 test_cli_args_without_yaml ();
162162 test_equivalent_yaml_and_cli ();
163163 test_all_major_cli_options ();
164-
164+
165165 std::cout << " All backward compatibility tests completed!" << std::endl;
166166 return 0 ;
167167 } catch (const std::exception& e) {
0 commit comments