diff --git a/common/test/Makefile b/common/test/Makefile index 3304f2f5f763..2df9e1284cad 100644 --- a/common/test/Makefile +++ b/common/test/Makefile @@ -90,4 +90,11 @@ common/test/run-bolt12_merkle-json: \ common/base32.o \ common/wireaddr.o + +common/test/run-version: \ + common/amount.o \ + wire/fromwire.o \ + wire/towire.o + + check-units: $(COMMON_TEST_PROGRAMS:%=unittest/%) diff --git a/common/test/run-version.c b/common/test/run-version.c new file mode 100644 index 000000000000..0e04b4cb061a --- /dev/null +++ b/common/test/run-version.c @@ -0,0 +1,16 @@ +#include "config.h" +#include "../version.c" +#include +#include +#include + +int main(int argc, char *argv[]) +{ + common_setup(argv[0]); + + assert(cmp_release_version("v22.11")); + assert(cmp_release_version("v22.11.1")); + assert(cmp_release_version("v22.11.1-6-gdf29990-modded") == false); + + common_shutdown(); +} diff --git a/common/version.c b/common/version.c index e64bc2595799..4fc20b6667e0 100644 --- a/common/version.c +++ b/common/version.c @@ -3,6 +3,7 @@ #include #include #include +#include /* Only common/version.c can safely include this. */ # include "version_gen.h" @@ -20,3 +21,15 @@ char *version_and_exit(const void *unused UNUSED) } exit(0); } + +static bool cmp_release_version(const char *version) { + if (version[0] != 'v') + return false; + return strspn(version+1, ".0123456789") == strlen(version+1); +} + +/* Released versions are of form v[year].[month]?(.patch)* */ +bool is_released_version(void) +{ + return cmp_release_version(version()); +} diff --git a/common/version.h b/common/version.h index b2db426dfd0a..90b7c824d12b 100644 --- a/common/version.h +++ b/common/version.h @@ -1,9 +1,14 @@ #ifndef LIGHTNING_COMMON_VERSION_H #define LIGHTNING_COMMON_VERSION_H #include "config.h" +#include char *version_and_exit(const void *unused); const char *version(void); +/* check if the current version is a release version. + * + * Released versions are of form v[year].[month]?(.patch)* */ +bool is_released_version(void); #define opt_register_version() \ opt_register_early_noarg("--version|-V", version_and_exit, NULL, \ diff --git a/wallet/db.c b/wallet/db.c index 5286d8cc12f0..4a45167f5fda 100644 --- a/wallet/db.c +++ b/wallet/db.c @@ -945,14 +945,6 @@ static struct migration dbmigrations[] = { /* FIXME: Remove payments local_offer_id column! */ }; -/* Released versions are of form v{num}[.{num}]* */ -static bool is_released_version(void) -{ - if (version()[0] != 'v') - return false; - return strcspn(version()+1, ".0123456789") == strlen(version()+1); -} - /** * db_migrate - Apply all remaining migrations from the current version */