mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-19 00:54:42 +04:00
Support GN build language
GN is a meta-build system that generates build files for Ninja See also https://gn.googlesource.com/gn/
This commit is contained in:
parent
9c9983dba0
commit
7d323a5c29
2 changed files with 138 additions and 0 deletions
37
tests/languages/gn_test.py
Normal file
37
tests/languages/gn_test.py
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import re
|
||||
|
||||
from pre_commit.languages import gn
|
||||
from testing.language_helpers import run_language
|
||||
|
||||
|
||||
def test_gn_format(tmp_path):
|
||||
# Create a GN file with content that needs formatting
|
||||
gn_file_content = """\
|
||||
source_set("hello_world") {
|
||||
sources = [ "hello_world.cc", ]
|
||||
}
|
||||
"""
|
||||
gn_file = tmp_path.joinpath('test.gn')
|
||||
gn_file.write_text(gn_file_content)
|
||||
|
||||
# Run gn format on the created file
|
||||
ret, out = run_language(tmp_path, gn, f'gn format {gn_file}')
|
||||
|
||||
# Read the formatted file
|
||||
formatted_content = gn_file.read_text()
|
||||
|
||||
assert ret == 0
|
||||
assert gn_file_content != formatted_content
|
||||
|
||||
|
||||
def test_gn_version(tmp_path):
|
||||
ret, out = run_language(
|
||||
tmp_path,
|
||||
gn,
|
||||
'gn --version',
|
||||
)
|
||||
assert ret == 0
|
||||
version_regex = re.compile(rb'\d+ \([a-f0-9]+\)\n')
|
||||
assert version_regex.search(out) is not None
|
||||
Loading…
Add table
Add a link
Reference in a new issue