v31.1-roots.1 · Commit 8: [PATCH 08/17] chore(roots): integrate v31 identity and maintenance tooling
test/cmake/test_identity.py
Before: /dev/null · After: test/cmake/test_identity.py
File metadata
new file mode 100644 index 0000000000000000000000000000000000000000..7ec03aace83b87e5aefa5b5fca434c532b877ea0
Download original patch · Release notes
Diff rows 1–69 of 69. Line numbers refer to the original before/after files.
+ Added− RemovedUnmarked lines are context.
Scroll the code area horizontally to read long lines. The two line-number columns refer to before and after.
test/cmake/test_identity.py
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# Copyright (c) 2026-present The Bitcoin Roots developers
|
|
3
|
+
# Distributed under the MIT software license, see the accompanying
|
|
4
|
+
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
5
|
+
|
|
6
|
+
"""Exercise the production Roots release version block without Git metadata."""
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
import argparse
|
|
9
|
+
import re
|
|
10
|
+
import subprocess
|
|
11
|
+
import tempfile
|
|
12
|
+
import unittest
|
|
13
|
+
|
|
14
|
+
ROOT = Path(__file__).resolve().parents[2]
|
|
15
|
+
parser = argparse.ArgumentParser()
|
|
16
|
+
parser.add_argument("--cmake", default="cmake")
|
|
17
|
+
args, unittest_args = parser.parse_known_args()
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class BuildIdentityTest(unittest.TestCase):
|
|
21
|
+
def configure(self, tag=None):
|
|
22
|
+
config = (ROOT / "CMakeLists.txt").read_text(encoding="utf-8")
|
|
23
|
+
start = re.search(r"^set\(CLIENT_VERSION_STRING ", config, re.MULTILINE)
|
|
24
|
+
self.assertIsNotNone(start)
|
|
25
|
+
version_block = config[start.start():].split("#=============================", 1)[0]
|
|
26
|
+
metadata = "\n".join(
|
|
27
|
+
re.search(rf"set\({name} [^)]+\)", config).group(0)
|
|
28
|
+
for name in ("CLIENT_VERSION_MAJOR", "CLIENT_VERSION_MINOR", "CLIENT_VERSION_RC")
|
|
29
|
+
)
|
|
30
|
+
with tempfile.TemporaryDirectory(prefix="roots-build-identity-") as directory:
|
|
31
|
+
source = Path(directory)
|
|
32
|
+
(source / "CMakeLists.txt").write_text(
|
|
33
|
+
"cmake_minimum_required(VERSION 3.22)\n"
|
|
34
|
+
"project(IdentityTest LANGUAGES NONE)\n"
|
|
35
|
+
+ metadata + "\n" + version_block
|
|
36
|
+
+ f'configure_file("{ROOT / "cmake/bitcoin-build-config.h.in"}" '
|
|
37
|
+
'"${CMAKE_BINARY_DIR}/identity.h" @ONLY)\n', encoding="utf-8",
|
|
38
|
+
)
|
|
39
|
+
command = [args.cmake, "-S", str(source), "-B", str(source / "build")]
|
|
40
|
+
if tag is not None:
|
|
41
|
+
command.append(f"-DCLIENT_VERSION_TAG={tag}")
|
|
42
|
+
result = subprocess.run(command, capture_output=True, text=True, timeout=30)
|
|
43
|
+
header = source / "build/identity.h"
|
|
44
|
+
return result, header.read_text(encoding="utf-8") if header.exists() else ""
|
|
45
|
+
|
|
46
|
+
def test_release_version_without_git(self):
|
|
47
|
+
for tag in ("v31.1-roots.2", "v31.1-roots.4"):
|
|
48
|
+
with self.subTest(tag=tag):
|
|
49
|
+
result, header = self.configure(tag)
|
|
50
|
+
self.assertEqual(result.returncode, 0, result.stderr)
|
|
51
|
+
self.assertIn(f'#define CLIENT_VERSION_STRING "{tag[1:]}"', header)
|
|
52
|
+
self.assertIn("#define CLIENT_VERSION_MAJOR 31", header)
|
|
53
|
+
self.assertIn("#define CLIENT_VERSION_MINOR 1", header)
|
|
54
|
+
|
|
55
|
+
def test_wrong_base_and_invalid_release(self):
|
|
56
|
+
for tag in ("v30.3-roots.4", "v31x1-roots.4", "v31.1-roots.0", "v31.1-knots.4", ""):
|
|
57
|
+
with self.subTest(tag=tag):
|
|
58
|
+
result, _ = self.configure(tag)
|
|
59
|
+
self.assertNotEqual(result.returncode, 0)
|
|
60
|
+
self.assertIn("CLIENT_VERSION_TAG must be a Roots release tag", result.stderr)
|
|
61
|
+
|
|
62
|
+
def test_default_version(self):
|
|
63
|
+
result, header = self.configure()
|
|
64
|
+
self.assertEqual(result.returncode, 0, result.stderr)
|
|
65
|
+
self.assertIn('#define CLIENT_VERSION_STRING "31.1-roots.1"', header)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
if __name__ == "__main__":
|
|
69
|
+
unittest.main(argv=[__file__] + unittest_args)
|