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

GothenburgBitFactory / taskwarrior / 13158305484

05 Feb 2025 01:20PM UTC coverage: 85.125% (+0.08%) from 85.045%
13158305484

push

github

web-flow
Test for unusual task data (#3770)

* Test for unusual task data

A task might have any combination of keys and values, but Taskwarrior
often assumes that only valid values can occur, and crashes otherwise.
This is highly inconvenient, as it's often impossible to do anything
with the invalid task -- Taskwarrior just fails without modifying it.

So, this is the beginning of some testing for such invalid tasks, with
the goal of making Taskwarrior due something reasonable. In general, an
invalid attribute value is treated as if it was not set. This is not
exhaustive, and there are likely still bugs of this sort, but as we find
them we can fix and add regression tests to this script.

This introduces a new test-only binary that creates a "bare" task using
TaskChampion, avoiding Taskwarrior's efforts to not create "unusual"
tasks.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

70 of 77 new or added lines in 7 files covered. (90.91%)

1 existing line in 1 file now uncovered.

19555 of 22972 relevant lines covered (85.13%)

23300.32 hits per line

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

79.17
/test/make_tc_task.cpp
1
////////////////////////////////////////////////////////////////////////////////
2
//
3
// Copyright 2025, Dustin J. Mitchell
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 <CmdInfo.h>
31
#include <main.h>
32
#include <stdlib.h>
33
#include <taskchampion-cpp/lib.h>
34
#include <test.h>
35
#include <util.h>
36

37
#include <iostream>
38
#include <limits>
39

40
#include "format.h"
41

42
namespace {
43

44
////////////////////////////////////////////////////////////////////////////////
NEW
45
int usage() {
×
NEW
46
  std::cerr << "USAGE: make_tc_task DATADIR KEY=VALUE ..\n";
×
NEW
47
  return 1;
×
48
}
49

50
}  // namespace
51

52
////////////////////////////////////////////////////////////////////////////////
53
int main(int argc, char **argv) {
14✔
54
  if (!--argc) {
14✔
NEW
55
    return usage();
×
56
  }
57
  char *datadir = *++argv;
14✔
58

59
  auto replica = tc::new_replica_on_disk(datadir, true);
14✔
60
  auto uuid = tc::uuid_v4();
14✔
61
  auto operations = tc::new_operations();
14✔
62
  auto task = tc::create_task(uuid, operations);
14✔
63

64
  while (--argc) {
64✔
65
    std::string arg = *++argv;
50✔
66
    size_t eq_idx = arg.find('=');
50✔
67
    if (eq_idx == std::string::npos) {
50✔
NEW
68
      return usage();
×
69
    }
70
    std::string property = arg.substr(0, eq_idx);
50✔
71
    std::string value = arg.substr(eq_idx + 1);
50✔
72
    task->update(property, value, operations);
50✔
73
  }
50✔
74
  replica->commit_operations(std::move(operations));
14✔
75

76
  std::cout << static_cast<std::string>(uuid.to_string()) << "\n";
14✔
77
  return 0;
14✔
78
}
14✔
79

80
////////////////////////////////////////////////////////////////////////////////
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

© 2026 Coveralls, Inc