check-namespace: don't require comment after #else (#6513)

This commit is contained in:
Alex
2022-09-19 17:45:44 +02:00
committed by GitHub
parent 5bfd7fba4e
commit e407e73e24
2 changed files with 14 additions and 1 deletions

View File

@@ -164,8 +164,10 @@ for cur_file in files:
if not expectations:
error(cur_file, m, f'Unexpected {statement}')
break
# Don't pop the expectation for an #else tag, we are still waiting for the #endif
if statement.startswith('#el') and expectations[-1].statement == '#endif':
# After an #else or #elif the comment is no longer mandatory, since it's hard to define
expectations[-1] = Expectation(IF_MACRO, '#endif', '')
# Don't pop the expectations, we are still waiting for the #endif
continue
exp = expectations.pop()
name = m.group('macro_name') or m.group('namespace_end') or ''

View File

@@ -232,6 +232,17 @@ with tempfile.TemporaryDirectory() as tmpdir:
} // namespace smml
#endif // ABC_H
''')
create_file('09_NoEndifAfterElseIsOk.cpp', '''
#ifdef XYZ
namespace lmms {
\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
}
#else
namespace lmms {
\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
}
#endif
''')
test.run()
test.expect('8 errors')
test.expect('''