From 72450e72e400eb03325ca182f0e118fde8cd1705 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 26 Jul 2017 13:44:24 +0200 Subject: Add support for printing progress --- tests/progress/buildfile | 7 ++++++ tests/progress/driver.cxx | 62 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 tests/progress/buildfile create mode 100644 tests/progress/driver.cxx (limited to 'tests/progress') diff --git a/tests/progress/buildfile b/tests/progress/buildfile new file mode 100644 index 0000000..19e85c0 --- /dev/null +++ b/tests/progress/buildfile @@ -0,0 +1,7 @@ +# file : tests/progress/buildfile +# copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +import libs = libbutl%lib{butl} + +exe{driver}: {hxx cxx}{*} $libs diff --git a/tests/progress/driver.cxx b/tests/progress/driver.cxx new file mode 100644 index 0000000..702319a --- /dev/null +++ b/tests/progress/driver.cxx @@ -0,0 +1,62 @@ +// file : tests/progress/driver.cxx -*- C++ -*- +// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#ifndef _WIN32 +# include // this_thread::sleep_for() +#else +# include +#endif + +#include // size_t +#include + +#include + +using namespace std; +using namespace butl; + +int +main () +{ + auto sleep = [] (size_t ms = 100) + { + // MINGW GCC 4.9 doesn't implement this_thread so use Win32 Sleep(). + // +#ifndef _WIN32 + this_thread::sleep_for (chrono::milliseconds (ms)); +#else + Sleep (static_cast (ms)); +#endif + }; + + for (size_t i (100); i != 0; --i) + { + if (i % 10 == 0) + diag_stream_lock () << "Line " << i / 10 << endl; + + { + diag_progress_lock l; + diag_progress = " " + to_string (i) + "%"; + } + + sleep (); + } + + sleep (1000); + + // Test that the progress line is restored by the diag_stream_lock. + // + diag_stream_lock () << "Printed to diag_stream" << endl; + + sleep (1000); + + // Test that the progress line is restored after printing to cerr. + // + { + cerr << "Printed to std::cerr" << endl; + diag_progress_lock (); + } + + sleep (1000); +} -- cgit v1.1