diff --git a/hyprtester/src/tests/main/hyprctl.cpp b/hyprtester/src/tests/main/hyprctl.cpp new file mode 100644 index 000000000..c16b0d979 --- /dev/null +++ b/hyprtester/src/tests/main/hyprctl.cpp @@ -0,0 +1,35 @@ +#include "tests.hpp" +#include "../../shared.hpp" +#include "../../hyprctlCompat.hpp" +#include +#include +#include +#include +#include +#include +#include +#include "../shared.hpp" + +static int ret = 0; + +using namespace Hyprutils::OS; +using namespace Hyprutils::Memory; + +#define UP CUniquePointer +#define SP CSharedPointer + +static bool test() { + NLog::log("{}Testing hyprctl", Colors::GREEN); + + { + NLog::log("{}Testing hyprctl descriptions for any json errors", Colors::GREEN); + CProcess jqProc("bash", {"-c", "hyprctl descriptions | jq"}); + jqProc.addEnv("HYPRLAND_INSTANCE_SIGNATURE", HIS); + jqProc.runSync(); + EXPECT(jqProc.exitCode(), 0); + } + + return !ret; +} + +REGISTER_TEST_FN(test); diff --git a/nix/tests/default.nix b/nix/tests/default.nix index 4d71aec46..5c5f8157a 100644 --- a/nix/tests/default.nix +++ b/nix/tests/default.nix @@ -10,6 +10,7 @@ in { flake.hyprtester # Programs needed for tests + jq kitty xorg.xeyes ]; diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 337682dce..48c1d1036 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -3210,8 +3210,8 @@ std::string SConfigOptionDescription::jsonify() const { "explicit": {})#", val.value, val.min, val.max, currentValue, EXPLICIT); } else if constexpr (std::is_same_v) { - return std::format(R"#( "value": {}, - "current": {}, + return std::format(R"#( "value": "{}", + "current": "{}", "explicit": {})#", val.color.getAsHex(), currentValue, EXPLICIT); } else if constexpr (std::is_same_v) { @@ -3220,7 +3220,7 @@ std::string SConfigOptionDescription::jsonify() const { "explicit": {})#", val.value, currentValue, EXPLICIT); } else if constexpr (std::is_same_v) { - return std::format(R"#( "value": {}, + return std::format(R"#( "value": "{}", "firstIndex": {}, "current": {}, "explicit": {})#", @@ -3257,7 +3257,7 @@ std::string SConfigOptionDescription::jsonify() const { {} }} }})#", - value, description, (uint16_t)type, (uint32_t)flags, parseData()); + value, escapeJSONStrings(description), (uint16_t)type, (uint32_t)flags, parseData()); return json; } diff --git a/src/debug/HyprCtl.cpp b/src/debug/HyprCtl.cpp index cec410873..3b83d3230 100644 --- a/src/debug/HyprCtl.cpp +++ b/src/debug/HyprCtl.cpp @@ -1697,7 +1697,7 @@ static std::string getIsLocked(eHyprCtlOutputFormat format, std::string request) } static std::string getDescriptions(eHyprCtlOutputFormat format, std::string request) { - std::string json = "{"; + std::string json = "["; const auto& DESCS = g_pConfigManager->getAllDescriptions(); for (const auto& d : DESCS) { @@ -1707,7 +1707,7 @@ static std::string getDescriptions(eHyprCtlOutputFormat format, std::string requ json.pop_back(); json.pop_back(); - json += "}\n"; + json += "]\n"; return json; }