[Lldb-commits] [PATCH] D50751: WIP: Expose FileCheck-style testing within lldb inline tests
Vedant Kumar via Phabricator via lldb-commits
lldb-commits at lists.llvm.org
Tue Aug 14 17:28:36 PDT 2018
vsk created this revision.
This patch isn't quite ready for review. It's a simple proof-of-concept which shows what it would take to make FileCheck available within lldb inline tests. I'll kick off a discussion about this on lldb-dev.
https://reviews.llvm.org/D50751
Files:
lldb/packages/Python/lldbsuite/test/lldbtest.py
Index: lldb/packages/Python/lldbsuite/test/lldbtest.py
===================================================================
--- lldb/packages/Python/lldbsuite/test/lldbtest.py
+++ lldb/packages/Python/lldbsuite/test/lldbtest.py
@@ -48,6 +48,8 @@
import signal
from subprocess import *
import sys
+import commands
+import tempfile
import time
import traceback
import types
@@ -2143,6 +2145,53 @@
return match_object
+ def filecheck(
+ self,
+ command,
+ check_file,
+ filecheck_options = '',
+ trace = False):
+ # Run the command.
+ self.runCmd(
+ command,
+ msg="FileCheck'ing result of `{0}`".format(command))
+
+ # Get the error text if there was an error, and the regular text if not.
+ output = self.res.GetOutput() if self.res.Succeeded() \
+ else self.res.GetError()
+
+ # Write the output to a temporary file.
+ input_file = tempfile.NamedTemporaryFile()
+ input_file.write(output)
+ input_file.flush()
+
+ self.assertTrue(len(output) > 0, "No output to FileCheck")
+
+ # Assemble the absolute path to the check file.
+ check_file_abs = os.path.join(os.path.dirname(self.test_filename),
+ check_file)
+
+ # Run FileCheck. Source the check lines from the inline test.
+ filecheck_bin = os.path.join(os.path.dirname(configuration.compiler),
+ 'FileCheck')
+ filecheck_cmd = "{0} {1} -input-file {2} {3}".format(filecheck_bin,
+ check_file_abs, input_file.name, filecheck_options)
+
+ if not is_exe(filecheck_bin):
+ with recording(self, trace) as sbuf:
+ print("warning: FileCheck not found, skipping command:",
+ filecheck_cmd, file=sbuf)
+ return
+
+ (cmd_status, cmd_output) = commands.getstatusoutput(filecheck_cmd)
+
+ with recording(self, trace) as sbuf:
+ print("filecheck:", filecheck_cmd, file=sbuf)
+
+ self.assertTrue(cmd_status == 0,
+ "FileCheck failed (code={0}):\n\n{1}".format(cmd_status,
+ cmd_output))
+
def expect(
self,
str,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D50751.160729.patch
Type: text/x-patch
Size: 2278 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20180815/14c6b4cb/attachment.bin>
More information about the lldb-commits
mailing list