cli icon indicating copy to clipboard operation
cli copied to clipboard

Output colorized logs from pg_prove

Open lauri865 opened this issue 1 year ago • 2 comments

Is your feature request related to a problem? Please describe. Small quality of life feature request – would be great to have pg_prove logs passed through with colors (should be the default behavior of pg_prove). Otherwise with many tests, it's a bit difficult to follow the structure.

Describe the solution you'd like Colorised logs.

Describe alternatives you've considered N/A

Additional context Platform test: Mac OS latest CLI

lauri865 avatar Feb 06 '24 14:02 lauri865

@sweatybridge, any chance this could be fixed? Just adding -t option to docker run would fix this – I'd be fine if it was even an optional flag, but don't want to inherit another very long package script ideally for such a simple thing. Screenshot 2024-10-14 at 22 29 14

lauri865 avatar Oct 14 '24 20:10 lauri865

Current behavior – takes way too much time to read and locate failing tests (and even worse when multiple tests are failing and there's more plans that are failing): Screenshot 2024-10-14 at 22 31 36

lauri865 avatar Oct 14 '24 20:10 lauri865

Yes please!!!

jumski avatar Oct 29 '24 09:10 jumski

@lauri865 as a temporary workaround i managed to create an awk script to colorise the output, the results look much better:

Image

Use the script like this:

supabase db test 2>&1 | awk -f colorize-pgtap-output.awk

[!WARNING] The "2>&1" bit is important as pg_prove is writing on stderr!

The script:

BEGIN {
    # ANSI color codes
    RED="\033[31m";
    GREEN="\033[32m";
    YELLOW="\033[33m";
    GRAY="\033[90m";
    BOLD="\033[1m";
    RESET="\033[0m";
}

/Dubious|Failed|error|exit 1|Result: FAIL/ {
    print RED $0 RESET;
    next;
}

# Match any line containing ERROR: (PostgreSQL error messages)
/ERROR:/ {
    print RED $0 RESET;
    next;
}

# Match DETAIL: and CONTEXT: lines that are part of PostgreSQL error messages
/DETAIL:|CONTEXT:/ {
    print RED $0 RESET;
    next;
}

/ok$/ {
    print GREEN $0 RESET;
    next;
}

/\.\.\.+/ {
    test = $1;
    result = $NF;
    if (result == "ok") {
        printf "%s %s %s\n", test, GRAY RESET, GREEN result RESET;
    } else {
        printf "%s %s %s\n", RED test RESET, GRAY RESET, RED result RESET;
    }
    next;
}

/Test Summary Report|-------------------/ {
    print YELLOW BOLD $0 RESET;
    next;
}

/\(Wstat:.*/ {
    sub(/^[[:space:]]+/, "");
    filename = $1;
    print YELLOW "  " RED filename RESET YELLOW $2 $3 $4 $5 $6 RESET;
    next;
}

/^Files=|^Result:/ {
    if ($0 ~ /FAIL/) {
        print RED BOLD $0 RESET;
    } else {
        print YELLOW $0 RESET;
    }
    next;
}

/Try rerunning/ {
    print YELLOW $0 RESET;
    next;
}

{
    print;
}

jumski avatar Mar 12 '25 12:03 jumski