git: 1c7843495664 - stable/13 - testing: provide meaningful error when pytest is not available

From: Alexander V. Chernikov <melifaro_at_FreeBSD.org>
Date: Fri, 13 Jan 2023 21:25:30 UTC
The branch stable/13 has been updated by melifaro:

URL: https://cgit.FreeBSD.org/src/commit/?id=1c78434956641ee7b722f4f2a6cbcf5394753887

commit 1c78434956641ee7b722f4f2a6cbcf5394753887
Author:     Alexander V. Chernikov <melifaro@FreeBSD.org>
AuthorDate: 2022-07-06 19:55:48 +0000
Commit:     Alexander V. Chernikov <melifaro@FreeBSD.org>
CommitDate: 2023-01-13 21:24:10 +0000

    testing: provide meaningful error when pytest is not available
    
    atf format does not provide any way of signalling any error message
     back to the atf runner when listing tests. Work this around by
     reporting "__test_cases_list_pytest_binary_not_found__" test instead.
    
    Reviewed By: kp
    Differential Revision: https://reviews.freebsd.org/D35721
    
    (cherry picked from commit 2bfd8b5b9419b0ceb3dd0295fdf413d32969e5b2)
---
 .../atf/atf-pytest-wrapper/atf_pytest_wrapper.cpp  | 23 +++++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)

diff --git a/libexec/atf/atf-pytest-wrapper/atf_pytest_wrapper.cpp b/libexec/atf/atf-pytest-wrapper/atf_pytest_wrapper.cpp
index 6baa85999070..7f6e886a16d9 100644
--- a/libexec/atf/atf-pytest-wrapper/atf_pytest_wrapper.cpp
+++ b/libexec/atf/atf-pytest-wrapper/atf_pytest_wrapper.cpp
@@ -1,3 +1,5 @@
+// vim: ts=2 sw=2 et
+
 #include <format>
 #include <iostream>
 #include <map>
@@ -181,7 +183,7 @@ class Handler {
       }
     }
 
-    int Run(std::string binary, std::vector<std::string> args) {
+    bool Run(std::string binary, std::vector<std::string> args) {
       if (flag_debug) {
         PrintVector("OUT", args);
       }
@@ -191,12 +193,27 @@ class Handler {
 	// work around 'char *const *'
         arr[i] = strdup(args[i].c_str());
       }
-      return (execvp(binary.c_str(), arr) != 0);
+      return execvp(binary.c_str(), arr) == 0;
+    }
+
+    void ReportError() {
+      if (flag_list) {
+        std::cout << "Content-Type: application/X-atf-tp; version=\"1\"";
+        std::cout << std::endl << std::endl;
+        std::cout << "ident: __test_cases_list_"<< kPytestName << "_binary_" <<
+          "not_found__" << std::endl;
+      } else {
+        std::cout << "execvp(" << kPytestName << ") failed: " <<
+            std::strerror(errno) << std::endl;
+      }
     }
 
     int Process() {
       SetEnv();
-      return Run(kPytestName, BuildArgs());
+      if (!Run(kPytestName, BuildArgs())) {
+        ReportError();
+      }
+      return 0;
     }
 };