diff options
author | Dylan Baker <dylan@pnwbakers.com> | 2019-12-12 13:31:04 -0800 |
---|---|---|
committer | Xavier Claessens <xclaesse@gmail.com> | 2019-12-13 09:57:05 -0500 |
commit | 614372aa556a08da2ffacce271dc7ba094ef58a9 (patch) | |
tree | 6d159659f70c0deafd6b85ea304459c3de79d6ac /run_unittests.py | |
parent | eb30c493f609ebdad5a41ad26fcf9845258729e1 (diff) | |
download | meson-614372aa556a08da2ffacce271dc7ba094ef58a9.zip meson-614372aa556a08da2ffacce271dc7ba094ef58a9.tar.gz meson-614372aa556a08da2ffacce271dc7ba094ef58a9.tar.bz2 |
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.
Diffstat (limited to 'run_unittests.py')
-rwxr-xr-x | run_unittests.py | 29 |
1 files changed, 29 insertions, 0 deletions
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): |