libtest: Only colorize output if stdout is a tty

Fixes #14570.