[llvm] 1783924 - [llvm-lit] Print environment variables when using env without subcommand (#98414)

via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 29 10:01:01 PDT 2024


Author: Harini0924
Date: 2024-08-29T10:00:58-07:00
New Revision: 178392454e076624674b4a7ddf3fc8bda2e94f0e

URL: https://github.com/llvm/llvm-project/commit/178392454e076624674b4a7ddf3fc8bda2e94f0e
DIFF: https://github.com/llvm/llvm-project/commit/178392454e076624674b4a7ddf3fc8bda2e94f0e.diff

LOG: [llvm-lit] Print environment variables when using env without subcommand (#98414)

This patch addresses an issue with lit's internal shell when env is
without any arguments, it fails with exit code 127 because `env`
requires a subcommand. This patch addresses the issue by encoding the
command to properly return environment variables even when no arguments
are provided.

The error occurred when running the command 
` LIT_USE_INTERNAL_SHELL=1 ninja check-llvm`.

fixes: #102383
This is part of the test cleanups proposed in the RFC: [[RFC] Enabling
the Lit Internal Shell by
Default](https://discourse.llvm.org/t/rfc-enabling-the-lit-internal-shell-by-default/80179)

Added: 
    llvm/utils/lit/tests/Inputs/shtest-env-negative/env-calls-cd.txt
    llvm/utils/lit/tests/Inputs/shtest-env-negative/env-calls-colon.txt
    llvm/utils/lit/tests/Inputs/shtest-env-negative/env-calls-echo.txt
    llvm/utils/lit/tests/Inputs/shtest-env-negative/env-calls-export.txt
    llvm/utils/lit/tests/Inputs/shtest-env-negative/env-calls-mkdir.txt
    llvm/utils/lit/tests/Inputs/shtest-env-negative/env-calls-not-builtin.txt
    llvm/utils/lit/tests/Inputs/shtest-env-negative/env-calls-rm.txt
    llvm/utils/lit/tests/Inputs/shtest-env-negative/lit.cfg
    llvm/utils/lit/tests/Inputs/shtest-env-positive/env-args-last-is-assign.txt
    llvm/utils/lit/tests/Inputs/shtest-env-positive/env-args-last-is-u-arg.txt
    llvm/utils/lit/tests/Inputs/shtest-env-positive/env-args-last-is-u.txt
    llvm/utils/lit/tests/Inputs/shtest-env-positive/env-args-nested-none.txt
    llvm/utils/lit/tests/Inputs/shtest-env-positive/env-calls-env.txt
    llvm/utils/lit/tests/Inputs/shtest-env-positive/env-no-subcommand.txt
    llvm/utils/lit/tests/Inputs/shtest-env-positive/env-u.txt
    llvm/utils/lit/tests/Inputs/shtest-env-positive/env.txt
    llvm/utils/lit/tests/Inputs/shtest-env-positive/lit.cfg
    llvm/utils/lit/tests/Inputs/shtest-env-positive/mixed.txt
    llvm/utils/lit/tests/shtest-env-negative.py
    llvm/utils/lit/tests/shtest-env-positive.py

Modified: 
    llvm/utils/lit/lit/TestRunner.py

Removed: 
    llvm/utils/lit/tests/Inputs/shtest-env/env-args-last-is-assign.txt
    llvm/utils/lit/tests/Inputs/shtest-env/env-args-last-is-u-arg.txt
    llvm/utils/lit/tests/Inputs/shtest-env/env-args-last-is-u.txt
    llvm/utils/lit/tests/Inputs/shtest-env/env-args-nested-none.txt
    llvm/utils/lit/tests/Inputs/shtest-env/env-args-none.txt
    llvm/utils/lit/tests/Inputs/shtest-env/env-calls-cd.txt
    llvm/utils/lit/tests/Inputs/shtest-env/env-calls-colon.txt
    llvm/utils/lit/tests/Inputs/shtest-env/env-calls-echo.txt
    llvm/utils/lit/tests/Inputs/shtest-env/env-calls-env.txt
    llvm/utils/lit/tests/Inputs/shtest-env/env-calls-export.txt
    llvm/utils/lit/tests/Inputs/shtest-env/env-calls-mkdir.txt
    llvm/utils/lit/tests/Inputs/shtest-env/env-calls-not-builtin.txt
    llvm/utils/lit/tests/Inputs/shtest-env/env-calls-rm.txt
    llvm/utils/lit/tests/Inputs/shtest-env/env-u.txt
    llvm/utils/lit/tests/Inputs/shtest-env/env.txt
    llvm/utils/lit/tests/Inputs/shtest-env/lit.cfg
    llvm/utils/lit/tests/Inputs/shtest-env/mixed.txt
    llvm/utils/lit/tests/Inputs/shtest-env/print_environment.py
    llvm/utils/lit/tests/shtest-env.py


################################################################################
diff  --git a/llvm/utils/lit/lit/TestRunner.py b/llvm/utils/lit/lit/TestRunner.py
index 223a6c6e4ca0a2..19f35fc7e212f3 100644
--- a/llvm/utils/lit/lit/TestRunner.py
+++ b/llvm/utils/lit/lit/TestRunner.py
@@ -742,7 +742,16 @@ def _executeShCmd(cmd, shenv, results, timeoutHelper):
                     cmd_shenv = ShellEnvironment(shenv.cwd, shenv.env)
                 args = updateEnv(cmd_shenv, args)
                 if not args:
-                    raise InternalShellError(j, "Error: 'env' requires a" " subcommand")
+                    # Return the environment variables if no argument is provided.
+                    env_str = "\n".join(
+                        f"{key}={value}" for key, value in sorted(cmd_shenv.env.items())
+                    )
+                    results.append(
+                        ShellCommandResult(
+                            j, env_str, "", 0, timeoutHelper.timeoutReached(), []
+                        )
+                    )
+                    return 0
             elif args[0] == "not":
                 not_args.append(args.pop(0))
                 not_count += 1

diff  --git a/llvm/utils/lit/tests/Inputs/shtest-env/env-calls-cd.txt b/llvm/utils/lit/tests/Inputs/shtest-env-negative/env-calls-cd.txt
similarity index 100%
rename from llvm/utils/lit/tests/Inputs/shtest-env/env-calls-cd.txt
rename to llvm/utils/lit/tests/Inputs/shtest-env-negative/env-calls-cd.txt

diff  --git a/llvm/utils/lit/tests/Inputs/shtest-env/env-calls-colon.txt b/llvm/utils/lit/tests/Inputs/shtest-env-negative/env-calls-colon.txt
similarity index 100%
rename from llvm/utils/lit/tests/Inputs/shtest-env/env-calls-colon.txt
rename to llvm/utils/lit/tests/Inputs/shtest-env-negative/env-calls-colon.txt

diff  --git a/llvm/utils/lit/tests/Inputs/shtest-env/env-calls-echo.txt b/llvm/utils/lit/tests/Inputs/shtest-env-negative/env-calls-echo.txt
similarity index 100%
rename from llvm/utils/lit/tests/Inputs/shtest-env/env-calls-echo.txt
rename to llvm/utils/lit/tests/Inputs/shtest-env-negative/env-calls-echo.txt

diff  --git a/llvm/utils/lit/tests/Inputs/shtest-env/env-calls-export.txt b/llvm/utils/lit/tests/Inputs/shtest-env-negative/env-calls-export.txt
similarity index 100%
rename from llvm/utils/lit/tests/Inputs/shtest-env/env-calls-export.txt
rename to llvm/utils/lit/tests/Inputs/shtest-env-negative/env-calls-export.txt

diff  --git a/llvm/utils/lit/tests/Inputs/shtest-env/env-calls-mkdir.txt b/llvm/utils/lit/tests/Inputs/shtest-env-negative/env-calls-mkdir.txt
similarity index 100%
rename from llvm/utils/lit/tests/Inputs/shtest-env/env-calls-mkdir.txt
rename to llvm/utils/lit/tests/Inputs/shtest-env-negative/env-calls-mkdir.txt

diff  --git a/llvm/utils/lit/tests/Inputs/shtest-env/env-calls-not-builtin.txt b/llvm/utils/lit/tests/Inputs/shtest-env-negative/env-calls-not-builtin.txt
similarity index 100%
rename from llvm/utils/lit/tests/Inputs/shtest-env/env-calls-not-builtin.txt
rename to llvm/utils/lit/tests/Inputs/shtest-env-negative/env-calls-not-builtin.txt

diff  --git a/llvm/utils/lit/tests/Inputs/shtest-env/env-calls-rm.txt b/llvm/utils/lit/tests/Inputs/shtest-env-negative/env-calls-rm.txt
similarity index 100%
rename from llvm/utils/lit/tests/Inputs/shtest-env/env-calls-rm.txt
rename to llvm/utils/lit/tests/Inputs/shtest-env-negative/env-calls-rm.txt

diff  --git a/llvm/utils/lit/tests/Inputs/shtest-env/lit.cfg b/llvm/utils/lit/tests/Inputs/shtest-env-negative/lit.cfg
similarity index 90%
rename from llvm/utils/lit/tests/Inputs/shtest-env/lit.cfg
rename to llvm/utils/lit/tests/Inputs/shtest-env-negative/lit.cfg
index df9df7da81daaf..626c00f71d7287 100644
--- a/llvm/utils/lit/tests/Inputs/shtest-env/lit.cfg
+++ b/llvm/utils/lit/tests/Inputs/shtest-env-negative/lit.cfg
@@ -7,4 +7,5 @@ config.test_source_root = None
 config.test_exec_root = None
 config.environment["FOO"] = "1"
 config.environment["BAR"] = "2"
+config.environment["QUX"] = "3"
 config.substitutions.append(("%{python}", '"%s"' % (sys.executable)))

diff  --git a/llvm/utils/lit/tests/Inputs/shtest-env/env-args-last-is-assign.txt b/llvm/utils/lit/tests/Inputs/shtest-env-positive/env-args-last-is-assign.txt
similarity index 100%
rename from llvm/utils/lit/tests/Inputs/shtest-env/env-args-last-is-assign.txt
rename to llvm/utils/lit/tests/Inputs/shtest-env-positive/env-args-last-is-assign.txt

diff  --git a/llvm/utils/lit/tests/Inputs/shtest-env/env-args-last-is-u-arg.txt b/llvm/utils/lit/tests/Inputs/shtest-env-positive/env-args-last-is-u-arg.txt
similarity index 100%
rename from llvm/utils/lit/tests/Inputs/shtest-env/env-args-last-is-u-arg.txt
rename to llvm/utils/lit/tests/Inputs/shtest-env-positive/env-args-last-is-u-arg.txt

diff  --git a/llvm/utils/lit/tests/Inputs/shtest-env/env-args-last-is-u.txt b/llvm/utils/lit/tests/Inputs/shtest-env-positive/env-args-last-is-u.txt
similarity index 100%
rename from llvm/utils/lit/tests/Inputs/shtest-env/env-args-last-is-u.txt
rename to llvm/utils/lit/tests/Inputs/shtest-env-positive/env-args-last-is-u.txt

diff  --git a/llvm/utils/lit/tests/Inputs/shtest-env/env-args-nested-none.txt b/llvm/utils/lit/tests/Inputs/shtest-env-positive/env-args-nested-none.txt
similarity index 100%
rename from llvm/utils/lit/tests/Inputs/shtest-env/env-args-nested-none.txt
rename to llvm/utils/lit/tests/Inputs/shtest-env-positive/env-args-nested-none.txt

diff  --git a/llvm/utils/lit/tests/Inputs/shtest-env-positive/env-calls-env.txt b/llvm/utils/lit/tests/Inputs/shtest-env-positive/env-calls-env.txt
new file mode 100644
index 00000000000000..ee40c60a1e4b65
--- /dev/null
+++ b/llvm/utils/lit/tests/Inputs/shtest-env-positive/env-calls-env.txt
@@ -0,0 +1,32 @@
+## Tests the behaviour of chaining env commands together.
+
+## Check that internal env can call internal env.
+# RUN: env env | FileCheck -check-prefix=CHECK-2-EMPTY-ARGS %s
+#
+# CHECK-2-EMPTY-ARGS: BAR = 2
+# CHECK-2-EMPTY-ARGS: FOO = 1
+
+## Check setting variables in a nested env call.
+# RUN: env FOO=2 env BAR=1 | FileCheck -check-prefix=CHECK-2-VAL %s
+#
+# CHECK-2-VAL: BAR = 1
+# CHECK-2-VAL: FOO = 2
+
+## Check unsetting variables in a nested env call.
+# RUN: env -u FOO env -u BAR | FileCheck -check-prefix=CHECK-2-U %s
+#
+# CHECK-2-U-NOT: BAR
+# CHECK-2-U-NOT: FOO
+
+## Check mixed setting and unsetting in nested env calls.
+# RUN: env -u FOO BAR=1 env -u BAR FOO=2 | FileCheck -check-prefix=CHECK-2-U-VAL %s
+#
+# CHECK-2-U-VAL-NOT: BAR
+# CHECK-2-U-VAL: FOO = 2
+
+## Check setting, unsetting, and adding a new variable in nested env calls.
+# RUN: env -u FOO BAR=1 env -u BAR FOO=2 env BAZ=3 | FileCheck -check-prefix=CHECK-3 %s
+#
+# CHECK-3-NOT: BAR
+# CHECK-3: BAZ = 3
+# CHECK-3: FOO = 2

diff  --git a/llvm/utils/lit/tests/Inputs/shtest-env-positive/env-no-subcommand.txt b/llvm/utils/lit/tests/Inputs/shtest-env-positive/env-no-subcommand.txt
new file mode 100644
index 00000000000000..761a8061a0b0de
--- /dev/null
+++ b/llvm/utils/lit/tests/Inputs/shtest-env-positive/env-no-subcommand.txt
@@ -0,0 +1,37 @@
+## Tests the env command in various scenarios: without arguments, setting, unsetting, and mixing envrionment variables.
+
+## Check default environment.
+# RUN: env | FileCheck -check-prefix=NO-ARGS %s
+#
+# NO-ARGS: BAR=2
+# NO-ARGS: FOO=1
+# NO-ARGS: QUX=3
+
+## Set environment variables.
+# RUN: env FOO=2 BAR=1 | FileCheck -check-prefix=SET-VAL %s
+#
+# SET-VAL: BAR=1
+# SET-VAL: FOO=2
+# SET-VAL: QUX=3
+
+## Unset environment variables.
+# RUN: env -u FOO -u BAR | FileCheck -check-prefix=UNSET-U %s
+#
+# UNSET-U-NOT: BAR
+# UNSET-U-NOT: FOO
+# UNSET-U: QUX=3
+
+## Mixed set and unset environment variables.
+# RUN: env -u FOO BAR=1 -u BAR FOO=2 | FileCheck -check-prefix=MIXED-SET-UNSET %s
+#
+# MIXED-SET-UNSET-NOT: BAR
+# MIXED-SET-UNSET: FOO=2
+# MIXED-SET-UNSET: QUX=3
+
+## Mixed set and unset with additional variable.
+# RUN: env -u FOO BAR=1 -u BAR FOO=2 BAZ=4 | FileCheck -check-prefix=MIXED-SET-UNSET-ADD-3 %s
+#
+# MIXED-SET-UNSET-ADD-NOT: BAR
+# MIXED-SET-UNSET-ADD: BAZ=4
+# MIXED-SET-UNSET-ADD: FOO=2
+# MIXED-SET-UNSET-ADD: QUX=3 

diff  --git a/llvm/utils/lit/tests/Inputs/shtest-env-positive/env-u.txt b/llvm/utils/lit/tests/Inputs/shtest-env-positive/env-u.txt
new file mode 100644
index 00000000000000..2945639c0642df
--- /dev/null
+++ b/llvm/utils/lit/tests/Inputs/shtest-env-positive/env-u.txt
@@ -0,0 +1,22 @@
+## Tests env command for preset variables and handling single/multiple unsets.
+
+## Check and make sure preset environment variable were set in lit.cfg.
+#
+# RUN: env | FileCheck --check-prefix=CHECK-ENV-PRESET %s
+#
+## Check single unset of environment variable.
+#
+# RUN: env -u FOO | FileCheck --check-prefix=CHECK-ENV-UNSET-1 %s
+#
+## Check multiple unsets of environment variables.
+#
+# RUN: env -u FOO -u BAR | FileCheck --check-prefix=CHECK-ENV-UNSET-MULTIPLE %s
+
+# CHECK-ENV-PRESET: BAR = 2
+# CHECK-ENV-PRESET: FOO = 1
+
+# CHECK-ENV-UNSET-1: BAR = 2
+# CHECK-ENV-UNSET-1-NOT: FOO
+
+# CHECK-ENV-UNSET-MULTIPLE-NOT: BAR
+# CHECK-ENV-UNSET-MULTIPLE-NOT: FOO

diff  --git a/llvm/utils/lit/tests/Inputs/shtest-env-positive/env.txt b/llvm/utils/lit/tests/Inputs/shtest-env-positive/env.txt
new file mode 100644
index 00000000000000..74a2a65d260f41
--- /dev/null
+++ b/llvm/utils/lit/tests/Inputs/shtest-env-positive/env.txt
@@ -0,0 +1,15 @@
+## Tests env command for setting single and multiple environment variables.
+
+## Check for simple one environment variable setting.
+#
+# RUN: env A_FOO=999 | FileCheck --check-prefix=CHECK-ENV-1 %s
+#
+## Check for multiple environment variable settings.
+#
+# RUN: env A_FOO=1 B_BAR=2 C_OOF=3 | FileCheck --check-prefix=CHECK-ENV-MULTIPLE %s
+
+# CHECK-ENV-1: A_FOO = 999
+
+# CHECK-ENV-MULTIPLE: A_FOO = 1
+# CHECK-ENV-MULTIPLE: B_BAR = 2
+# CHECK-ENV-MULTIPLE: C_OOF = 3

diff  --git a/llvm/utils/lit/tests/Inputs/shtest-env-positive/lit.cfg b/llvm/utils/lit/tests/Inputs/shtest-env-positive/lit.cfg
new file mode 100644
index 00000000000000..626c00f71d7287
--- /dev/null
+++ b/llvm/utils/lit/tests/Inputs/shtest-env-positive/lit.cfg
@@ -0,0 +1,11 @@
+import lit.formats
+
+config.name = "shtest-env"
+config.suffixes = [".txt"]
+config.test_format = lit.formats.ShTest()
+config.test_source_root = None
+config.test_exec_root = None
+config.environment["FOO"] = "1"
+config.environment["BAR"] = "2"
+config.environment["QUX"] = "3"
+config.substitutions.append(("%{python}", '"%s"' % (sys.executable)))

diff  --git a/llvm/utils/lit/tests/Inputs/shtest-env-positive/mixed.txt b/llvm/utils/lit/tests/Inputs/shtest-env-positive/mixed.txt
new file mode 100644
index 00000000000000..c2c4e8bfdfc8bd
--- /dev/null
+++ b/llvm/utils/lit/tests/Inputs/shtest-env-positive/mixed.txt
@@ -0,0 +1,18 @@
+## Tests env command for setting and unsetting single and multiple environment variables.
+
+## Check for setting and removing one environment variable
+#
+# RUN: env A_FOO=999 -u FOO | FileCheck --check-prefix=CHECK-ENV-1 %s
+#
+## Check for setting/unsetting multiple environment variables
+#
+# RUN: env A_FOO=1 -u FOO B_BAR=2 -u BAR C_OOF=3 | FileCheck --check-prefix=CHECK-ENV-MULTIPLE %s
+
+# CHECK-ENV-1: A_FOO = 999
+# CHECK-ENV-1-NOT: FOO
+
+# CHECK-ENV-MULTIPLE: A_FOO = 1
+# CHECK-ENV-MULTIPLE-NOT: BAR
+# CHECK-ENV-MULTIPLE: B_BAR = 2
+# CHECK-ENV-MULTIPLE: C_OOF = 3
+# CHECK-ENV-MULTIPLE-NOT: FOO

diff  --git a/llvm/utils/lit/tests/Inputs/shtest-env/env-args-none.txt b/llvm/utils/lit/tests/Inputs/shtest-env/env-args-none.txt
deleted file mode 100644
index dc5cdbad09afc9..00000000000000
--- a/llvm/utils/lit/tests/Inputs/shtest-env/env-args-none.txt
+++ /dev/null
@@ -1 +0,0 @@
-# RUN: env

diff  --git a/llvm/utils/lit/tests/Inputs/shtest-env/env-calls-env.txt b/llvm/utils/lit/tests/Inputs/shtest-env/env-calls-env.txt
deleted file mode 100644
index 26150c413dc03d..00000000000000
--- a/llvm/utils/lit/tests/Inputs/shtest-env/env-calls-env.txt
+++ /dev/null
@@ -1,32 +0,0 @@
-# Check that internal env can call internal env.
-
-# RUN: env env %{python} print_environment.py \
-# RUN: | FileCheck -check-prefix=CHECK-2-EMPTY-ARGS %s
-#
-# CHECK-2-EMPTY-ARGS: BAR = 2
-# CHECK-2-EMPTY-ARGS: FOO = 1
-
-# RUN: env FOO=2 env BAR=1 %{python} print_environment.py \
-# RUN: | FileCheck -check-prefix=CHECK-2-VAL %s
-#
-# CHECK-2-VAL: BAR = 1
-# CHECK-2-VAL: FOO = 2
-
-# RUN: env -u FOO env -u BAR %{python} print_environment.py \
-# RUN: | FileCheck -check-prefix=CHECK-2-U %s
-#
-# CHECK-2-U-NOT: BAR
-# CHECK-2-U-NOT: FOO
-
-# RUN: env -u FOO BAR=1 env -u BAR FOO=2 %{python} print_environment.py \
-# RUN: | FileCheck -check-prefix=CHECK-2-U-VAL %s
-#
-# CHECK-2-U-VAL-NOT: BAR
-# CHECK-2-U-VAL: FOO = 2
-
-# RUN: env -u FOO BAR=1 env -u BAR FOO=2 env BAZ=3 %{python} print_environment.py \
-# RUN: | FileCheck -check-prefix=CHECK-3 %s
-#
-# CHECK-3-NOT: BAR
-# CHECK-3: BAZ = 3
-# CHECK-3: FOO = 2

diff  --git a/llvm/utils/lit/tests/Inputs/shtest-env/env-u.txt b/llvm/utils/lit/tests/Inputs/shtest-env/env-u.txt
deleted file mode 100644
index 9cdf9d08850f78..00000000000000
--- a/llvm/utils/lit/tests/Inputs/shtest-env/env-u.txt
+++ /dev/null
@@ -1,23 +0,0 @@
-# Check and make sure preset environment variable were set in lit.cfg
-#
-# RUN: %{python} print_environment.py \
-# RUN:   | FileCheck --check-prefix=CHECK-ENV-PRESET %s
-#
-# Check single unset of environment variable
-#
-# RUN: env -u FOO %{python} print_environment.py \
-# RUN:  | FileCheck --check-prefix=CHECK-ENV-UNSET-1 %s
-#
-# Check multiple unsets of environment variables
-#
-# RUN: env -u FOO -u BAR %{python} print_environment.py \
-# RUN:  | FileCheck --check-prefix=CHECK-ENV-UNSET-MULTIPLE %s
-
-# CHECK-ENV-PRESET: BAR = 2
-# CHECK-ENV-PRESET: FOO = 1
-
-# CHECK-ENV-UNSET-1: BAR = 2
-# CHECK-ENV-UNSET-1-NOT: FOO
-
-# CHECK-ENV-UNSET-MULTIPLE-NOT: BAR
-# CHECK-ENV-UNSET-MULTIPLE-NOT: FOO

diff  --git a/llvm/utils/lit/tests/Inputs/shtest-env/env.txt b/llvm/utils/lit/tests/Inputs/shtest-env/env.txt
deleted file mode 100644
index aa697b0c4081f4..00000000000000
--- a/llvm/utils/lit/tests/Inputs/shtest-env/env.txt
+++ /dev/null
@@ -1,15 +0,0 @@
-# Check for simple one environment variable setting
-#
-# RUN: env A_FOO=999 %{python} print_environment.py \
-# RUN:   | FileCheck --check-prefix=CHECK-ENV-1 %s
-#
-# Check for multiple environment variable settings
-#
-# RUN: env A_FOO=1 B_BAR=2 C_OOF=3 %{python} print_environment.py \
-# RUN:   | FileCheck --check-prefix=CHECK-ENV-MULTIPLE %s
-
-# CHECK-ENV-1: A_FOO = 999
-
-# CHECK-ENV-MULTIPLE: A_FOO = 1
-# CHECK-ENV-MULTIPLE: B_BAR = 2
-# CHECK-ENV-MULTIPLE: C_OOF = 3

diff  --git a/llvm/utils/lit/tests/Inputs/shtest-env/mixed.txt b/llvm/utils/lit/tests/Inputs/shtest-env/mixed.txt
deleted file mode 100644
index be32d458843bc3..00000000000000
--- a/llvm/utils/lit/tests/Inputs/shtest-env/mixed.txt
+++ /dev/null
@@ -1,18 +0,0 @@
-# Check for setting and removing one environment variable
-#
-# RUN: env A_FOO=999 -u FOO %{python} print_environment.py \
-# RUN:   | FileCheck --check-prefix=CHECK-ENV-1 %s
-#
-# Check for setting/unsetting multiple environment variables
-#
-# RUN: env A_FOO=1 -u FOO B_BAR=2 -u BAR C_OOF=3 %{python} print_environment.py \
-# RUN:   | FileCheck --check-prefix=CHECK-ENV-MULTIPLE %s
-
-# CHECK-ENV-1: A_FOO = 999
-# CHECK-ENV-1-NOT: FOO
-
-# CHECK-ENV-MULTIPLE: A_FOO = 1
-# CHECK-ENV-MULTIPLE-NOT: BAR
-# CHECK-ENV-MULTIPLE: B_BAR = 2
-# CHECK-ENV-MULTIPLE: C_OOF = 3
-# CHECK-ENV-MULTIPLE-NOT: FOO

diff  --git a/llvm/utils/lit/tests/Inputs/shtest-env/print_environment.py b/llvm/utils/lit/tests/Inputs/shtest-env/print_environment.py
deleted file mode 100644
index e39bd73e44a108..00000000000000
--- a/llvm/utils/lit/tests/Inputs/shtest-env/print_environment.py
+++ /dev/null
@@ -1,9 +0,0 @@
-#!/usr/bin/env python
-
-from __future__ import print_function
-import os
-
-sorted_environment = sorted(os.environ.items())
-
-for name, value in sorted_environment:
-    print(name, "=", value)

diff  --git a/llvm/utils/lit/tests/shtest-env-negative.py b/llvm/utils/lit/tests/shtest-env-negative.py
new file mode 100644
index 00000000000000..c8b59b224e7c43
--- /dev/null
+++ b/llvm/utils/lit/tests/shtest-env-negative.py
@@ -0,0 +1,49 @@
+## Test the env command (failing tests).
+
+# RUN: not %{lit} -a -v %{inputs}/shtest-env-negative \
+# RUN: | FileCheck -match-full-lines %s
+#
+# END.
+
+## Test the env command's expected failures.
+
+# CHECK: -- Testing: 7 tests{{.*}}
+
+# CHECK: FAIL: shtest-env :: env-calls-cd.txt ({{[^)]*}})
+# CHECK: env -u FOO BAR=3 cd foobar
+# CHECK: # executed command: env -u FOO BAR=3 cd foobar
+# CHECK: # error: command failed with exit status: {{.*}}
+
+# CHECK: FAIL: shtest-env :: env-calls-colon.txt ({{[^)]*}})
+# CHECK: env -u FOO BAR=3 :
+# CHECK: # executed command: env -u FOO BAR=3 :
+# CHECK: # error: command failed with exit status: {{.*}}
+
+# CHECK: FAIL: shtest-env :: env-calls-echo.txt ({{[^)]*}})
+# CHECK: env -u FOO BAR=3 echo hello world
+# CHECK: # executed command: env -u FOO BAR=3 echo hello world
+# CHECK: # error: command failed with exit status: {{.*}}
+
+# CHECK: FAIL: shtest-env :: env-calls-export.txt ({{[^)]*}})
+# CHECK: env -u FOO BAR=3 export BAZ=3
+# CHECK: # executed command: env -u FOO BAR=3 export BAZ=3
+# CHECK: # error: command failed with exit status: {{.*}}
+
+# CHECK: FAIL: shtest-env :: env-calls-mkdir.txt ({{[^)]*}})
+# CHECK: env -u FOO BAR=3 mkdir foobar
+# CHECK: # executed command: env -u FOO BAR=3 mkdir foobar
+# CHECK: # error: command failed with exit status: {{.*}}
+
+# CHECK: FAIL: shtest-env :: env-calls-not-builtin.txt ({{[^)]*}})
+# CHECK: env -u FOO BAR=3 not rm {{.+}}.no-such-file
+# CHECK: # executed command: env -u FOO BAR=3 not rm {{.+}}.no-such-file{{.*}}
+# CHECK: # error: command failed with exit status: {{.*}}
+
+# CHECK: FAIL: shtest-env :: env-calls-rm.txt ({{[^)]*}})
+# CHECK: env -u FOO BAR=3 rm foobar
+# CHECK: # executed command: env -u FOO BAR=3 rm foobar
+# CHECK: # error: command failed with exit status: {{.*}}
+
+# CHECK: Total Discovered Tests: 7
+# CHECK: Failed: 7 {{\([0-9]*\.[0-9]*%\)}}
+# CHECK-NOT: {{.}}

diff  --git a/llvm/utils/lit/tests/shtest-env-positive.py b/llvm/utils/lit/tests/shtest-env-positive.py
new file mode 100644
index 00000000000000..863fbda8c5b6dc
--- /dev/null
+++ b/llvm/utils/lit/tests/shtest-env-positive.py
@@ -0,0 +1,70 @@
+## Test the env command (passing tests).
+
+# RUN: %{lit} -a -v %{inputs}/shtest-env-positive \
+# RUN: | FileCheck -match-full-lines %s
+#
+# END.
+
+## Test the env command's successful executions.
+
+# CHECK: -- Testing: 9 tests{{.*}}
+
+# CHECK: PASS: shtest-env :: env-args-last-is-assign.txt ({{[^)]*}})
+# CHECK: env FOO=1
+# CHECK: # executed command: env FOO=1
+# CHECK-NOT: # error:
+# CHECK: --
+
+# CHECK: PASS: shtest-env :: env-args-last-is-u-arg.txt ({{[^)]*}})
+# CHECK: env -u FOO
+# CHECK: # executed command: env -u FOO
+# CHECK-NOT: # error:
+# CHECK: --
+
+# CHECK: PASS: shtest-env :: env-args-last-is-u.txt ({{[^)]*}})
+# CHECK: env -u
+# CHECK: # executed command: env -u
+# CHECK-NOT: # error:
+# CHECK: --
+
+# CHECK: PASS: shtest-env :: env-args-nested-none.txt ({{[^)]*}})
+# CHECK: env env env
+# CHECK: # executed command: env env env
+# CHECK-NOT: # error:
+# CHECK: --
+
+# CHECK: PASS: shtest-env :: env-calls-env.txt ({{[^)]*}})
+# CHECK: env env | {{.*}}
+# CHECK: # executed command: env env
+# CHECK-NOT: # error:
+# CHECK: --
+
+# CHECK: PASS: shtest-env :: env-no-subcommand.txt ({{[^)]*}})
+# CHECK: env | {{.*}}
+# CHECK: # executed command: env
+# CHECK: env FOO=2 BAR=1 | {{.*}}
+# CHECK: # executed command: env FOO=2 BAR=1
+# CHECK-NOT: # error:
+# CHECK: --
+
+# CHECK: PASS: shtest-env :: env-u.txt ({{[^)]*}})
+# CHECK: env -u FOO | {{.*}}
+# CHECK: # executed command: env -u FOO
+# CHECK-NOT: # error:
+# CHECK: --
+
+# CHECK: PASS: shtest-env :: env.txt ({{[^)]*}})
+# CHECK: env A_FOO=999 | {{.*}}
+# CHECK: # executed command: env A_FOO=999
+# CHECK-NOT: # error:
+# CHECK: --
+
+# CHECK: PASS: shtest-env :: mixed.txt ({{[^)]*}})
+# CHECK: env A_FOO=999 -u FOO | {{.*}}
+# CHECK: # executed command: env A_FOO=999 -u FOO
+# CHECK-NOT: # error:
+# CHECK: --
+
+# CHECK: Total Discovered Tests: 9
+# CHECK: Passed: 9 {{\([0-9]*\.[0-9]*%\)}}
+# CHECK-NOT: {{.}}

diff  --git a/llvm/utils/lit/tests/shtest-env.py b/llvm/utils/lit/tests/shtest-env.py
deleted file mode 100644
index 03bb4a3cae7dd1..00000000000000
--- a/llvm/utils/lit/tests/shtest-env.py
+++ /dev/null
@@ -1,126 +0,0 @@
-# Check the env command
-
-# RUN: not %{lit} -a -v %{inputs}/shtest-env \
-# RUN: | FileCheck -match-full-lines %s
-#
-# END.
-
-# Make sure env commands are included in printed commands.
-
-# CHECK: -- Testing: 16 tests{{.*}}
-
-# CHECK: FAIL: shtest-env :: env-args-last-is-assign.txt ({{[^)]*}})
-# CHECK: env FOO=1
-# CHECK: # executed command: env FOO=1
-# CHECK: # | Error: 'env' requires a subcommand
-# CHECK: # error: command failed with exit status: {{.*}}
-
-# CHECK: FAIL: shtest-env :: env-args-last-is-u-arg.txt ({{[^)]*}})
-# CHECK: env -u FOO
-# CHECK: # executed command: env -u FOO
-# CHECK: # | Error: 'env' requires a subcommand
-# CHECK: # error: command failed with exit status: {{.*}}
-
-# CHECK: FAIL: shtest-env :: env-args-last-is-u.txt ({{[^)]*}})
-# CHECK: env -u
-# CHECK: # executed command: env -u
-# CHECK: # | Error: 'env' requires a subcommand
-# CHECK: # error: command failed with exit status: {{.*}}
-
-# CHECK: FAIL: shtest-env :: env-args-nested-none.txt ({{[^)]*}})
-# CHECK: env env env
-# CHECK: # executed command: env env env
-# CHECK: # | Error: 'env' requires a subcommand
-# CHECK: # error: command failed with exit status: {{.*}}
-
-# CHECK: FAIL: shtest-env :: env-args-none.txt ({{[^)]*}})
-# CHECK: env
-# CHECK: # executed command: env
-# CHECK: # | Error: 'env' requires a subcommand
-# CHECK: # error: command failed with exit status: {{.*}}
-
-# CHECK: FAIL: shtest-env :: env-calls-cd.txt ({{[^)]*}})
-# CHECK: env -u FOO BAR=3 cd foobar
-# CHECK: # executed command: env -u FOO BAR=3 cd foobar
-# CHECK: # | Error: 'env' cannot call 'cd'
-# CHECK: # error: command failed with exit status: {{.*}}
-
-# CHECK: FAIL: shtest-env :: env-calls-colon.txt ({{[^)]*}})
-# CHECK: env -u FOO BAR=3 :
-# CHECK: # executed command: env -u FOO BAR=3 :
-# CHECK: # | Error: 'env' cannot call ':'
-# CHECK: # error: command failed with exit status: {{.*}}
-
-# CHECK: FAIL: shtest-env :: env-calls-echo.txt ({{[^)]*}})
-# CHECK: env -u FOO BAR=3 echo hello world
-# CHECK: # executed command: env -u FOO BAR=3 echo hello world
-# CHECK: # | Error: 'env' cannot call 'echo'
-# CHECK: # error: command failed with exit status: {{.*}}
-
-# CHECK: PASS: shtest-env :: env-calls-env.txt ({{[^)]*}})
-# CHECK: env env [[PYTHON:.+]] print_environment.py | {{.*}}
-# CHECK: # executed command: env env [[PYTHON_BARE:.+]] print_environment.py
-# CHECK: env FOO=2 env BAR=1 [[PYTHON]] print_environment.py | {{.*}}
-# CHECK: # executed command: env FOO=2 env BAR=1 [[PYTHON_BARE]] print_environment.py
-# CHECK: env -u FOO env -u BAR [[PYTHON]] print_environment.py | {{.*}}
-# CHECK: # executed command: env -u FOO env -u BAR [[PYTHON_BARE]] print_environment.py
-# CHECK: env -u FOO BAR=1 env -u BAR FOO=2 [[PYTHON]] print_environment.py | {{.*}}
-# CHECK: # executed command: env -u FOO BAR=1 env -u BAR FOO=2 [[PYTHON_BARE]] print_environment.py
-# CHECK: env -u FOO BAR=1 env -u BAR FOO=2 env BAZ=3 [[PYTHON]] print_environment.py | {{.*}}
-# CHECK: # executed command: env -u FOO BAR=1 env -u BAR FOO=2 env BAZ=3 [[PYTHON_BARE]] print_environment.py
-# CHECK-NOT: {{^[^#]}}
-# CHECK: --
-
-# CHECK: FAIL: shtest-env :: env-calls-export.txt ({{[^)]*}})
-# CHECK: env -u FOO BAR=3 export BAZ=3
-# CHECK: # executed command: env -u FOO BAR=3 export BAZ=3
-# CHECK: # | Error: 'env' cannot call 'export'
-# CHECK: # error: command failed with exit status: {{.*}}
-
-# CHECK: FAIL: shtest-env :: env-calls-mkdir.txt ({{[^)]*}})
-# CHECK: env -u FOO BAR=3 mkdir foobar
-# CHECK: # executed command: env -u FOO BAR=3 mkdir foobar
-# CHECK: # | Error: 'env' cannot call 'mkdir'
-# CHECK: # error: command failed with exit status: {{.*}}
-
-# CHECK: FAIL: shtest-env :: env-calls-not-builtin.txt ({{[^)]*}})
-# CHECK: env -u FOO BAR=3 not rm {{.+}}.no-such-file
-# CHECK: # executed command: env -u FOO BAR=3 not rm {{.+}}.no-such-file{{.*}}
-# CHECK: # | Error: 'env' cannot call 'rm'
-# CHECK: # error: command failed with exit status: {{.*}}
-
-# CHECK: FAIL: shtest-env :: env-calls-rm.txt ({{[^)]*}})
-# CHECK: env -u FOO BAR=3 rm foobar
-# CHECK: # executed command: env -u FOO BAR=3 rm foobar
-# CHECK: # | Error: 'env' cannot call 'rm'
-# CHECK: # error: command failed with exit status: {{.*}}
-
-# CHECK: PASS: shtest-env :: env-u.txt ({{[^)]*}})
-# CHECK: [[PYTHON]] print_environment.py | {{.*}}
-# CHECK: env -u FOO [[PYTHON]] print_environment.py | {{.*}}
-# CHECK: # executed command: env -u FOO [[PYTHON_BARE]] print_environment.py
-# CHECK: env -u FOO -u BAR [[PYTHON]] print_environment.py | {{.*}}
-# CHECK: # executed command: env -u FOO -u BAR [[PYTHON_BARE]] print_environment.py
-# CHECK-NOT: {{^[^#]}}
-# CHECK: --
-
-# CHECK: PASS: shtest-env :: env.txt ({{[^)]*}})
-# CHECK: env A_FOO=999 [[PYTHON]] print_environment.py | {{.*}}
-# CHECK: # executed command: env A_FOO=999 [[PYTHON_BARE]] print_environment.py
-# CHECK: env A_FOO=1 B_BAR=2 C_OOF=3 [[PYTHON]] print_environment.py | {{.*}}
-# CHECK: # executed command: env A_FOO=1 B_BAR=2 C_OOF=3 [[PYTHON_BARE]] print_environment.py
-# CHECK-NOT: {{^[^#]}}
-# CHECK: --
-
-# CHECK: PASS: shtest-env :: mixed.txt ({{[^)]*}})
-# CHECK: env A_FOO=999 -u FOO [[PYTHON]] print_environment.py | {{.*}}
-# CHECK: # executed command: env A_FOO=999 -u FOO [[PYTHON_BARE]] print_environment.py
-# CHECK: env A_FOO=1 -u FOO B_BAR=2 -u BAR C_OOF=3 [[PYTHON]] print_environment.py | {{.*}}
-# CHECK: # executed command: env A_FOO=1 -u FOO B_BAR=2 -u BAR C_OOF=3 [[PYTHON_BARE]] print_environment.py
-# CHECK-NOT: {{^[^#]}}
-# CHECK: --
-
-# CHECK: Total Discovered Tests: 16
-# CHECK: Passed:  4 {{\([0-9]*\.[0-9]*%\)}}
-# CHECK: Failed: 12 {{\([0-9]*\.[0-9]*%\)}}
-# CHECK-NOT: {{.}}


        


More information about the llvm-commits mailing list