On 5/15/20 12:58 PM, David Malcolm wrote:
On Fri, 2020-05-15 at 10:59 +0200, Martin Liška wrote:
Hi.
Since we moved to git world and we're in the preparation for
ChangeLog messages
being in git commit messages, I think it's the right time to also
simplify mklog
script.
I'm sending a new version (which should eventually replace
contrib/mklog and contrib/mklog.pl).
Changes made in the version:
- the script uses unifdiff - it rapidly simplifies parsing of the '+-
!' lines that is done
in contrib/mklog
- no author nor date stamp is used - that all can be get from git
- --inline option is not supported - I don't see a use-case for it
now
- the new script has a unit tests (just few of them for now)
I compares results in between the old Python script for last 80
commits and it's very close,
in some cases it does even better.
I'm planning to maintain and improve the script for the future.
Thoughts?
Martin
+class TestMklog(unittest.TestCase):
+ def test_macro_definition(self):
+ changelog = generate_changelog(PATCH1)
+ assert changelog == EXPECTED1
+
+ def test_changed_argument(self):
+ changelog = generate_changelog(PATCH2)
+ assert changelog == EXPECTED2
+
+ def test_enum_and_struct(self):
+ changelog = generate_changelog(PATCH3)
+ assert changelog == EXPECTED3
+
+ def test_no_function(self):
+ changelog = generate_changelog(PATCH3, True)
+ assert changelog == EXPECTED3B
Thank you David for review.
However I see the same output for both operator== and assertEqual. Probably
because of usage of pytest version 4?
assertEqual:
$ pytest contrib/test_mklog_ng.py
Test session starts (platform: linux, Python 3.8.2, pytest 4.6.9, pytest-sugar
0.9.3)
benchmark: 3.2.3 (defaults: timer=time.perf_counter disable_gc=False
min_rounds=5 min_time=0.000005 max_time=1.0 calibration_precision=10
warmup=False warmup_iterations=100000)
rootdir: /home/marxin/Programming/gcc
plugins: xdist-1.32.0, sugar-0.9.3, forked-1.1.3, benchmark-3.2.3,
aspectlib-1.5.0, cov-2.8.1, flake8-1.0.5
collecting ...
contrib/test_mklog_ng.py ✓
25% ██▌
――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――
TestMklog.test_enum_and_struct
――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――
self = <test_mklog_ng.TestMklog testMethod=test_enum_and_struct>
def test_enum_and_struct(self):
changelog = generate_changelog(PATCH3)
self.assertEqual(changelog, EXPECTED3)
E AssertionError: 'libc[23 chars]clude/cpplib.h (enum c_lang):\n\t(struct
cpp_options):\n\n' != 'libc[23 chars]clude/cppli22b.h (enum c_lang):\n\t(struct
cpp_optio44ns):\n\n'
E libcpp/ChangeLog:
E
E - * include/cpplib.h (enum c_lang):
E + * include/cppli22b.h (enum c_lang):
E ? ++
E - (struct cpp_options):
E + (struct cpp_optio44ns):
E ? ++
contrib/test_mklog_ng.py:154: AssertionError
operator==:
pytest contrib/test_mklog_ng.py
Test session starts (platform: linux, Python 3.8.2, pytest 4.6.9, pytest-sugar
0.9.3)
benchmark: 3.2.3 (defaults: timer=time.perf_counter disable_gc=False
min_rounds=5 min_time=0.000005 max_time=1.0 calibration_precision=10
warmup=False warmup_iterations=100000)
rootdir: /home/marxin/Programming/gcc
plugins: xdist-1.32.0, sugar-0.9.3, forked-1.1.3, benchmark-3.2.3,
aspectlib-1.5.0, cov-2.8.1, flake8-1.0.5
collecting ...
contrib/test_mklog_ng.py ✓
25% ██▌
――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――
TestMklog.test_enum_and_struct
――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――
self = <test_mklog_ng.TestMklog testMethod=test_enum_and_struct>
def test_enum_and_struct(self):
changelog = generate_changelog(PATCH3)
assert changelog == EXPECTED3
E AssertionError: assert 'libcpp/Chang...options):\n\n' ==
'libcpp/Change...tio44ns):\n\n'
E libcpp/ChangeLog:
E
E - * include/cpplib.h (enum c_lang):
E + * include/cppli22b.h (enum c_lang):
E ? ++
E - (struct cpp_options):
E + (struct cpp_optio44ns):...
E
E ...Full output truncated (3 lines hidden), use '-vv' to show
Martin
Use self.assertEqual(a, b) rather than assert a == b, so that if it
fails you get a multiline diff:
e.g.:
import unittest
class TestMklog(unittest.TestCase):
def test_macro_definition(self):
self.assertEqual('''
first
second
third''', '''
first
SECOND
third''')
unittest.main()
has this output:
F
======================================================================
FAIL: test_macro_definition (__main__.TestMklog)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/foo.py", line 11, in test_macro_definition
third''')
AssertionError: '\nfirst\nsecond\nthird' != '\nfirst\nSECOND\nthird'
first
- second
+ SECOND
third
----------------------------------------------------------------------
Ran 1 test in 0.000s
FAILED (failures=1)
which is much easier to debug than the output from assert a == b, which
is just:
F
======================================================================
FAIL: test_macro_definition (__main__.TestMklog)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/foo.py", line 11, in test_macro_definition
third''')
AssertionError
----------------------------------------------------------------------
Ran 1 test in 0.000s
FAILED (failures=1)