]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: make the diff regex BRE-compatible
authorFrantisek Sumsal <frantisek@sumsal.cz>
Thu, 18 Nov 2021 16:19:03 +0000 (17:19 +0100)
committerFrantisek Sumsal <frantisek@sumsal.cz>
Thu, 18 Nov 2021 21:06:04 +0000 (21:06 +0000)
Since the GNU `diff` utility uses grep-style regular expressions[0], which
use the BRE style, we need to tweak the regex to make it work properly
(most notably - in BRE the meta characters need to be escaped).

```
$ diff a b
21c21
<   Volume Key: 256bit
---
>   Volume Key: 257bit
25c25
< Disk Ceiling: 323.2M
---
> Disk Ceiling: 323.1M

$ diff -I '^\s*Disk (Size|Free|Floor|Ceiling):' a b
21c21
<   Volume Key: 256bit
---
>   Volume Key: 257bit
25c25
< Disk Ceiling: 323.2M
---
> Disk Ceiling: 323.1M

$ diff -I '^\s*Disk \(Size\|Free\|Floor\|Ceiling\):' a b && echo OK
21c21
<   Volume Key: 256bit
---
>   Volume Key: 257bit
```

Caught in one of the nightly CentOS CI cron jobs.

[0] https://www.gnu.org/software/diffutils/manual/html_node/Specified-Lines.html

test/units/testsuite-46.sh

index 6c70b32d45cfee42f12d0223142e4acb73fa2cb2..a136e727d7999f2a63a2a2c715a91b44960337b7 100755 (executable)
@@ -19,7 +19,8 @@ inspect() {
     homectl inspect "$USERNAME" | tee /tmp/a
     userdbctl user "$USERNAME" | tee /tmp/b
 
-    diff -I '/^\s*Disk (Size|Free|Floor|Ceiling):/' /tmp/{a,b}
+    # diff uses the grep BREs for pattern matching
+    diff -I '^\s*Disk \(Size\|Free\|Floor\|Ceiling\):' /tmp/{a,b}
     rm /tmp/{a,b}
 }