summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWill Thompson <will@willthompson.co.uk>2018-08-10 16:53:23 +0100
committerWill Thompson <will@willthompson.co.uk>2018-08-10 17:05:59 +0100
commit7928fee2a84fc9b73dca68a7b9003640223b15f7 (patch)
tree979b9e752056957f97a08c861a4738316bd79e73
parentcbd335c8c998ce3a30348e2dafcc12022ee3b33f (diff)
downloadglib-7928fee2a84fc9b73dca68a7b9003640223b15f7.tar.gz
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.
-rwxr-xr-xgobject/glib-mkenums.in18
-rw-r--r--gobject/tests/mkenums.py93
2 files changed, 91 insertions, 20 deletions
diff --git a/gobject/glib-mkenums.in b/gobject/glib-mkenums.in
index de05232ce..0388fb86d 100755
--- a/gobject/glib-mkenums.in
+++ b/gobject/glib-mkenums.in
@@ -415,12 +415,17 @@ def replace_specials(prod):
prod = prod.rstrip()
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:
prod = fhead
- base = os.path.basename(options.args[0])
-
- prod = prod.replace('\u0040filename\u0040', options.args[0])
- prod = prod.replace('\u0040basename\u0040', base)
+ warn_if_filename_basename_used('file-header', prod)
prod = replace_specials(prod)
write_output(prod)
@@ -712,10 +717,7 @@ for fname in sorted(options.args):
if len(ftail) > 0:
prod = ftail
- base = os.path.basename(options.args[-1]) # FIXME, wrong
-
- prod = prod.replace('\u0040filename\u0040', 'ARGV') # wrong too
- prod = prod.replace('\u0040basename\u0040', base)
+ warn_if_filename_basename_used('file-tail', prod)
prod = replace_specials(prod)
write_output(prod)
diff --git a/gobject/tests/mkenums.py b/gobject/tests/mkenums.py
index dbc06aa7e..bb5443394 100644
--- a/gobject/tests/mkenums.py
+++ b/gobject/tests/mkenums.py
@@ -24,6 +24,7 @@ import collections
import os
import subprocess
import tempfile
+import textwrap
import unittest
import taptestrunner
@@ -108,8 +109,6 @@ class TestMkenums(unittest.TestCase):
template_contents = '''
/*** BEGIN file-header ***/
file-header
-filename: @filename@
-basename: @basename@
/*** END file-header ***/
/*** BEGIN file-production ***/
@@ -171,8 +170,6 @@ comment: @comment@
/*** BEGIN file-tail ***/
file-tail
-filename: @filename@
-basename: @basename@
/*** END file-tail ***/
'''
return self.runMkenumsWithTemplate(template_contents, *args)
@@ -222,8 +219,6 @@ comment: {standard_top_comment}
file-header
-filename: {filename}
-basename: {basename}
file-production
filename: {filename}
basename: {basename}
@@ -262,8 +257,6 @@ type: {type_lower}
Type: {type_camel}
TYPE: {type_upper}
file-tail
-filename: ARGV
-basename: {basename}
comment
comment: {standard_bottom_comment}
@@ -274,6 +267,42 @@ comment: {standard_bottom_comment}
result = self.runMkenums('--help')
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):
"""Test an empty header."""
result = self.runMkenumsWithHeader('')
@@ -284,11 +313,7 @@ comment: {standard_top_comment}
file-header
-filename: {filename}
-basename: {basename}
file-tail
-filename: ARGV
-basename: {basename}
comment
comment: {standard_bottom_comment}
@@ -378,6 +403,50 @@ comment: {standard_bottom_comment}
'SAMPLER_TYPE', 'GEGL', 'enum', 'Enum',
'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__':
unittest.main(testRunner=taptestrunner.TAPTestRunner())