================
@@ -914,6 +914,25 @@ def checkForkVForkSupport():
         configuration.skip_categories.append("fork")
 
 
+def checkPexpectSupport():
+    from lldbsuite.test import lldbplatformutil
+
+    platform = lldbplatformutil.getPlatform()
+
+    # llvm.org/pr22274: need a pexpect replacement for windows
+    if platform in ["windows"]:
+        if configuration.verbose:
+            print("pexpect tests will be skipped because of unsupported 
platform")
+        configuration.skip_categories.append("pexpect")
+    elif not configuration.shouldSkipBecauseOfCategories(["pexpect"]):
+        try:
+            import pexpect
+        except:
+            print(
+                "Warning: pexpect is not installed, but pexpect tests are not 
being skipped."
----------------
rupprecht wrote:

`checkPexpectSupport()` will be called for every test, just like the other 
check* methods above.

This `try` block here will only run if a non-Windows platform is configured to 
run `pexpect` tests, either because:
* The test is running w/ various `--skip-category=foo --skip-category=bar`, and 
`pexpect` is not one of the skipped categories, or
* The test is running w/ `--category=pexpect` (this is unusual)

I don't think there's a way to only run this check if the test has a certain 
category. We don't know what the category is, because the test file isn't 
loaded, and loading it would mean potentially evaluating the `import pexpect` 
statement that will fail.

The whole `elif` block is just to provide a better message if `pexpect` is not 
installed. If I remove it, then running a `pexpect` test will fail like so:

```
$ bin/lldb-dotest -p TestSTTYBeforeAndAfter.py
...
lldb version 19.0.0git (https://github.com/llvm/llvm-project.git revision 
b5e04eb49c89c8c654305c6ba5db5e2f237bccec)
  clang revision b5e04eb49c89c8c654305c6ba5db5e2f237bccec
  llvm revision b5e04eb49c89c8c654305c6ba5db5e2f237bccec
Skipping the following test categories: ['dsym', 'gmodules', 'debugserver', 
'objc']
FAIL: LLDB (/home/rupprecht/src/llvm-build/dev/bin/clang-x86_64) :: 
test_stty_dash_a_before_and_afetr_invoking_lldb_command 
(TestSTTYBeforeAndAfter.TestSTTYBeforeAndAfter.test_stty_dash_a_before_and_afetr_invoking_lldb_command)
======================================================================
ERROR: test_stty_dash_a_before_and_afetr_invoking_lldb_command 
(TestSTTYBeforeAndAfter.TestSTTYBeforeAndAfter.test_stty_dash_a_before_and_afetr_invoking_lldb_command)
   Test that 'stty -a' displays the same output before and after running the 
lldb command.
----------------------------------------------------------------------
Traceback (most recent call last):
  File 
"/home/rupprecht/src/llvm-project/lldb/packages/Python/lldbsuite/test/decorators.py",
 line 446, in wrapper
    return func(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File 
"/home/rupprecht/src/llvm-project/lldb/test/API/terminal/TestSTTYBeforeAndAfter.py",
 line 26, in test_stty_dash_a_before_and_afetr_invoking_lldb_command
    import pexpect
ModuleNotFoundError: No module named 'pexpect'
Config=x86_64-/home/rupprecht/src/llvm-build/dev/bin/clang
----------------------------------------------------------------------
Ran 1 test in 0.011s

FAILED (errors=1)
```

I suppose the error raised by the `elif` block, as written, doesn't provide 
much benefit on top of that -- it's clear that the issue is trying to run a 
pexpect test w/o pexpect being installed. So maybe I should replace it with 
something more actionable, e.g. to suggest configuring cmake w/ 
`-DLLDB_TEST_USER_ARGS=--skip-category=pexpect`. Or just remove it altogether?

https://github.com/llvm/llvm-project/pull/84860
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to