Allow tests to fake stdin/stdout/stderr is a console

We've been unable to effectively test cases where stdin/stdout/stderr
are consoles, because in our test cases they generally aren't. Allow the
command line flags `--fake-std{in,out,err}-is-console` to tell the CLI
to pretend that std{in,out,err} is a console.
This commit is contained in:
Nick Terrell
2022-12-14 15:44:09 -08:00
committed by Nick Terrell
parent 031de3c69c
commit e58a39f84e
5 changed files with 55 additions and 6 deletions
+28
View File
@@ -288,6 +288,34 @@ int UTIL_isLink(const char* infilename)
return 0;
}
static int g_fakeStdinIsConsole = 0;
static int g_fakeStderrIsConsole = 0;
static int g_fakeStdoutIsConsole = 0;
int UTIL_isConsole(FILE* file)
{
if (file == stdin && g_fakeStdinIsConsole)
return 1;
if (file == stderr && g_fakeStderrIsConsole)
return 1;
if (file == stdout && g_fakeStdoutIsConsole)
return 1;
return IS_CONSOLE(file);
}
void UTIL_fakeStdinIsConsole(void)
{
g_fakeStdinIsConsole = 1;
}
void UTIL_fakeStdoutIsConsole(void)
{
g_fakeStdoutIsConsole = 1;
}
void UTIL_fakeStderrIsConsole(void)
{
g_fakeStderrIsConsole = 1;
}
U64 UTIL_getFileSize(const char* infilename)
{
stat_t statbuf;