GCC Code Coverage Report


Directory: ./
File: src/cli/cli.cpp
Date: 2023-04-27 00:55:30
Exec Total Coverage
Lines: 44 53 83.0%
Functions: 1 2 50.0%
Branches: 45 56 80.4%

Line Branch Exec Source
1
2 #include "revision_data.h"
3
4 #include "cli/commands/code.h"
5 #include "cli/commands/codegen.h"
6 #include "cli/commands/debug.h"
7 #include "cli/commands/doc.h"
8 #include "cli/commands/format.h"
9 #include "cli/commands/install.h"
10 #include "cli/commands/internal.h"
11 #include "cli/commands/linter.h"
12 #include "cli/commands/profile.h"
13 #include "cli/commands/tests.h"
14
15 #include "utilities/metadata.h"
16 #include "utilities/names.h"
17 #include "utilities/strings.h"
18
19 using namespace lython;
20
21 const char* VERSION_STRING = "\n"
22 "[0] Lython Interpreter \n"
23 "[0] Compiler: " COMPILER_ID " " COMPILER_VERSION "\n"
24 "[0] Branch: " _BRANCH "\n"
25 "[0] Version: " _HASH "\n"
26 "[0] Date: " _DATE "\n\n";
27
28 int main(int argc, const char* argv[]) {
29
30
1/1
✓ Branch 1 taken 8 times.
8 auto linter = std::make_unique<LinterCmd>();
31
1/1
✓ Branch 1 taken 8 times.
8 auto install = std::make_unique<InstallCmd>();
32
1/1
✓ Branch 1 taken 8 times.
8 auto codegen = std::make_unique<CodegenCmd>();
33
1/1
✓ Branch 1 taken 8 times.
8 auto fmtcmd = std::make_unique<FormatCmd>();
34
1/1
✓ Branch 1 taken 8 times.
8 auto debug = std::make_unique<DebugCmd>();
35
1/1
✓ Branch 1 taken 8 times.
8 auto doc = std::make_unique<DocCmd>();
36
1/1
✓ Branch 1 taken 8 times.
8 auto profile = std::make_unique<ProfileCmd>();
37
1/1
✓ Branch 1 taken 8 times.
8 auto tests = std::make_unique<TestsCmd>();
38
1/1
✓ Branch 1 taken 8 times.
8 auto internal = std::make_unique<InternalCmd>();
39
40 // There is a problem when putting unique ptr inside the array :/
41 Array<Command*> commands = {
42 8 linter.get(),
43 8 install.get(),
44 8 codegen.get(),
45 8 fmtcmd.get(),
46 8 debug.get(),
47 8 doc.get(),
48 8 profile.get(),
49 8 tests.get(),
50 8 internal.get(),
51
1/1
✓ Branch 10 taken 8 times.
8 };
52
53 // Main Parser
54 // --------------------------------------------
55
3/3
✓ Branch 2 taken 8 times.
✓ Branch 6 taken 8 times.
✓ Branch 9 taken 8 times.
8 argparse::ArgumentParser lython_args("lython", "", argparse::default_arguments::help);
56
1/1
✓ Branch 2 taken 8 times.
8 lython_args.add_description("");
57
1/1
✓ Branch 1 taken 8 times.
8 lython_args.add_argument("--show-alloc-stats")
58
1/1
✓ Branch 2 taken 8 times.
16 .help("Print memory allocation statistics")
59
1/1
✓ Branch 1 taken 8 times.
8 .default_value(false)
60
2/2
✓ Branch 1 taken 8 times.
✓ Branch 4 taken 8 times.
8 .implicit_value(true);
61
62
1/1
✓ Branch 1 taken 8 times.
8 lython_args.add_argument("--show-string-stats")
63
1/1
✓ Branch 2 taken 8 times.
16 .help("Print string database allocations")
64
1/1
✓ Branch 1 taken 8 times.
8 .default_value(false)
65
2/2
✓ Branch 1 taken 8 times.
✓ Branch 4 taken 8 times.
8 .implicit_value(true);
66
67
1/1
✓ Branch 1 taken 8 times.
8 lython_args.add_argument("-v", "--version")
68 .action([&](const auto& /*unused*/) {
69 std::cout << VERSION_STRING;
70 std::exit(0);
71 })
72
1/1
✓ Branch 1 taken 8 times.
8 .default_value(false)
73
1/1
✓ Branch 2 taken 8 times.
16 .help("prints version information and exits")
74
2/2
✓ Branch 1 taken 8 times.
✓ Branch 4 taken 8 times.
16 .implicit_value(true)
75
1/1
✓ Branch 1 taken 8 times.
8 .nargs(0);
76
77
2/2
✓ Branch 5 taken 72 times.
✓ Branch 6 taken 8 times.
80 for (Command* cmd: commands) {
78
2/2
✓ Branch 1 taken 72 times.
✓ Branch 4 taken 72 times.
72 lython_args.add_subparser(*cmd->parser());
79 }
80
81 try {
82
1/1
✓ Branch 1 taken 1 times.
8 lython_args.parse_args(argc, argv);
83 } catch (const std::runtime_error& err) {
84 std::cerr << err.what() << std::endl;
85 std::cerr << lython_args;
86 return -1;
87 }
88
89 // -----------------
90
1/1
✓ Branch 1 taken 1 times.
1 register_globals();
91
2/2
✓ Branch 2 taken 1 times.
✓ Branch 5 taken 1 times.
1 show_alloc_stats_on_destroy(lython_args.get<bool>("--show-alloc-stats"));
92
2/2
✓ Branch 2 taken 1 times.
✓ Branch 5 taken 1 times.
1 show_string_stats_on_destroy(lython_args.get<bool>("--show-string-stats"));
93
94 // Execute command
95
1/2
✓ Branch 5 taken 9 times.
✗ Branch 6 not taken.
9 for (Command* cmd: commands) {
96
3/3
✓ Branch 2 taken 9 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 8 times.
9 if (lython_args.is_subcommand_used(cmd->name)) {
97
1/1
✓ Branch 1 taken 1 times.
1 return cmd->exec();
98 }
99 }
100
101 // At least one command should have been selected
102 std::cerr << lython_args;
103 return -1;
104 1 }
105