diff options
Diffstat (limited to 'test cases/format')
28 files changed, 914 insertions, 0 deletions
diff --git a/test cases/format/1 default/crazy_comments.meson b/test cases/format/1 default/crazy_comments.meson new file mode 100644 index 000000000..f391ca28c --- /dev/null +++ b/test cases/format/1 default/crazy_comments.meson @@ -0,0 +1,47 @@ +# SPDX-FileCopyrightText: Stone Tickle <lattis@mochiro.moe> +# SPDX-License-Identifier: GPL-3.0-only + +project('a') + +if ( + # comment + false # in a weird +) # place! # test +else +endif # test2 + +foreach a : ( + # test 7 + b # test 4 +) # test 6 # test 3 +endforeach +# test 5 + +a = [ + 1, + # inner + 2, # between comma + # between comma 2 +] # trailing + +( + # hello + a() +) +( + # comment 1 + # comment 2 + # comment 3 + a # comment 4 + # comment 5 + # comment 6 + = ( + # comment 7 + 1 # comment 8 + # comment 9 + + 2 # comment 10 + ) # comment 11 + # comment 12 +) # comment 13 + +# trailing comment diff --git a/test cases/format/1 default/indentation.meson b/test cases/format/1 default/indentation.meson new file mode 100644 index 000000000..31a809abf --- /dev/null +++ b/test cases/format/1 default/indentation.meson @@ -0,0 +1,73 @@ +project( + 'indentation', + default_options: { + 'buildtype': 'release', + 'default_library': 'shared', + 'prefer_static': false, + 'unity': 'off', + }, + meson_version: '>= 1.5.0', + version: '1.2.3', +) + +a = [ + 1, + 2, + 3, + [ + 4, + 5, + 6, + [ + 7, + 8, + 9, + [ + 10, # 10 + 11, # 11 + 12, # 12 + ], + 13, + 14, + 15, + ], + ], +] +d = {} + +if meson.project_version().version_compare('>1.2') + if meson.version().version_compare('>1.0') + foreach i : a + e = { + 'a': 'a', + 'b': 'b', + 'c': 'c', + 'd': [ + 1, + 2, + 3, + { + 'e': 'e', + 'f': 'f', + 'g': 'g', + 'h': { + 'i': ( + # a + 1 + # b + + + # c + 2 + ), + 'j': [ + 1, # 1 + 2, # 2 + 3, # 3 + ], + }, + }, + ], + } + endforeach + endif +endif diff --git a/test cases/format/1 default/meson.build b/test cases/format/1 default/meson.build new file mode 100644 index 000000000..5b5b1152a --- /dev/null +++ b/test cases/format/1 default/meson.build @@ -0,0 +1,14 @@ +# This file is for testing meson format with default options + +project('default format') + +meson_cmd = find_program('meson') +meson_files = { + 'self': files('meson.build'), + 'comments': files('crazy_comments.meson'), + 'indentation': files('indentation.meson'), +} + +foreach name, f : meson_files + test(name, meson_cmd, args: ['format', '--check-only', f]) +endforeach diff --git a/test cases/format/2 muon/crazy_comments.meson b/test cases/format/2 muon/crazy_comments.meson new file mode 100644 index 000000000..5ebda7d63 --- /dev/null +++ b/test cases/format/2 muon/crazy_comments.meson @@ -0,0 +1,47 @@ +# SPDX-FileCopyrightText: Stone Tickle <lattis@mochiro.moe> +# SPDX-License-Identifier: GPL-3.0-only + +project('a') + +if ( + # comment + false # in a weird +) # place! # test +else +endif # test2 + +foreach a : ( + # test 7 + b # test 4 +) # test 6 # test 3 +endforeach +# test 5 + +a = [ + 1, + # inner + 2, # between comma + # between comma 2 +] # trailing + +( + # hello + a() +) +( + # comment 1 + # comment 2 + # comment 3 + a # comment 4 + # comment 5 + # comment 6 + = ( + # comment 7 + 1 # comment 8 + # comment 9 + + 2 # comment 10 + ) # comment 11 + # comment 12 +) # comment 13 + +# trailing comment diff --git a/test cases/format/2 muon/indentation.meson b/test cases/format/2 muon/indentation.meson new file mode 100644 index 000000000..8f891d57c --- /dev/null +++ b/test cases/format/2 muon/indentation.meson @@ -0,0 +1,71 @@ +project( + 'indentation', + default_options: { + 'buildtype': 'release', + 'default_library': 'shared', + 'prefer_static': false, + 'unity': 'off', + }, + meson_version: '>= 1.5.0', + version: '1.2.3', +) + +a = [ + 1, + 2, + 3, + [ + 4, + 5, + 6, + [ + 7, + 8, + 9, + [ + 10, # 10 + 11, # 11 + 12, # 12 + ], + 13, + 14, + 15, + ], + ], +] +d = {} + +if meson.project_version().version_compare('>1.2') + if meson.version().version_compare('>1.0') + foreach i : a + e = { + 'a': 'a', + 'b': 'b', + 'c': 'c', + 'd': [ + 1, + 2, + 3, + { + 'e': 'e', + 'f': 'f', + 'g': 'g', + 'h': { + 'i': ( + # a + 1 # b + # c + + 2 + ), + 'j': [ + 1, # 1 + 2, # 2 + 3, # 3 + ], + }, + }, + ], + } + endforeach + endif +endif diff --git a/test cases/format/2 muon/meson.build b/test cases/format/2 muon/meson.build new file mode 100644 index 000000000..165e38a5f --- /dev/null +++ b/test cases/format/2 muon/meson.build @@ -0,0 +1,14 @@ +# This file is for testing meson format is compatible with muon format + +project('default format') + +meson_cmd = find_program('meson') +meson_files = { + 'self': files('meson.build'), + 'comments': files('crazy_comments.meson'), + 'indentation': files('indentation.meson'), +} + +foreach name, f : meson_files + test(name, meson_cmd, args: ['fmt', '-q', '-c', files('muon.ini'), f]) +endforeach diff --git a/test cases/format/2 muon/muon.ini b/test cases/format/2 muon/muon.ini new file mode 100644 index 000000000..f35fa3a23 --- /dev/null +++ b/test cases/format/2 muon/muon.ini @@ -0,0 +1,15 @@ +; This config should behave like muon default config + +; max_line_length = 80 +; indent_by = ' ' +; space_array = false +; kwargs_force_multiline = false +; wide_colon = false +; no_single_comma_function = false + +indent_before_comments = ' ' +end_of_line = lf +simplify_string_literals = false +; insert_final_newline = true +sort_files = false +; group_arg_value = false diff --git a/test cases/format/3 editorconfig/.editorconfig b/test cases/format/3 editorconfig/.editorconfig new file mode 100644 index 000000000..522922600 --- /dev/null +++ b/test cases/format/3 editorconfig/.editorconfig @@ -0,0 +1,8 @@ +root = true + +[*] + +indent_style = tab +indent_size = 1 +tab_width = 4 +max_line_length = 60 diff --git a/test cases/format/3 editorconfig/crazy_comments.meson b/test cases/format/3 editorconfig/crazy_comments.meson new file mode 100644 index 000000000..788ea1c88 --- /dev/null +++ b/test cases/format/3 editorconfig/crazy_comments.meson @@ -0,0 +1,47 @@ +# SPDX-FileCopyrightText: Stone Tickle <lattis@mochiro.moe> +# SPDX-License-Identifier: GPL-3.0-only + +project('a') + +if ( + # comment + false # in a weird +) # place! # test +else +endif # test2 + +foreach a : ( + # test 7 + b # test 4 +) # test 6 # test 3 +endforeach +# test 5 + +a = [ + 1, + # inner + 2, # between comma + # between comma 2 +] # trailing + +( + # hello + a() +) +( + # comment 1 + # comment 2 + # comment 3 + a # comment 4 + # comment 5 + # comment 6 + = ( + # comment 7 + 1 # comment 8 + # comment 9 + + 2 # comment 10 + ) # comment 11 + # comment 12 +) # comment 13 + +# trailing comment diff --git a/test cases/format/3 editorconfig/indentation.meson b/test cases/format/3 editorconfig/indentation.meson new file mode 100644 index 000000000..2f348b08f --- /dev/null +++ b/test cases/format/3 editorconfig/indentation.meson @@ -0,0 +1,73 @@ +project( + 'indentation', + default_options: { + 'buildtype': 'release', + 'default_library': 'shared', + 'prefer_static': false, + 'unity': 'off', + }, + meson_version: '>= 1.5.0', + version: '1.2.3', +) + +a = [ + 1, + 2, + 3, + [ + 4, + 5, + 6, + [ + 7, + 8, + 9, + [ + 10, # 10 + 11, # 11 + 12, # 12 + ], + 13, + 14, + 15, + ], + ], +] +d = {} + +if meson.project_version().version_compare('>1.2') + if meson.version().version_compare('>1.0') + foreach i : a + e = { + 'a': 'a', + 'b': 'b', + 'c': 'c', + 'd': [ + 1, + 2, + 3, + { + 'e': 'e', + 'f': 'f', + 'g': 'g', + 'h': { + 'i': ( + # a + 1 + # b + + + # c + 2 + ), + 'j': [ + 1, # 1 + 2, # 2 + 3, # 3 + ], + }, + }, + ], + } + endforeach + endif +endif diff --git a/test cases/format/3 editorconfig/meson.build b/test cases/format/3 editorconfig/meson.build new file mode 100644 index 000000000..b32974cb9 --- /dev/null +++ b/test cases/format/3 editorconfig/meson.build @@ -0,0 +1,31 @@ +# This file is for testing meson format with editor config + +project('default format') + +meson_cmd = find_program('meson') +meson_files = { + 'self': files('meson.build'), + 'comments': files('crazy_comments.meson'), + 'indentation': files('indentation.meson'), +} + +foreach name, f : meson_files + test( + name, + meson_cmd, + args: ['format', '-e', '--check-only', f], + ) + + # Test that .editorconfig can also be loaded from options file + test( + name + '-fromconfig', + meson_cmd, + args: [ + 'format', + '-c', + files('options.ini'), + '--check-only', + f, + ], + ) +endforeach diff --git a/test cases/format/3 editorconfig/options.ini b/test cases/format/3 editorconfig/options.ini new file mode 100644 index 000000000..d9f9f338b --- /dev/null +++ b/test cases/format/3 editorconfig/options.ini @@ -0,0 +1 @@ +use_editor_config = true diff --git a/test cases/format/4 config/crazy_comments.meson b/test cases/format/4 config/crazy_comments.meson new file mode 100644 index 000000000..557d5d409 --- /dev/null +++ b/test cases/format/4 config/crazy_comments.meson @@ -0,0 +1,47 @@ +# SPDX-FileCopyrightText: Stone Tickle <lattis@mochiro.moe> +# SPDX-License-Identifier: GPL-3.0-only + +project('a') + +if ( + # comment + false # in a weird +) # place! # test +else +endif # test2 + +foreach a : ( + # test 7 + b # test 4 +) # test 6 # test 3 +endforeach +# test 5 + +a = [ + 1, + # inner + 2, # between comma + # between comma 2 +] # trailing + +( + # hello + a() +) +( + # comment 1 + # comment 2 + # comment 3 + a # comment 4 + # comment 5 + # comment 6 + = ( + # comment 7 + 1 # comment 8 + # comment 9 + + 2 # comment 10 + ) # comment 11 + # comment 12 +) # comment 13 + +# trailing comment diff --git a/test cases/format/4 config/indentation.meson b/test cases/format/4 config/indentation.meson new file mode 100644 index 000000000..816b5f302 --- /dev/null +++ b/test cases/format/4 config/indentation.meson @@ -0,0 +1,73 @@ +project( + 'indentation', + default_options : { + 'buildtype' : 'release', + 'default_library' : 'shared', + 'prefer_static' : false, + 'unity' : 'off', + }, + meson_version : '>= 1.5.0', + version : '1.2.3', +) + +a = [ + 1, + 2, + 3, + [ + 4, + 5, + 6, + [ + 7, + 8, + 9, + [ + 10, # 10 + 11, # 11 + 12, # 12 + ], + 13, + 14, + 15, + ], + ], +] +d = {} + +if meson.project_version().version_compare('>1.2') + if meson.version().version_compare('>1.0') + foreach i : a + e = { + 'a' : 'a', + 'b' : 'b', + 'c' : 'c', + 'd' : [ + 1, + 2, + 3, + { + 'e' : 'e', + 'f' : 'f', + 'g' : 'g', + 'h' : { + 'i' : ( + # a + 1 + # b + + + # c + 2 + ), + 'j' : [ + 1, # 1 + 2, # 2 + 3, # 3 + ], + }, + }, + ], + } + endforeach + endif +endif diff --git a/test cases/format/4 config/meson.build b/test cases/format/4 config/meson.build new file mode 100644 index 000000000..7b49145dc --- /dev/null +++ b/test cases/format/4 config/meson.build @@ -0,0 +1,19 @@ +# This file is for testing meson format with custom options. +# It ensures 'meson.format' file is automatically loaded. + +project('default format') + +meson_cmd = find_program('meson') +meson_files = { + 'self' : files('meson.build'), + 'comments' : files('crazy_comments.meson'), + 'indentation' : files('indentation.meson'), +} + +foreach name, f : meson_files + test( + name, + meson_cmd, + args : [ 'format', '--check-only', f ], + ) +endforeach diff --git a/test cases/format/4 config/meson.format b/test cases/format/4 config/meson.format new file mode 100644 index 000000000..91f9143ec --- /dev/null +++ b/test cases/format/4 config/meson.format @@ -0,0 +1,11 @@ +; Different options for config + +max_line_length = 120 +indent_by = ' ' +space_array = true +kwargs_force_multiline = true +wide_colon = true +no_single_comma_function = true + +indent_before_comments = ' ' +; end_of_line = 'native' diff --git a/test cases/format/5 transform/default.expected.meson b/test cases/format/5 transform/default.expected.meson new file mode 100644 index 000000000..4201053e1 --- /dev/null +++ b/test cases/format/5 transform/default.expected.meson @@ -0,0 +1,69 @@ +project('a') # should be on one line + + +# List should be removed, and should be on one line +options_ini = 'options.ini' +f = files(options_ini, 'expected.meson', 'source.meson') + +# This array should fit on one line +a1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21] + +# This array is too long and should be splitted +a2 = [ + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + 14, + 15, + 16, + 17, + 18, + 19, + 20, + 21, + 22, +] + +# space array +a3 = [1, 2, 3] + +# no single comma function +fct = files( + 'meson.build', # force multiline +) + +# wide colon +d = {'a': 1, 'b': 2, 'c': 3} + +# string conversion +'This is not a multiline' +'This is not a fstring' + +# group arg value +arguments = [ + 'a', + '--opt_a', + 'opt_a_value', + 'b', + 'c', + '--opt_d', + '--opt_e', + 'opt_e_value', + '--opt_f', + '--opt_g', + 'opt_g_value', + 'other_value', + 'again', + '--x', +] + +# no final endline diff --git a/test cases/format/5 transform/default.ini b/test cases/format/5 transform/default.ini new file mode 100644 index 000000000..a0ff816fe --- /dev/null +++ b/test cases/format/5 transform/default.ini @@ -0,0 +1,15 @@ +; Use default values for config + +; max_line_length = 80 +; indent_by = ' ' +; space_array = false +; kwargs_force_multiline = false +; wide_colon = false +; no_single_comma_function = false + +; indent_before_comments = ' ' +; end_of_line = 'native' +; simplify_string_literals = true +; insert_final_newline = true +; sort_files = true +; group_arg_value = false diff --git a/test cases/format/5 transform/file_compare.py b/test cases/format/5 transform/file_compare.py new file mode 100644 index 000000000..7b0d1b856 --- /dev/null +++ b/test cases/format/5 transform/file_compare.py @@ -0,0 +1,7 @@ +#!/usr/bin/env python3 + +import sys + +with open(sys.argv[1], 'r', encoding='utf-8') as f, open(sys.argv[2], 'r', encoding='utf-8') as g: + if f.read() != g.read(): + sys.exit('contents are not equal') diff --git a/test cases/format/5 transform/genexpected.cmd b/test cases/format/5 transform/genexpected.cmd new file mode 100644 index 000000000..de3699dde --- /dev/null +++ b/test cases/format/5 transform/genexpected.cmd @@ -0,0 +1,7 @@ +@echo off +REM This script generates the expected files +REM Please double-check the contents of those files before commiting them!!! + +python ../../../meson.py format -o default.expected.meson source.meson +python ../../../meson.py format -c muon.ini -o muon.expected.meson source.meson +python ../../../meson.py format -c options.ini -o options.expected.meson source.meson diff --git a/test cases/format/5 transform/meson.build b/test cases/format/5 transform/meson.build new file mode 100644 index 000000000..d15fd1866 --- /dev/null +++ b/test cases/format/5 transform/meson.build @@ -0,0 +1,29 @@ +project('format') + +fs = import('fs') + +meson_cmd = find_program('meson') +file_compare = find_program(files('file_compare.py')) +config = get_option('fmt_config') + +source = files('source.meson') +config_file = files(config + '.ini') +expected = files(config + '.expected.meson') + +transform = custom_target( + input: [config_file, source], + output: 'transformed.meson', + command: [ + meson_cmd, + 'format', + '--output', '@OUTPUT@', + '--configuration', '@INPUT@', + ], +) + + +test( + 'transform', + file_compare, + args: [transform, expected], +) diff --git a/test cases/format/5 transform/meson.options b/test cases/format/5 transform/meson.options new file mode 100644 index 000000000..16927831a --- /dev/null +++ b/test cases/format/5 transform/meson.options @@ -0,0 +1 @@ +option('fmt_config', type: 'string', value: 'default') diff --git a/test cases/format/5 transform/muon.expected.meson b/test cases/format/5 transform/muon.expected.meson new file mode 100644 index 000000000..871ce27d7 --- /dev/null +++ b/test cases/format/5 transform/muon.expected.meson @@ -0,0 +1,69 @@ +project('a') # should be on one line + + +# List should be removed, and should be on one line +options_ini = 'options.ini' +f = files('expected.meson', 'source.meson', options_ini) + +# This array should fit on one line +a1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21] + +# This array is too long and should be splitted +a2 = [ + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + 14, + 15, + 16, + 17, + 18, + 19, + 20, + 21, + 22, +] + +# space array +a3 = [1, 2, 3] + +# no single comma function +fct = files( + 'meson.build', # force multiline +) + +# wide colon +d = {'a': 1, 'b': 2, 'c': 3} + +# string conversion +'''This is not a multiline''' +f'This is not a fstring' + +# group arg value +arguments = [ + 'a', + '--opt_a', + 'opt_a_value', + 'b', + 'c', + '--opt_d', + '--opt_e', + 'opt_e_value', + '--opt_f', + '--opt_g', + 'opt_g_value', + 'other_value', + 'again', + '--x', +] + +# no final endline diff --git a/test cases/format/5 transform/muon.ini b/test cases/format/5 transform/muon.ini new file mode 100644 index 000000000..9bf765948 --- /dev/null +++ b/test cases/format/5 transform/muon.ini @@ -0,0 +1,15 @@ +; This config should behave like muon default config + +; max_line_length = 80 +; indent_by = ' ' +; space_array = false +; kwargs_force_multiline = false +; wide_colon = false +; no_single_comma_function = false + +indent_before_comments = ' ' +end_of_line = lf +simplify_string_literals = false +; insert_final_newline = true +sort_files = false +; group_arg_value = false
\ No newline at end of file diff --git a/test cases/format/5 transform/options.expected.meson b/test cases/format/5 transform/options.expected.meson new file mode 100644 index 000000000..f7f45658d --- /dev/null +++ b/test cases/format/5 transform/options.expected.meson @@ -0,0 +1,48 @@ +project('a') # should be on one line + + +# List should be removed, and should be on one line +options_ini = 'options.ini' +f = files(options_ini, 'expected.meson', 'source.meson') + +# This array should fit on one line +a1 = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21 ] + +# This array is too long and should be splitted +a2 = [ 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22 ] + +# space array +a3 = [ 1, 2, 3 ] + +# no single comma function +fct = files( + 'meson.build' # force multiline +) + +# wide colon +d = { + 'a' : 1, + 'b' : 2, + 'c' : 3, +} + +# string conversion +'This is not a multiline' +'This is not a fstring' + +# group arg value +arguments = [ + 'a', + '--opt_a', 'opt_a_value', + 'b', + 'c', + '--opt_d', + '--opt_e', 'opt_e_value', + '--opt_f', + '--opt_g', 'opt_g_value', + 'other_value', + 'again', + '--x', +] + +# no final endline
\ No newline at end of file diff --git a/test cases/format/5 transform/options.ini b/test cases/format/5 transform/options.ini new file mode 100644 index 000000000..823400b8c --- /dev/null +++ b/test cases/format/5 transform/options.ini @@ -0,0 +1,15 @@ +; Different options for config + +max_line_length = 120 +indent_by = ' ' +space_array = true +kwargs_force_multiline = true +wide_colon = true +no_single_comma_function = true + +indent_before_comments = ' ' +; end_of_line = 'native' +; simplify_string_literals = true +insert_final_newline = false +; sort_files = true +group_arg_value = true diff --git a/test cases/format/5 transform/source.meson b/test cases/format/5 transform/source.meson new file mode 100644 index 000000000..7274d4802 --- /dev/null +++ b/test cases/format/5 transform/source.meson @@ -0,0 +1,37 @@ +project( + 'a' +) # should be on one line + + +# List should be removed, and should be on one line +options_ini = 'options.ini' +f = files( + [ + 'expected.meson', 'source.meson', options_ini]) + +# This array should fit on one line +a1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21] + +# This array is too long and should be splitted +a2 = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22] + +# space array +a3 = [ 1, 2, 3 ] + +# no single comma function +fct = files( + 'meson.build', # force multiline +) + +# wide colon +d = {'a': 1, 'b': 2, 'c': 3} + +# string conversion +'''This is not a multiline''' +f'This is not a fstring' + +# group arg value +arguments = ['a', '--opt_a', 'opt_a_value', 'b', 'c', '--opt_d', '--opt_e', 'opt_e_value', +'--opt_f', '--opt_g', 'opt_g_value', 'other_value', 'again', '--x'] + +# no final endline
\ No newline at end of file diff --git a/test cases/format/5 transform/test.json b/test cases/format/5 transform/test.json new file mode 100644 index 000000000..fe05a52b3 --- /dev/null +++ b/test cases/format/5 transform/test.json @@ -0,0 +1,11 @@ +{ + "matrix": { + "options": { + "fmt_config": [ + { "val": "default"}, + { "val": "muon"}, + { "val": "options"} + ] + } + } +} |
