aboutsummaryrefslogtreecommitdiff
path: root/unittests
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2023-09-12 17:50:13 +0300
committerGitHub <noreply@github.com>2023-09-12 17:50:13 +0300
commitd2dfef5205f031ab10591899a1fc5048ea6f4134 (patch)
tree3e1be43920441f9167e9ee5498a357a1d378aec8 /unittests
parent1b6c9ad02ab88d92fd055ccc1307456105c064fe (diff)
parent14e35b63c02a16f69dd1ad5bde775e6868965eb2 (diff)
downloadmeson-d2dfef5205f031ab10591899a1fc5048ea6f4134.zip
meson-d2dfef5205f031ab10591899a1fc5048ea6f4134.tar.gz
meson-d2dfef5205f031ab10591899a1fc5048ea6f4134.tar.bz2
Merge pull request #12152 from bruchar1/ast-preserve-all
Preserve whitespaces and comments in AST
Diffstat (limited to 'unittests')
-rw-r--r--unittests/rewritetests.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/unittests/rewritetests.py b/unittests/rewritetests.py
index ca30fe9..c338844 100644
--- a/unittests/rewritetests.py
+++ b/unittests/rewritetests.py
@@ -13,11 +13,15 @@
# limitations under the License.
import subprocess
+from itertools import zip_longest
import json
import os
+from pathlib import Path
import shutil
import unittest
+from mesonbuild.ast import IntrospectionInterpreter, AstIDGenerator
+from mesonbuild.ast.printer import RawPrinter
from mesonbuild.mesonlib import windows_proof_rmtree
from .baseplatformtests import BasePlatformTests
@@ -396,3 +400,21 @@ class RewriterTests(BasePlatformTests):
# Check the written file
out = self.rewrite(self.builddir, os.path.join(self.builddir, 'info.json'))
self.assertDictEqual(out, expected)
+
+ def test_raw_printer_is_idempotent(self):
+ test_path = Path(self.unit_test_dir, '118 rewrite')
+ meson_build_file = test_path / 'meson.build'
+ # original_contents = meson_build_file.read_bytes()
+ original_contents = meson_build_file.read_text(encoding='utf-8')
+
+ interpreter = IntrospectionInterpreter(test_path, '', 'ninja', visitors = [AstIDGenerator()])
+ interpreter.analyze()
+
+ printer = RawPrinter()
+ interpreter.ast.accept(printer)
+ # new_contents = printer.result.encode('utf-8')
+ new_contents = printer.result
+
+ # Do it line per line because it is easier to debug like that
+ for orig_line, new_line in zip_longest(original_contents.splitlines(), new_contents.splitlines()):
+ self.assertEqual(orig_line, new_line)