• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

GothenburgBitFactory / taskwarrior / 10152339701

29 Jul 2024 09:45PM UTC coverage: 84.437% (+0.07%) from 84.372%
10152339701

push

github

web-flow
Merge pull request #3566 from felixschurk/add-clang-format

Add clang-format to enforce style guide

12359 of 13760 new or added lines in 147 files covered. (89.82%)

123 existing lines in 42 files now uncovered.

19070 of 22585 relevant lines covered (84.44%)

19724.02 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

49.15
/test/tdb2.test.cpp
1
////////////////////////////////////////////////////////////////////////////////
2
//
3
// Copyright 2006 - 2021, Tomas Babej, Paul Beckingham, Federico Hernandez.
4
//
5
// Permission is hereby granted, free of charge, to any person obtaining a copy
6
// of this software and associated documentation files (the "Software"), to deal
7
// in the Software without restriction, including without limitation the rights
8
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
// copies of the Software, and to permit persons to whom the Software is
10
// furnished to do so, subject to the following conditions:
11
//
12
// The above copyright notice and this permission notice shall be included
13
// in all copies or substantial portions of the Software.
14
//
15
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
// SOFTWARE.
22
//
23
// https://www.opensource.org/licenses/mit-license.php
24
//
25
////////////////////////////////////////////////////////////////////////////////
26

27
#include <cmake.h>
28
// cmake.h include header must come first
29

30
#include <main.h>
31
#include <stdlib.h>
32
#include <test.h>
33
#include <unistd.h>
34

35
#include <iostream>
36

37
Context context;
38

39
void cleardb() {
1✔
40
  // Remove any residual test files.
41
  rmdir("./extensions");
1✔
42
  unlink("./taskchampion.sqlite3");
1✔
43
}
1✔
44

45
////////////////////////////////////////////////////////////////////////////////
46
int main(int, char**) {
1✔
47
  UnitTest t(12);
1✔
48
  Context context;
1✔
49
  Context::setContext(&context);
1✔
50

51
  // Ensure environment has no influence.
52
  unsetenv("TASKDATA");
1✔
53
  unsetenv("TASKRC");
1✔
54

55
  try {
56
    cleardb();
1✔
57

58
    // Set the context to allow GC.
59
    context.config.set("gc", 1);
1✔
60
    context.config.set("debug", 1);
1✔
61

62
    context.tdb2.open_replica(".", true);
1✔
63

64
    // Try reading an empty database.
65
    std::vector<Task> pending = context.tdb2.pending_tasks();
1✔
66
    std::vector<Task> completed = context.tdb2.completed_tasks();
1✔
67
    int num_reverts_possible = context.tdb2.num_reverts_possible();
1✔
68
    int num_local_changes = context.tdb2.num_local_changes();
1✔
69

70
    t.is((int)pending.size(), 0, "TDB2 Read empty pending");
1✔
71
    t.is((int)completed.size(), 0, "TDB2 Read empty completed");
1✔
72
    t.is((int)num_reverts_possible, 0, "TDB2 Read empty undo");
1✔
73
    t.is((int)num_local_changes, 0, "TDB2 Read empty backlog");
1✔
74

75
    // Add a task.
76
    Task task(R"([description:"description" name:"value"])");
3✔
NEW
77
    context.tdb2.add(task);
×
78

NEW
79
    pending = context.tdb2.pending_tasks();
×
NEW
80
    completed = context.tdb2.completed_tasks();
×
NEW
81
    num_reverts_possible = context.tdb2.num_reverts_possible();
×
NEW
82
    num_local_changes = context.tdb2.num_local_changes();
×
83

NEW
84
    t.is((int)pending.size(), 1, "TDB2 after add, 1 pending task");
×
NEW
85
    t.is((int)completed.size(), 0, "TDB2 after add, 0 completed tasks");
×
NEW
86
    t.is((int)num_reverts_possible, 1, "TDB2 after add, 1 revert possible");
×
NEW
87
    t.is((int)num_local_changes, 6, "TDB2 after add, 6 local changes");
×
88

NEW
89
    task.set("description", "This is a test");
×
NEW
90
    context.tdb2.modify(task);
×
91

NEW
92
    pending = context.tdb2.pending_tasks();
×
NEW
93
    completed = context.tdb2.completed_tasks();
×
NEW
94
    num_reverts_possible = context.tdb2.num_reverts_possible();
×
NEW
95
    num_local_changes = context.tdb2.num_local_changes();
×
96

NEW
97
    t.is((int)pending.size(), 1, "TDB2 after set, 1 pending task");
×
NEW
98
    t.is((int)completed.size(), 0, "TDB2 after set, 0 completed tasks");
×
NEW
99
    t.is((int)num_reverts_possible, 1, "TDB2 after set, 1 revert possible");
×
100

101
    // At this point, there may be 7 or 8 local changes, depending on whether
102
    // the `modified` property changed between the `add` and `modify`
103
    // invocation. That only happens if the clock ticks over to the next second
104
    // between those invocations.
NEW
105
    t.ok(num_local_changes == 7 || num_local_changes == 8, "TDB2 after set, 7 or 8 local changes");
×
106

107
    // Reset for reuse.
NEW
108
    cleardb();
×
NEW
109
    context.tdb2.open_replica(".", true);
×
110

111
    // TODO complete a task
112
    // TODO gc
113
  }
2✔
114

115
  catch (const std::string& error) {
1✔
116
    t.diag(error);
1✔
117
    return -1;
1✔
118
  }
1✔
119

NEW
120
  catch (...) {
×
NEW
121
    t.diag("Unknown error.");
×
UNCOV
122
    return -2;
×
123
  }
124

NEW
125
  rmdir("./extensions");
×
NEW
126
  unlink("./pending.data");
×
NEW
127
  unlink("./completed.data");
×
NEW
128
  unlink("./undo.data");
×
NEW
129
  unlink("./backlog.data");
×
130

131
  return 0;
×
132
}
1✔
133

134
////////////////////////////////////////////////////////////////////////////////
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc