From 614372aa556a08da2ffacce271dc7ba094ef58a9 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Thu, 12 Dec 2019 13:31:04 -0800 Subject: mlog: Add a log_once function There are a number of cases where we end up spamming users with the same message over and over again, which is really annoying. This solves that. --- run_unittests.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'run_unittests.py') diff --git a/run_unittests.py b/run_unittests.py index 703673f..977a4f8 100755 --- a/run_unittests.py +++ b/run_unittests.py @@ -1141,6 +1141,35 @@ class InternalTests(unittest.TestCase): deps = d.get_all_dependencies(target) self.assertEqual(deps, expdeps) + def test_log_once(self): + f = io.StringIO() + with mock.patch('mesonbuild.mlog.log_file', f), \ + mock.patch('mesonbuild.mlog._logged_once', set()): + mesonbuild.mlog.log_once('foo') + mesonbuild.mlog.log_once('foo') + actual = f.getvalue().strip() + self.assertEqual(actual, 'foo', actual) + + def test_log_once_ansi(self): + f = io.StringIO() + with mock.patch('mesonbuild.mlog.log_file', f), \ + mock.patch('mesonbuild.mlog._logged_once', set()): + mesonbuild.mlog.log_once(mesonbuild.mlog.bold('foo')) + mesonbuild.mlog.log_once(mesonbuild.mlog.bold('foo')) + actual = f.getvalue().strip() + self.assertEqual(actual.count('foo'), 1, actual) + + mesonbuild.mlog.log_once('foo') + actual = f.getvalue().strip() + self.assertEqual(actual.count('foo'), 1, actual) + + f.truncate() + + mesonbuild.mlog.warning('bar', once=True) + mesonbuild.mlog.warning('bar', once=True) + actual = f.getvalue().strip() + self.assertEqual(actual.count('bar'), 1, actual) + @unittest.skipIf(is_tarball(), 'Skipping because this is a tarball release') class DataTests(unittest.TestCase): -- cgit v1.1