Skip to content

gjs-test-utils: Be more liberal in comparing values of different types

Marco Trevisan requested to merge 3v1n0/gjs:assert-equal-comparable-types into master

Fixes compilation issues in some archs as per !615 (comment 1113160)

We can safely compare integers of different sizes, assuming they're both signed (or unsigned). So assert this instead of requiring two arguments of the very same type.


For some reason cpplint isn't smart enough to allow us grouping the checks such as

template <typename T1, typename T2>
constexpr bool comparable_types() {
    if constexpr (std::is_same<T1, T2>()) {
        return true;
    } else if constexpr (std::is_arithmetic_v<T1> ==std::is_arithmetic_v<T2> ||
                         std::is_enum_v<T1>() == std::is_enum_v<T2>()) {
        return std::is_signed_v<T1> == std::is_signed_v<T2>;
    } else {
        return false;
    }
}

As the above fails with test/gjs-test-utils.h:53: If an else has a brace on one side, it should have it on both [readability/braces] [5] :o

Merge request reports