tests/lib/conds: make `condMain()` take a span for args
[babeltrace.git] / tests / lib / conds / utils.cpp
index 28f0ba40748eecf0000e2811817eea603ac08546..b7d2c487e03504eac70ed44f47f8ebb826154b55 100644 (file)
@@ -4,6 +4,7 @@
  * Copyright (C) 2020 Philippe Proulx <pproulx@efficios.com>
  */
 
+#include <glib.h>
 #include <stdlib.h>
 #include <string.h>
 
 #include "utils.hpp"
 
 CondTrigger::CondTrigger(const Type type, const std::string& condId,
-                         const bt2s::optional<std::string>& nameSuffix) noexcept :
+                         const bt2c::CStringView nameSuffix) noexcept :
     _mType {type},
     _mCondId {fmt::format("{}:{}", type == Type::PRE ? "pre" : "post", condId)},
-    _mName {
-        fmt::format("{}{}{}", condId, nameSuffix ? "-" : "", nameSuffix ? nameSuffix->data() : "")}
+    _mName {fmt::format("{}{}{}", condId, nameSuffix ? "-" : "", nameSuffix ? nameSuffix : "")}
 {
 }
 
 SimpleCondTrigger::SimpleCondTrigger(std::function<void()> func, const Type type,
                                      const std::string& condId,
-                                     const bt2s::optional<std::string>& nameSuffix) :
+                                     const bt2c::CStringView nameSuffix) :
     CondTrigger {type, condId, nameSuffix},
     _mFunc {std::move(func)}
 {
@@ -34,11 +34,11 @@ SimpleCondTrigger::SimpleCondTrigger(std::function<void()> func, const Type type
 
 namespace {
 
-void listCondTriggers(const CondTriggers condTriggers) noexcept
+void listCondTriggers(const CondTriggers& condTriggers) noexcept
 {
     auto condTriggerArray = nlohmann::json::array();
 
-    for (const auto condTrigger : condTriggers) {
+    for (const auto& condTrigger : condTriggers) {
         condTriggerArray.push_back(nlohmann::json {
             {"cond-id", condTrigger->condId()},
             {"name", condTrigger->name()},
@@ -50,14 +50,22 @@ void listCondTriggers(const CondTriggers condTriggers) noexcept
 
 } /* namespace */
 
-void condMain(const int argc, const char ** const argv, const CondTriggers condTriggers) noexcept
+void condMain(const bt2s::span<const char * const> argv, const CondTriggers& condTriggers) noexcept
 {
-    BT_ASSERT(argc >= 2);
+    BT_ASSERT(argv.size() >= 2);
 
     if (strcmp(argv[1], "list") == 0) {
         listCondTriggers(condTriggers);
     } else if (strcmp(argv[1], "run") == 0) {
-        BT_ASSERT(argc >= 3);
+        /*
+         * It's expected that calling `*condTriggers[index]` below
+         * aborts (calls bt_common_abort()). In this testing context, we
+         * don't want any custom abortion command to run.
+         */
+        g_unsetenv("BABELTRACE_EXEC_ON_ABORT");
+
+        /* Call the trigger */
+        BT_ASSERT(argv.size() >= 3);
 
         const auto index = atoi(argv[2]);
 
This page took 0.027931 seconds and 4 git commands to generate.