[pacman-dev,4/7] add CACHE_FEXISTS and CACHE_FCONTENTS test rules

Message ID 20210119183010.12831-4-andrew.gregory.8@gmail.com
State New
Headers show
Series [pacman-dev,1/7] pacman: add -w to -U | expand

Commit Message

Andrew Gregory Jan. 19, 2021, 6:30 p.m. UTC
The existing CACHE_EXISTS rule takes a package, which is not suitable
for -U tests that need to be able to check for specific files.

Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
---
 test/pacman/pmrule.py | 10 ++++++++++
 1 file changed, 10 insertions(+)

Patch

diff --git a/test/pacman/pmrule.py b/test/pacman/pmrule.py
index 59293266..aef73cdb 100644
--- a/test/pacman/pmrule.py
+++ b/test/pacman/pmrule.py
@@ -181,6 +181,16 @@  def check(self, test):
                 if not pkg or not os.path.isfile(
                         os.path.join(cachedir, pkg.filename())):
                     success = 0
+            elif case == "FEXISTS":
+                if not os.path.isfile(os.path.join(cachedir, key)):
+                    success = 0
+            elif case == "FCONTENTS":
+                filename = os.path.join(cachedir, key)
+                try:
+                    with open(filename, 'r') as f:
+                        success = f.read() == value
+                except:
+                    success = 0
         else:
             tap.diag("Rule kind '%s' not found" % kind)
             success = -1