tests: Add test for release_is_new()

Also refactor the function so we pass it the current version
and don't rely on the define inside of it.

This function only allows version format in the style of "x.y.z".
This commit is contained in:
Michael Vetter
2026-02-25 12:07:46 +01:00
parent ea7a59808a
commit 549f28fa0d
6 changed files with 46 additions and 4 deletions

View File

@@ -471,11 +471,15 @@ release_get_latest(void)
}
gboolean
release_is_new(char* found_version)
release_is_new(const char* const curr_version, const char* const found_version)
{
if (!curr_version || !found_version) {
return FALSE;
}
int curr_maj, curr_min, curr_patch, found_maj, found_min, found_patch;
int parse_curr = sscanf(PACKAGE_VERSION, "%d.%d.%d", &curr_maj, &curr_min,
int parse_curr = sscanf(curr_version, "%d.%d.%d", &curr_maj, &curr_min,
&curr_patch);
int parse_found = sscanf(found_version, "%d.%d.%d", &found_maj, &found_min,
&found_patch);

View File

@@ -193,7 +193,7 @@ gboolean string_matches_one_of(const char* what, const char* is, gboolean is_can
gboolean valid_tls_policy_option(const char* is);
char* release_get_latest(void);
gboolean release_is_new(char* found_version);
gboolean release_is_new(const char* const curr_version, const char* const found_version);
char* strip_arg_quotes(const char* const input);
gboolean is_notify_enabled(void);

View File

@@ -395,7 +395,7 @@ cons_check_version(gboolean not_available_msg)
gboolean relase_valid = g_regex_match_simple("^\\d+\\.\\d+\\.\\d+$", latest_release, 0, 0);
if (relase_valid) {
if (release_is_new(latest_release)) {
if (release_is_new(PACKAGE_VERSION, latest_release)) {
win_println(console, THEME_DEFAULT, "-", "A new version of Profanity is available: %s", latest_release);
win_println(console, THEME_DEFAULT, "-", "Check <https://profanity-im.github.io> for details.");
win_println(console, THEME_DEFAULT, "-", "");