Skip to content

Commit

Permalink
Add Console::hasText() so tests can check if there are errors in the …
Browse files Browse the repository at this point in the history
…console

This is useful in case that we want to test (e.g.) save/load document
operations that print errors in the console. So checking the console
output (this hasText flag) we can determine if the operation was
completely successful or failed.
  • Loading branch information
dacap committed May 24, 2017
1 parent 6f09a82 commit b4ea90a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
16 changes: 14 additions & 2 deletions src/app/console.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2001-2016 David Capello
// Copyright (C) 2001-2017 David Capello
//
// This program is distributed under the terms of
// the End-User License Agreement for Aseprite.
Expand Down Expand Up @@ -34,6 +34,7 @@ static Widget* wid_cancel = NULL;
static int console_counter = 0;
static bool console_locked;
static bool want_close_flag = false;
static bool has_text = false;

Console::Console(Context* ctx)
: m_withUI(false)
Expand All @@ -42,13 +43,17 @@ Console::Console(Context* ctx)
m_withUI = (ctx->isUIAvailable());
else
m_withUI =
(App::instance()->isGui() &&
(App::instance() &&
App::instance()->isGui() &&
Manager::getDefault() &&
Manager::getDefault()->getDisplay());

if (!m_withUI)
return;

if (console_counter == 0)
has_text = false;

console_counter++;
if (wid_console || console_counter > 1)
return;
Expand Down Expand Up @@ -104,8 +109,15 @@ Console::~Console()
}
}

bool Console::hasText() const
{
return has_text;
}

void Console::printf(const char* format, ...)
{
has_text = true;

std::va_list ap;
va_start(ap, format);
std::string msg = base::string_vprintf(format, ap);
Expand Down
4 changes: 3 additions & 1 deletion src/app/console.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2001-2015 David Capello
// Copyright (C) 2001-2017 David Capello
//
// This program is distributed under the terms of
// the End-User License Agreement for Aseprite.
Expand All @@ -18,6 +18,8 @@ namespace app {
Console(Context* ctx = nullptr);
~Console();

bool hasText() const;

void printf(const char *format, ...);

static void showException(const std::exception& e);
Expand Down

0 comments on commit b4ea90a

Please sign in to comment.