summaryrefslogtreecommitdiff
path: root/test cases/format/5 transform
diff options
context:
space:
mode:
authorCharles Brunet <charles.brunet@optelgroup.com>2023-09-15 10:19:02 -0400
committerDylan Baker <dylan@pnwbakers.com>2024-04-08 10:43:57 -0700
commit2b37101998c82b8c4d3985d9b0695be38ec4cf76 (patch)
tree1768a7bb40fd5ceab99dd0c10899051049d282ea /test cases/format/5 transform
parentbd4fd9073081bcc9f4505b9604c5cb1e8cdc300f (diff)
downloadmeson-2b37101998c82b8c4d3985d9b0695be38ec4cf76.tar.gz
meson format command
Diffstat (limited to 'test cases/format/5 transform')
-rw-r--r--test cases/format/5 transform/default.expected.meson69
-rw-r--r--test cases/format/5 transform/default.ini15
-rw-r--r--test cases/format/5 transform/file_compare.py7
-rw-r--r--test cases/format/5 transform/genexpected.cmd7
-rw-r--r--test cases/format/5 transform/meson.build29
-rw-r--r--test cases/format/5 transform/meson.options1
-rw-r--r--test cases/format/5 transform/muon.expected.meson69
-rw-r--r--test cases/format/5 transform/muon.ini15
-rw-r--r--test cases/format/5 transform/options.expected.meson48
-rw-r--r--test cases/format/5 transform/options.ini15
-rw-r--r--test cases/format/5 transform/source.meson37
-rw-r--r--test cases/format/5 transform/test.json11
12 files changed, 323 insertions, 0 deletions
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"}
+ ]
+ }
+ }
+}