mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-25 23:16:14 +01:00
glib-mkenums: don't support @filename@/@basename@ in fhead/ftail
As discussed in https://gitlab.gnome.org/GNOME/glib/merge_requests/135#note_253986 it doesn't really make sense to support these outside the templates for any particular header file. Leave them unsubstituted, with a warning.
This commit is contained in:
parent
cbd335c8c9
commit
7928fee2a8
@ -415,12 +415,17 @@ def replace_specials(prod):
|
|||||||
prod = prod.rstrip()
|
prod = prod.rstrip()
|
||||||
return prod
|
return prod
|
||||||
|
|
||||||
|
|
||||||
|
def warn_if_filename_basename_used(section, prod):
|
||||||
|
for substitution in ('\u0040filename\u0040',
|
||||||
|
'\u0040basename\u0040'):
|
||||||
|
if substitution in prod:
|
||||||
|
print_warning('{} used in {} section.'.format(substitution,
|
||||||
|
section))
|
||||||
|
|
||||||
if len(fhead) > 0:
|
if len(fhead) > 0:
|
||||||
prod = fhead
|
prod = fhead
|
||||||
base = os.path.basename(options.args[0])
|
warn_if_filename_basename_used('file-header', prod)
|
||||||
|
|
||||||
prod = prod.replace('\u0040filename\u0040', options.args[0])
|
|
||||||
prod = prod.replace('\u0040basename\u0040', base)
|
|
||||||
prod = replace_specials(prod)
|
prod = replace_specials(prod)
|
||||||
write_output(prod)
|
write_output(prod)
|
||||||
|
|
||||||
@ -712,10 +717,7 @@ for fname in sorted(options.args):
|
|||||||
|
|
||||||
if len(ftail) > 0:
|
if len(ftail) > 0:
|
||||||
prod = ftail
|
prod = ftail
|
||||||
base = os.path.basename(options.args[-1]) # FIXME, wrong
|
warn_if_filename_basename_used('file-tail', prod)
|
||||||
|
|
||||||
prod = prod.replace('\u0040filename\u0040', 'ARGV') # wrong too
|
|
||||||
prod = prod.replace('\u0040basename\u0040', base)
|
|
||||||
prod = replace_specials(prod)
|
prod = replace_specials(prod)
|
||||||
write_output(prod)
|
write_output(prod)
|
||||||
|
|
||||||
|
@ -24,6 +24,7 @@ import collections
|
|||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
import tempfile
|
import tempfile
|
||||||
|
import textwrap
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import taptestrunner
|
import taptestrunner
|
||||||
@ -108,8 +109,6 @@ class TestMkenums(unittest.TestCase):
|
|||||||
template_contents = '''
|
template_contents = '''
|
||||||
/*** BEGIN file-header ***/
|
/*** BEGIN file-header ***/
|
||||||
file-header
|
file-header
|
||||||
filename: @filename@
|
|
||||||
basename: @basename@
|
|
||||||
/*** END file-header ***/
|
/*** END file-header ***/
|
||||||
|
|
||||||
/*** BEGIN file-production ***/
|
/*** BEGIN file-production ***/
|
||||||
@ -171,8 +170,6 @@ comment: @comment@
|
|||||||
|
|
||||||
/*** BEGIN file-tail ***/
|
/*** BEGIN file-tail ***/
|
||||||
file-tail
|
file-tail
|
||||||
filename: @filename@
|
|
||||||
basename: @basename@
|
|
||||||
/*** END file-tail ***/
|
/*** END file-tail ***/
|
||||||
'''
|
'''
|
||||||
return self.runMkenumsWithTemplate(template_contents, *args)
|
return self.runMkenumsWithTemplate(template_contents, *args)
|
||||||
@ -222,8 +219,6 @@ comment: {standard_top_comment}
|
|||||||
|
|
||||||
|
|
||||||
file-header
|
file-header
|
||||||
filename: {filename}
|
|
||||||
basename: {basename}
|
|
||||||
file-production
|
file-production
|
||||||
filename: {filename}
|
filename: {filename}
|
||||||
basename: {basename}
|
basename: {basename}
|
||||||
@ -262,8 +257,6 @@ type: {type_lower}
|
|||||||
Type: {type_camel}
|
Type: {type_camel}
|
||||||
TYPE: {type_upper}
|
TYPE: {type_upper}
|
||||||
file-tail
|
file-tail
|
||||||
filename: ARGV
|
|
||||||
basename: {basename}
|
|
||||||
|
|
||||||
comment
|
comment
|
||||||
comment: {standard_bottom_comment}
|
comment: {standard_bottom_comment}
|
||||||
@ -274,6 +267,42 @@ comment: {standard_bottom_comment}
|
|||||||
result = self.runMkenums('--help')
|
result = self.runMkenums('--help')
|
||||||
self.assertIn('usage: glib-mkenums', result.out)
|
self.assertIn('usage: glib-mkenums', result.out)
|
||||||
|
|
||||||
|
def test_no_args(self):
|
||||||
|
"""Test running with no arguments at all."""
|
||||||
|
result = self.runMkenums()
|
||||||
|
self.assertEqual('', result.err)
|
||||||
|
self.assertEquals('''/* {standard_top_comment} */
|
||||||
|
|
||||||
|
|
||||||
|
/* {standard_bottom_comment} */'''.format(**result.subs),
|
||||||
|
result.out.strip())
|
||||||
|
|
||||||
|
def test_empty_template(self):
|
||||||
|
"""Test running with an empty template and no header files."""
|
||||||
|
result = self.runMkenumsWithTemplate('')
|
||||||
|
self.assertEqual('', result.err)
|
||||||
|
self.assertEquals('''/* {standard_top_comment} */
|
||||||
|
|
||||||
|
|
||||||
|
/* {standard_bottom_comment} */'''.format(**result.subs),
|
||||||
|
result.out.strip())
|
||||||
|
|
||||||
|
def test_no_headers(self):
|
||||||
|
"""Test running with a complete template, but no header files."""
|
||||||
|
result = self.runMkenumsWithAllSubstitutions()
|
||||||
|
self.assertEqual('', result.err)
|
||||||
|
self.assertEquals('''
|
||||||
|
comment
|
||||||
|
comment: {standard_top_comment}
|
||||||
|
|
||||||
|
|
||||||
|
file-header
|
||||||
|
file-tail
|
||||||
|
|
||||||
|
comment
|
||||||
|
comment: {standard_bottom_comment}
|
||||||
|
'''.format(**result.subs).strip(), result.out)
|
||||||
|
|
||||||
def test_empty_header(self):
|
def test_empty_header(self):
|
||||||
"""Test an empty header."""
|
"""Test an empty header."""
|
||||||
result = self.runMkenumsWithHeader('')
|
result = self.runMkenumsWithHeader('')
|
||||||
@ -284,11 +313,7 @@ comment: {standard_top_comment}
|
|||||||
|
|
||||||
|
|
||||||
file-header
|
file-header
|
||||||
filename: {filename}
|
|
||||||
basename: {basename}
|
|
||||||
file-tail
|
file-tail
|
||||||
filename: ARGV
|
|
||||||
basename: {basename}
|
|
||||||
|
|
||||||
comment
|
comment
|
||||||
comment: {standard_bottom_comment}
|
comment: {standard_bottom_comment}
|
||||||
@ -378,6 +403,50 @@ comment: {standard_bottom_comment}
|
|||||||
'SAMPLER_TYPE', 'GEGL', 'enum', 'Enum',
|
'SAMPLER_TYPE', 'GEGL', 'enum', 'Enum',
|
||||||
'ENUM', 'GEGL_SAMPLER_NEAREST', 'nearest', '0')
|
'ENUM', 'GEGL_SAMPLER_NEAREST', 'nearest', '0')
|
||||||
|
|
||||||
|
def test_filename_basename_in_fhead_ftail(self):
|
||||||
|
template_contents = '''
|
||||||
|
/*** BEGIN file-header ***/
|
||||||
|
file-header
|
||||||
|
filename: @filename@
|
||||||
|
basename: @basename@
|
||||||
|
/*** END file-header ***/
|
||||||
|
|
||||||
|
/*** BEGIN comment ***/
|
||||||
|
comment
|
||||||
|
comment: @comment@
|
||||||
|
/*** END comment ***/
|
||||||
|
|
||||||
|
/*** BEGIN file-tail ***/
|
||||||
|
file-tail
|
||||||
|
filename: @filename@
|
||||||
|
basename: @basename@
|
||||||
|
/*** END file-tail ***/'''
|
||||||
|
result = self.runMkenumsWithTemplate(template_contents)
|
||||||
|
self.assertEqual(
|
||||||
|
textwrap.dedent(
|
||||||
|
'''
|
||||||
|
WARNING: @filename@ used in file-header section.
|
||||||
|
WARNING: @basename@ used in file-header section.
|
||||||
|
WARNING: @filename@ used in file-tail section.
|
||||||
|
WARNING: @basename@ used in file-tail section.
|
||||||
|
''').strip(),
|
||||||
|
result.err)
|
||||||
|
self.assertEqual('''
|
||||||
|
comment
|
||||||
|
comment: {standard_top_comment}
|
||||||
|
|
||||||
|
|
||||||
|
file-header
|
||||||
|
filename: @filename@
|
||||||
|
basename: @basename@
|
||||||
|
file-tail
|
||||||
|
filename: @filename@
|
||||||
|
basename: @basename@
|
||||||
|
|
||||||
|
comment
|
||||||
|
comment: {standard_bottom_comment}
|
||||||
|
'''.format(**result.subs).strip(), result.out)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main(testRunner=taptestrunner.TAPTestRunner())
|
unittest.main(testRunner=taptestrunner.TAPTestRunner())
|
||||||
|
Loading…
Reference in New Issue
Block a user