File: 0017-testHumanBytes-Skip-2-GiB-test-on-32-bit-systems.patch

package info (click to toggle)
shaarli 0.14.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 5,612 kB
  • sloc: php: 30,001; javascript: 2,083; makefile: 139; xml: 69; python: 42; sh: 35
file content (29 lines) | stat: -rw-r--r-- 1,511 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
From: James Valleroy <jvalleroy@mailbox.org>
Date: Sun, 10 Dec 2023 08:16:17 -0500
Subject: testHumanBytes: Skip 2 GiB test on 32-bit systems

---
 tests/UtilsTest.php | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/tests/UtilsTest.php b/tests/UtilsTest.php
index a18c01b..44d4755 100644
--- a/tests/UtilsTest.php
+++ b/tests/UtilsTest.php
@@ -319,8 +319,14 @@ class UtilsTest extends TestCase
         $this->assertEquals('2' . t('kiB'), human_bytes(strval(2 * 1024)));
         $this->assertEquals('2' . t('MiB'), human_bytes(2 * (pow(1024, 2))));
         $this->assertEquals('2' . t('MiB'), human_bytes(strval(2 * (pow(1024, 2)))));
-        $this->assertEquals('2' . t('GiB'), human_bytes(2 * (pow(1024, 3))));
-        $this->assertEquals('2' . t('GiB'), human_bytes(strval(2 * (pow(1024, 3)))));
+        /* human_bytes only works for valid integers. On 32-bit
+         * systems, this is less than 2 GiB. Note that human_bytes is
+         * only used for get_max_upload_size, so it is very unlikely
+         * to cause an issue in production systems. */
+        if (PHP_INT_SIZE > 4) {
+            $this->assertEquals('2'. t('GiB'), human_bytes(2 * (pow(1024, 3))));
+            $this->assertEquals('2'. t('GiB'), human_bytes(strval(2 * (pow(1024, 3)))));
+        }
         $this->assertEquals('374' . t('B'), human_bytes(374));
         $this->assertEquals('374' . t('B'), human_bytes('374'));
         $this->assertEquals('232' . t('kiB'), human_bytes(237481));