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

GothenburgBitFactory / taskwarrior / 12469969465

23 Dec 2024 04:34PM UTC coverage: 85.033% (+0.04%) from 84.989%
12469969465

push

github

web-flow
Consider news read if `news.version` > current version (#3734)

Avoids two installations of taskwarrior with differing versions from
constantly nagging and rewriting `news.version`

1 of 2 new or added lines in 1 file covered. (50.0%)

14 existing lines in 6 files now uncovered.

19458 of 22883 relevant lines covered (85.03%)

23169.57 hits per line

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

71.05
/src/Version.cpp
1
////////////////////////////////////////////////////////////////////////////////
2
//
3
// Copyright 2024, Dustin 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 <Version.h>
28
#include <cmake.h>
29
// cmake.h include header must come first
30

31
#include <iostream>
32
#include <sstream>
33
#include <string>
34
#include <tuple>
35
#include <vector>
36

37
////////////////////////////////////////////////////////////////////////////////
38
Version::Version(std::string version) {
3,947✔
39
  std::vector<int> parts;
3,947✔
40
  std::string part;
3,947✔
41
  std::istringstream input(version);
3,947✔
42

43
  while (std::getline(input, part, '.')) {
15,788✔
44
    int value;
45
    // Try converting string to integer
46
    if (std::stringstream(part) >> value && value >= 0) {
11,841✔
47
      parts.push_back(value);
11,841✔
48
    } else {
49
      return;
×
50
    }
51
  }
52

53
  if (parts.size() != 3) {
3,947✔
54
    return;
×
55
  }
56

57
  major = parts[0];
3,947✔
58
  minor = parts[1];
3,947✔
59
  patch = parts[2];
3,947✔
60
}
3,947✔
61

62
////////////////////////////////////////////////////////////////////////////////
63
Version Version::Current() { return Version(PACKAGE_VERSION); }
2,994✔
64

65
////////////////////////////////////////////////////////////////////////////////
66
bool Version::is_valid() const { return major >= 0; }
998✔
67

68
////////////////////////////////////////////////////////////////////////////////
69
bool Version::operator<(const Version &other) const {
×
70
  return std::tie(major, minor, patch) < std::tie(other.major, other.minor, other.patch);
×
71
}
72

73
////////////////////////////////////////////////////////////////////////////////
74
bool Version::operator<=(const Version &other) const {
×
75
  return std::tie(major, minor, patch) <= std::tie(other.major, other.minor, other.patch);
×
76
}
77

78
////////////////////////////////////////////////////////////////////////////////
79
bool Version::operator>(const Version &other) const {
6,344✔
80
  return std::tie(major, minor, patch) > std::tie(other.major, other.minor, other.patch);
6,344✔
81
}
82

83
////////////////////////////////////////////////////////////////////////////////
84
bool Version::operator>=(const Version &other) const {
509✔
85
  return std::tie(major, minor, patch) >= std::tie(other.major, other.minor, other.patch);
509✔
86
}
87

88
////////////////////////////////////////////////////////////////////////////////
UNCOV
89
bool Version::operator==(const Version &other) const {
×
UNCOV
90
  return std::tie(major, minor, patch) == std::tie(other.major, other.minor, other.patch);
×
91
}
92

93
////////////////////////////////////////////////////////////////////////////////
94
bool Version::operator!=(const Version &other) const {
×
95
  return std::tie(major, minor, patch) != std::tie(other.major, other.minor, other.patch);
×
96
}
97

98
////////////////////////////////////////////////////////////////////////////////
99
Version::operator std::string() const {
489✔
100
  std::ostringstream output;
489✔
101
  if (is_valid()) {
489✔
102
    output << major << '.' << minor << '.' << patch;
489✔
103
  } else {
104
    output << "(invalid version)";
×
105
  }
106
  return output.str();
978✔
107
}
489✔
108

109
////////////////////////////////////////////////////////////////////////////////
110
std::ostream &operator<<(std::ostream &os, const Version &version) {
489✔
111
  os << std::string(version);
489✔
112
  return os;
489✔
113
}
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