MCPcopy Create free account
hub / github.com/appdevforall/CodeOnTheGo / main

Function main

subprojects/llama.cpp/tests/test-arg-parser.cpp:13–208  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11#include <cassert>
12
13int main(void) {
14 common_params params;
15
16 printf("test-arg-parser: make sure there is no duplicated arguments in any examples\n\n");
17 for (int ex = 0; ex < LLAMA_EXAMPLE_COUNT; ex++) {
18 try {
19 auto ctx_arg = common_params_parser_init(params, (enum llama_example)ex);
20 common_params_add_preset_options(ctx_arg.options);
21 std::unordered_set<std::string> seen_args;
22 std::unordered_set<std::string> seen_env_vars;
23 for (const auto & opt : ctx_arg.options) {
24 // check for args duplications
25 for (const auto & arg : opt.get_args()) {
26 if (seen_args.find(arg) == seen_args.end()) {
27 seen_args.insert(arg);
28 } else {
29 fprintf(stderr, "test-arg-parser: found different handlers for the same argument: %s", arg.c_str());
30 exit(1);
31 }
32 }
33 // check for env var duplications
34 for (const auto & env : opt.get_env()) {
35 if (seen_env_vars.find(env) == seen_env_vars.end()) {
36 seen_env_vars.insert(env);
37 } else {
38 fprintf(stderr, "test-arg-parser: found different handlers for the same env var: %s", env.c_str());
39 exit(1);
40 }
41 }
42
43 // ensure shorter argument precedes longer argument
44 if (opt.args.size() > 1) {
45 const std::string first(opt.args.front());
46 const std::string last(opt.args.back());
47
48 if (first.length() > last.length()) {
49 fprintf(stderr, "test-arg-parser: shorter argument should come before longer one: %s, %s\n",
50 first.c_str(), last.c_str());
51 assert(false);
52 }
53 }
54
55 // same check for negated arguments
56 if (opt.args_neg.size() > 1) {
57 const std::string first(opt.args_neg.front());
58 const std::string last(opt.args_neg.back());
59
60 if (first.length() > last.length()) {
61 fprintf(stderr, "test-arg-parser: shorter negated argument should come before longer one: %s, %s\n",
62 first.c_str(), last.c_str());
63 assert(false);
64 }
65 }
66 }
67 } catch (std::exception & e) {
68 printf("%s\n", e.what());
69 assert(false);
70 }

Callers

nothing calls this directly

Calls 14

common_params_parseFunction · 0.85
get_argsMethod · 0.80
get_envMethod · 0.80
findMethod · 0.65
sizeMethod · 0.65
lengthMethod · 0.65
endMethod · 0.45
insertMethod · 0.45
whatMethod · 0.45

Tested by

no test coverage detected