descriptions: fix bad json output (#11350)
--------- Co-authored-by: Mihai Fufezan <mihai@fufexan.net>
This commit is contained in:
parent
0c317f2508
commit
ec26b753a2
4 changed files with 42 additions and 6 deletions
35
hyprtester/src/tests/main/hyprctl.cpp
Normal file
35
hyprtester/src/tests/main/hyprctl.cpp
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
#include "tests.hpp"
|
||||||
|
#include "../../shared.hpp"
|
||||||
|
#include "../../hyprctlCompat.hpp"
|
||||||
|
#include <print>
|
||||||
|
#include <thread>
|
||||||
|
#include <chrono>
|
||||||
|
#include <hyprutils/os/Process.hpp>
|
||||||
|
#include <hyprutils/memory/WeakPtr.hpp>
|
||||||
|
#include <csignal>
|
||||||
|
#include <cerrno>
|
||||||
|
#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);
|
||||||
|
|
@ -10,6 +10,7 @@ in {
|
||||||
flake.hyprtester
|
flake.hyprtester
|
||||||
|
|
||||||
# Programs needed for tests
|
# Programs needed for tests
|
||||||
|
jq
|
||||||
kitty
|
kitty
|
||||||
xorg.xeyes
|
xorg.xeyes
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -3210,8 +3210,8 @@ std::string SConfigOptionDescription::jsonify() const {
|
||||||
"explicit": {})#",
|
"explicit": {})#",
|
||||||
val.value, val.min, val.max, currentValue, EXPLICIT);
|
val.value, val.min, val.max, currentValue, EXPLICIT);
|
||||||
} else if constexpr (std::is_same_v<T, SColorData>) {
|
} else if constexpr (std::is_same_v<T, SColorData>) {
|
||||||
return std::format(R"#( "value": {},
|
return std::format(R"#( "value": "{}",
|
||||||
"current": {},
|
"current": "{}",
|
||||||
"explicit": {})#",
|
"explicit": {})#",
|
||||||
val.color.getAsHex(), currentValue, EXPLICIT);
|
val.color.getAsHex(), currentValue, EXPLICIT);
|
||||||
} else if constexpr (std::is_same_v<T, SBoolData>) {
|
} else if constexpr (std::is_same_v<T, SBoolData>) {
|
||||||
|
|
@ -3220,7 +3220,7 @@ std::string SConfigOptionDescription::jsonify() const {
|
||||||
"explicit": {})#",
|
"explicit": {})#",
|
||||||
val.value, currentValue, EXPLICIT);
|
val.value, currentValue, EXPLICIT);
|
||||||
} else if constexpr (std::is_same_v<T, SChoiceData>) {
|
} else if constexpr (std::is_same_v<T, SChoiceData>) {
|
||||||
return std::format(R"#( "value": {},
|
return std::format(R"#( "value": "{}",
|
||||||
"firstIndex": {},
|
"firstIndex": {},
|
||||||
"current": {},
|
"current": {},
|
||||||
"explicit": {})#",
|
"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;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1697,7 +1697,7 @@ static std::string getIsLocked(eHyprCtlOutputFormat format, std::string request)
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::string getDescriptions(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();
|
const auto& DESCS = g_pConfigManager->getAllDescriptions();
|
||||||
|
|
||||||
for (const auto& d : DESCS) {
|
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.pop_back();
|
json.pop_back();
|
||||||
|
|
||||||
json += "}\n";
|
json += "]\n";
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue