Skip to content

Commit 4f0edda

Browse files
committed
Testsuite: rework "main" arguments for build_and_run
In particular, rename "ada_main" to "gpr_main" and allow it to contain both Ada and C mains. Also remove the now useless "with_c" argument, and the unused "mains" one as well.
1 parent 55bcc4c commit 4f0edda

File tree

76 files changed

+364
-267
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+364
-267
lines changed

testsuite/python_support/utils.py

Lines changed: 32 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -204,10 +204,10 @@ def build(grammar=None, lexer=None, lkt_file=None,
204204
warning_set=warning_set)
205205

206206

207-
def build_and_run(grammar=None, py_script=None, ada_main=None, with_c=False,
207+
def build_and_run(grammar=None, py_script=None, gpr_mains=None,
208208
lexer=None, lkt_file=None, types_from_lkt=False,
209209
lkt_semantic_checks=False, ocaml_main=None, java_main=None,
210-
ni_main=None, mains=False, warning_set=default_warning_set,
210+
ni_main=None, warning_set=default_warning_set,
211211
generate_unparser=False, symbol_canonicalizer=None,
212212
show_property_logging=False, unparse_script=unparse_script,
213213
case_insensitive: bool = False,
@@ -237,13 +237,9 @@ def build_and_run(grammar=None, py_script=None, ada_main=None, with_c=False,
237237
:param None|str py_script: If not None, name of the Python script to run
238238
with the built library available.
239239
240-
:param None|str|list[str] ada_main: If not None, list of name of main
241-
source files for Ada programs to build and run with the generated
242-
library. If the input is a single string, consider it's a single mail
243-
source file.
244-
245-
:param bool with_c: Whether to add "C" to the languages of the generated
246-
project.
240+
:param None|list[str] gpr_mains: If not None, list of name of main source
241+
files (Ada and/or C) for the generated GPR file, to build and run with
242+
the generated library.
247243
248244
:param None|str ocaml_main: If not None, name of the OCaml source file to
249245
build and run with the built library available.
@@ -258,8 +254,6 @@ def build_and_run(grammar=None, py_script=None, ada_main=None, with_c=False,
258254
:param langkit.compile_context.LibraryEntity|None symbol_canonicalizer:
259255
Symbol canonicalizer to use for this context, if any.
260256
261-
:param bool mains: Whether to build mains.
262-
263257
:param bool show_property_logging: If true, any property that has been
264258
marked with tracing activated will be traced on stdout by default,
265259
without need for any config file.
@@ -347,10 +341,8 @@ def manage_run(generate_only, types_from_lkt, additional_args):
347341
if generate_unparser:
348342
argv.append('--generate-unparser')
349343

350-
# For testsuite performance, do not generate mains unless told
351-
# otherwise.
352-
if not mains:
353-
argv.append('--disable-all-mains')
344+
# No testcase uses the generated mains, so save time: never build them
345+
argv.append('--disable-all-mains')
354346

355347
argv.extend(additional_args)
356348
argv.extend(additional_make_args)
@@ -420,42 +412,45 @@ def run(*argv, **kwargs):
420412
args.append(py_script)
421413
run(*args)
422414

423-
if ada_main is not None:
424-
if isinstance(ada_main, str):
425-
ada_main = [ada_main]
415+
if gpr_mains:
416+
source_dirs = [".", c_support_dir]
426417

427-
langs = ["Ada"]
428-
source_dirs = ["."]
429-
if with_c:
430-
langs.append("C")
431-
source_dirs.append(c_support_dir)
418+
# Detect languages based on the source files present in the test
419+
# directory.
420+
langs = set()
421+
for f in os.listdir("."):
422+
if any(f.endswith(ext) for ext in [".c", ".h"]):
423+
langs.add("C")
424+
if any(f.endswith(ext) for ext in [".adb", ".ads"]):
425+
langs.add("Ada")
432426

433-
# Generate a project file to build the given Ada main and then run
434-
# the program. Do a static build to improve the debugging experience.
435-
with open('gen.gpr', 'w') as f:
427+
# Generate a project file to build the given mains. Do a static build
428+
# (the default) to improve the debugging experience.
429+
with open("gen.gpr", "w") as f:
436430

437431
def fmt_str_list(strings: List[str]) -> str:
438432
return ", ".join(f'"{s}"' for s in strings)
439433

440434
f.write(project_template.format(
441435
languages=fmt_str_list(langs),
442436
source_dirs=fmt_str_list(source_dirs),
443-
main_sources=fmt_str_list(ada_main),
437+
main_sources=fmt_str_list(gpr_mains),
444438
))
445-
run('gprbuild', '-Pgen', '-q', '-p',
446-
'-XLIBRARY_TYPE=static',
447-
'-XXMLADA_BUILD=static')
439+
run("gprbuild", "-Pgen", "-q", "-p")
448440

449-
for i, m in enumerate(ada_main):
450-
assert m.endswith('.adb')
441+
# Now run all mains. If there are more than one main to run, print a
442+
# heading before each one.
443+
for i, main in enumerate(gpr_mains):
451444
if i > 0:
452-
print('')
453-
if len(ada_main) > 1:
454-
print('== {} =='.format(m))
445+
print("")
446+
if len(gpr_mains) > 1:
447+
print(f"== {main} ==")
455448
sys.stdout.flush()
456-
run(P.join('obj', m[:-4]),
449+
run(
450+
P.join("obj", os.path.splitext(main)[0]),
457451
valgrind=True,
458-
valgrind_suppressions=['gnat'])
452+
valgrind_suppressions=["gnat"],
453+
)
459454

460455
if ocaml_main is not None:
461456
# Set up a Dune project

testsuite/tests/ada_api/bigint_array_comp/test.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ def prop(a=T.BigInt.array):
1919
return a
2020

2121

22-
build_and_run(lkt_file='expected_concrete_syntax.lkt', ada_main=['main.adb'],
23-
types_from_lkt=True)
24-
print('Done')
22+
build_and_run(
23+
lkt_file="expected_concrete_syntax.lkt",
24+
gpr_mains=["main.adb"],
25+
types_from_lkt=True,
26+
)
27+
print("Done")

testsuite/tests/ada_api/calls_on_null/test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ class Decl(FooNode):
2222
value = Field(type=Identifier)
2323

2424

25-
build_and_run(lkt_file='expected_concrete_syntax.lkt', ada_main=['main.adb'])
25+
build_and_run(lkt_file="expected_concrete_syntax.lkt", gpr_mains=["main.adb"])
2626
print('Done')

testsuite/tests/ada_api/children_and_trivia/test.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ class Decl(FooNode):
2525
error = Field(type=DeclError)
2626

2727

28-
build_and_run(lkt_file='expected_concrete_syntax.lkt', ada_main='main.adb',
29-
types_from_lkt=True)
30-
print('Done')
28+
build_and_run(
29+
lkt_file="expected_concrete_syntax.lkt",
30+
gpr_mains=["main.adb"],
31+
types_from_lkt=True,
32+
)
33+
print("Done")

testsuite/tests/ada_api/event_handler/test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class Example(FooNode):
2828

2929
build_and_run(
3030
lkt_file="expected_concrete_syntax.lkt",
31-
ada_main="main.adb",
31+
gpr_mains=["main.adb"],
3232
types_from_lkt=True,
3333
)
3434

testsuite/tests/ada_api/general/test.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ class Decl(FooNode):
2525
error = Field(type=DeclError)
2626

2727

28-
build_and_run(lkt_file='expected_concrete_syntax.lkt', ada_main='main.adb',
29-
types_from_lkt=True)
30-
print('Done')
28+
build_and_run(
29+
lkt_file="expected_concrete_syntax.lkt",
30+
gpr_mains=["main.adb"],
31+
types_from_lkt=True,
32+
)
33+
print("Done")

testsuite/tests/ada_api/generic_api/test.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,11 @@ class Ref(Expr):
169169

170170
build_and_run(
171171
lkt_file="expected_concrete_syntax.lkt",
172-
ada_main=["analysis.adb", "introspection_types.adb",
173-
"introspection_values.adb", "hash.adb"]
172+
gpr_mains=[
173+
"analysis.adb",
174+
"introspection_types.adb",
175+
"introspection_values.adb",
176+
"hash.adb",
177+
],
174178
)
175179
print("Done")

testsuite/tests/ada_api/hashes/test.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ class Example(FooNode):
1515
token_node = True
1616

1717

18-
build_and_run(lkt_file='expected_concrete_syntax.lkt', ada_main=['main.adb'],
19-
types_from_lkt=True)
20-
print('Done')
18+
build_and_run(
19+
lkt_file="expected_concrete_syntax.lkt",
20+
gpr_mains=["main.adb"],
21+
types_from_lkt=True,
22+
)
23+
print("Done")

testsuite/tests/ada_api/lifetimes/test.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ class Example(FooNode):
1616
token_node = True
1717

1818

19-
build_and_run(lkt_file='expected_concrete_syntax.lkt', ada_main=['main.adb'],
20-
types_from_lkt=True)
21-
print('Done')
19+
build_and_run(
20+
lkt_file="expected_concrete_syntax.lkt",
21+
gpr_mains=["main.adb"],
22+
types_from_lkt=True,
23+
)
24+
print("Done")

testsuite/tests/ada_api/member_is_null_for/test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class A2B2(A2):
5454

5555
build_and_run(
5656
lkt_file="expected_concrete_syntax.lkt",
57-
ada_main=["main.adb"],
57+
gpr_mains=["main.adb"],
5858
types_from_lkt=True,
5959
)
6060
print("Done")

0 commit comments

Comments
 (0)