xaizek / dit (License: GPLv3) (since 2018-12-07)
Command-line task keeper that remembers all old values and is meant to combine several orthogonal features to be rather flexible in managing items.
Commit a234370cebf9c5fe05634e42a4dacff01f78e15e

Avoid copies in range loops and `catch ()` stmt
With -Werror warnings about these on modern GCC fails the build.
Author: xaizek
Author date (UTC): 2022-02-04 21:35
Committer name: xaizek
Committer date (UTC): 2022-02-04 21:35
Parent(s): 46f71de3879ad204d7dfb850e02360060fc65030
Signing key: 99DC5E4DB05F6BE2
Tree: fd1b42ce5a536d13da4def877afe2751815ba7fa
File Lines added Lines deleted
src/decoration.cpp 1 1
tests/Commands.cpp 2 1
tests/Config.cpp 2 1
tests/Dit.cpp 2 2
tests/Invocation.cpp 3 2
tests/Item.cpp 5 3
tests/ItemFilter.cpp 1 1
tests/ItemTable.cpp 1 1
tests/Project.cpp 1 1
tests/Storage.cpp 2 1
tests/cmds/ExportCmd.cpp 1 1
tests/cmds/LogCmd.cpp 2 1
tests/file_format.cpp 2 2
tests/utils/args.cpp 12 6
File src/decoration.cpp changed (mode: 100644) (index 7fa3869..e83fef5)
... ... std::ostream &
141 141 ScopedDecoration::decorate(std::ostream &os) const ScopedDecoration::decorate(std::ostream &os) const
142 142 { {
143 143 os << decoration; os << decoration;
144 for (const auto app : apps) {
144 for (const auto &app : apps) {
145 145 app(os); app(os);
146 146 } }
147 147 os << def; os << def;
File tests/Commands.cpp changed (mode: 100644) (index aef7576..6ffb59d)
... ... TEST_CASE("Commands must have unique names", "[commands]")
46 46 REQUIRE(cmd != nullptr); REQUIRE(cmd != nullptr);
47 47
48 48 auto fakeCmd = make_unique<Cmd>("log", std::string(), std::string()); auto fakeCmd = make_unique<Cmd>("log", std::string(), std::string());
49 REQUIRE_THROWS_AS(Commands::add(std::move(fakeCmd)), std::runtime_error);
49 REQUIRE_THROWS_AS(Commands::add(std::move(fakeCmd)),
50 const std::runtime_error &);
50 51 } }
File tests/Config.cpp changed (mode: 100644) (index aa77618..d874cac)
... ... TEST_CASE("Loading file of wrong format throws exception", "[config]")
92 92 Config child("tests/main.cpp"); Config child("tests/main.cpp");
93 93
94 94 namespace pt = boost::property_tree; namespace pt = boost::property_tree;
95 REQUIRE_THROWS_AS(child.get("key", "v") == "value", pt::info_parser_error);
95 REQUIRE_THROWS_AS(child.get("key", "v") == "value",
96 const pt::info_parser_error &);
96 97 } }
File tests/Dit.cpp changed (mode: 100644) (index 5e6cafb..0f6303c)
35 35
36 36 TEST_CASE("Dit throws exception on empty args", "[app][invocation]") TEST_CASE("Dit throws exception on empty args", "[app][invocation]")
37 37 { {
38 REQUIRE_THROWS_AS(Dit({}), std::runtime_error);
38 REQUIRE_THROWS_AS(Dit({}), const std::runtime_error &);
39 39 } }
40 40
41 41 TEST_CASE("Dit throws exception on absent $HOME", "[app][invocation]") TEST_CASE("Dit throws exception on absent $HOME", "[app][invocation]")
 
... ... TEST_CASE("Dit throws exception on absent $HOME", "[app][invocation]")
43 43 std::string home = std::getenv("HOME"); std::string home = std::getenv("HOME");
44 44
45 45 unsetenv("HOME"); unsetenv("HOME");
46 REQUIRE_THROWS_AS(Dit({ "dit" }), std::runtime_error);
46 REQUIRE_THROWS_AS(Dit({ "dit" }), const std::runtime_error &);
47 47
48 48 static std::string homeSet = "HOME=" + home; static std::string homeSet = "HOME=" + home;
49 49 putenv(&homeSet[0]); putenv(&homeSet[0]);
File tests/Invocation.cpp changed (mode: 100644) (index d12f481..c7e4a13)
... ... TEST_CASE("Wrong options.", "[invocation][completion]")
331 331
332 332 SECTION("Error on running") SECTION("Error on running")
333 333 { {
334 REQUIRE_THROWS_AS(invocation.parse(), boost::program_options::error);
334 REQUIRE_THROWS_AS(invocation.parse(),
335 const boost::program_options::error &);
335 336 } }
336 337 } }
337 338
 
... ... TEST_CASE("Invocation throws if alias resolved isn't set.", "[invocation]")
340 341 Invocation invocation; Invocation invocation;
341 342 invocation.setCmdLine({ "alias" }); invocation.setCmdLine({ "alias" });
342 343
343 REQUIRE_THROWS_AS(invocation.parse(), std::bad_function_call);
344 REQUIRE_THROWS_AS(invocation.parse(), const std::bad_function_call &);
344 345 } }
345 346
346 347 TEST_CASE("Aliases are decomposed.", "[invocation][alias][composition]") TEST_CASE("Aliases are decomposed.", "[invocation][alias][composition]")
File tests/Item.cpp changed (mode: 100644) (index c21a2e9..fbca007)
... ... TEST_CASE("Wrongly named keys cause error.", "[item]")
105 105
106 106 SECTION("On get().") SECTION("On get().")
107 107 { {
108 REQUIRE_THROWS_AS(item.getValue("!@@#$%^"), std::runtime_error);
108 REQUIRE_THROWS_AS(item.getValue("!@@#$%^"), const std::runtime_error &);
109 109 } }
110 110
111 111 SECTION("On set().") SECTION("On set().")
112 112 { {
113 REQUIRE_THROWS_AS(item.setValue("!@@#$%^", "b"), std::runtime_error);
113 REQUIRE_THROWS_AS(item.setValue("!@@#$%^", "b"),
114 const std::runtime_error &);
114 115 } }
115 116 } }
116 117
 
... ... TEST_CASE("Items with broken timestamps fail to load.", "[item][load]")
195 196 { {
196 197 Project prj("tests/data/dit/projects/tmp"); Project prj("tests/data/dit/projects/tmp");
197 198 Storage &storage = prj.getStorage(); Storage &storage = prj.getStorage();
198 REQUIRE_THROWS_AS(storage.get(id).getValue("c"), std::logic_error);
199 REQUIRE_THROWS_AS(storage.get(id).getValue("c"),
200 const std::logic_error &);
199 201 } }
200 202
201 203 } catch (...) { } catch (...) {
File tests/ItemFilter.cpp changed (mode: 100644) (index eda2bab..acd86cd)
28 28
29 29 TEST_CASE("Throws on wrong syntax", "[item-filter]") TEST_CASE("Throws on wrong syntax", "[item-filter]")
30 30 { {
31 REQUIRE_THROWS_AS(ItemFilter({ "wrong expr" }), std::runtime_error);
31 REQUIRE_THROWS_AS(ItemFilter({ "wrong expr" }), const std::runtime_error &);
32 32 } }
33 33
34 34 TEST_CASE("Error messages add up", "[item-filter]") TEST_CASE("Error messages add up", "[item-filter]")
File tests/ItemTable.cpp changed (mode: 100644) (index 0795270..fbf2e27)
... ... TEST_CASE("Throws on wrong specification.", "[item-table][format]")
30 30 { {
31 31 REQUIRE_THROWS_AS(ItemTable(std::string(), "this is not valid", REQUIRE_THROWS_AS(ItemTable(std::string(), "this is not valid",
32 32 std::string(), 80), std::string(), 80),
33 std::runtime_error);
33 const std::runtime_error &);
34 34 } }
35 35
36 36 TEST_CASE("No columns result in no output.", "[item-table][format]") TEST_CASE("No columns result in no output.", "[item-table][format]")
File tests/Project.cpp changed (mode: 100644) (index 623cb06..c327bad)
21 21 TEST_CASE("Project::init fails on failure to create directory", "[project]") TEST_CASE("Project::init fails on failure to create directory", "[project]")
22 22 { {
23 23 REQUIRE_THROWS_AS(Project::init("tests/data/dit/config"), REQUIRE_THROWS_AS(Project::init("tests/data/dit/config"),
24 std::runtime_error);
24 const std::runtime_error &);
25 25 } }
File tests/Storage.cpp changed (mode: 100644) (index 6e56a9c..2b1df94)
... ... TEST_CASE("Storage throws on save if project removed", "[storage]")
101 101 Item &item = storage.get(id); Item &item = storage.get(id);
102 102 fs::remove_all("tests/data/dit/projects/tmp"); fs::remove_all("tests/data/dit/projects/tmp");
103 103
104 REQUIRE_THROWS_AS(item.getValue("title"), std::runtime_error);
104 REQUIRE_THROWS_AS(item.getValue("title"),
105 const std::runtime_error &);
105 106 } }
106 107
107 108 } catch (...) { } catch (...) {
File tests/cmds/ExportCmd.cpp changed (mode: 100644) (index 5dac925..5d9e67d)
... ... TEST_CASE("Item exporting", "[cmds][export]")
117 117 SECTION("Failed run") SECTION("Failed run")
118 118 { {
119 119 REQUIRE_THROWS_AS(cmd->run(*prj, { "no-such-cmd" }), REQUIRE_THROWS_AS(cmd->run(*prj, { "no-such-cmd" }),
120 std::runtime_error);
120 const std::runtime_error &);
121 121 } }
122 122
123 123 REQUIRE(out.str() == std::string()); REQUIRE(out.str() == std::string());
File tests/cmds/LogCmd.cpp changed (mode: 100644) (index 4b612c7..ed01e23)
... ... TEST_CASE("Log fails on wrong invocation", "[cmds][log][invocation]")
53 53
54 54 SECTION("Wrong id") SECTION("Wrong id")
55 55 { {
56 REQUIRE_THROWS_AS(cmd->run(*prj, { "asdf" }), std::runtime_error);
56 REQUIRE_THROWS_AS(cmd->run(*prj, { "asdf" }),
57 const std::runtime_error &);
57 58 } }
58 59 } }
59 60
File tests/file_format.cpp changed (mode: 100644) (index cc85604..8650d3b)
... ... TEST_CASE("Deserialization of broken stream errors.", "[file-format]")
44 44 std::stringstream ss; std::stringstream ss;
45 45 ss << "bla=bla\n"; ss << "bla=bla\n";
46 46
47 REQUIRE_THROWS_AS(ss >> d, std::runtime_error);
47 REQUIRE_THROWS_AS(ss >> d, const std::runtime_error &);
48 48 } }
49 49
50 50 TEST_CASE("Deserialized objects are identical to original", "[file-format]") TEST_CASE("Deserialized objects are identical to original", "[file-format]")
 
... ... TEST_CASE("Deserialization throws on empty string", "[file-format]")
71 71
72 72 std::stringstream ss; std::stringstream ss;
73 73 ss << '\n' << o; ss << '\n' << o;
74 REQUIRE_THROWS_AS(ss >> d, std::runtime_error);
74 REQUIRE_THROWS_AS(ss >> d, const std::runtime_error &);
75 75 } }
76 76
77 77 static inline bool static inline bool
File tests/utils/args.cpp changed (mode: 100644) (index 2000334..b117e17)
... ... TEST_CASE("Whitespace everywhere", "[utils][args]")
59 59
60 60 TEST_CASE("Throws exception on unclosed bracket", "[utils][args]") TEST_CASE("Throws exception on unclosed bracket", "[utils][args]")
61 61 { {
62 REQUIRE_THROWS_AS(breakIntoArgs("'broken"), boost::escaped_list_error);
63 REQUIRE_THROWS_AS(breakIntoArgs("\"broken"), boost::escaped_list_error);
64 REQUIRE_THROWS_AS(breakIntoArgs("broken'"), boost::escaped_list_error);
65 REQUIRE_THROWS_AS(breakIntoArgs("broken\""), boost::escaped_list_error);
62 REQUIRE_THROWS_AS(breakIntoArgs("'broken"),
63 const boost::escaped_list_error &);
64 REQUIRE_THROWS_AS(breakIntoArgs("\"broken"),
65 const boost::escaped_list_error &);
66 REQUIRE_THROWS_AS(breakIntoArgs("broken'"),
67 const boost::escaped_list_error &);
68 REQUIRE_THROWS_AS(breakIntoArgs("broken\""),
69 const boost::escaped_list_error &);
66 70 } }
67 71
68 72 TEST_CASE("Escaping works", "[utils][args]") TEST_CASE("Escaping works", "[utils][args]")
 
... ... TEST_CASE("Escaping works", "[utils][args]")
73 77
74 78 TEST_CASE("Throws exception on wrong escaping", "[utils][args]") TEST_CASE("Throws exception on wrong escaping", "[utils][args]")
75 79 { {
76 REQUIRE_THROWS_AS(breakIntoArgs("broken\\"), boost::escaped_list_error);
77 REQUIRE_THROWS_AS(breakIntoArgs("broken\\x"), boost::escaped_list_error);
80 REQUIRE_THROWS_AS(breakIntoArgs("broken\\"),
81 const boost::escaped_list_error &);
82 REQUIRE_THROWS_AS(breakIntoArgs("broken\\x"),
83 const boost::escaped_list_error &);
78 84 } }
79 85
80 86 TEST_CASE("Accepts empty arguments", "[utils][args]") TEST_CASE("Accepts empty arguments", "[utils][args]")
Hints

Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/dit

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/dit

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master