From 080baf4894e491e2bd812c7cd2a79059ca1b07a2 Mon Sep 17 00:00:00 2001 From: PerfectLaugh Date: Sun, 20 Aug 2023 05:56:38 +0800 Subject: [PATCH] tests: add `defines` ManifestKey --- tests/compile-only/defines/fail-main.sp | 7 ++++++ tests/compile-only/defines/fail-main.txt | 2 ++ tests/compile-only/defines/ok-main.sp | 9 +++++++ tests/runtests.py | 32 ++++++++++++++++++++---- 4 files changed, 45 insertions(+), 5 deletions(-) create mode 100644 tests/compile-only/defines/fail-main.sp create mode 100644 tests/compile-only/defines/fail-main.txt create mode 100644 tests/compile-only/defines/ok-main.sp diff --git a/tests/compile-only/defines/fail-main.sp b/tests/compile-only/defines/fail-main.sp new file mode 100644 index 000000000..2f8cb2d55 --- /dev/null +++ b/tests/compile-only/defines/fail-main.sp @@ -0,0 +1,7 @@ +#if defined A +#define B 20 +#endif + +public int DefinesFailTest() { + return A + B; +} diff --git a/tests/compile-only/defines/fail-main.txt b/tests/compile-only/defines/fail-main.txt new file mode 100644 index 000000000..362d45107 --- /dev/null +++ b/tests/compile-only/defines/fail-main.txt @@ -0,0 +1,2 @@ +(6) : error 017: undefined symbol "A" +(6) : error 017: undefined symbol "B" diff --git a/tests/compile-only/defines/ok-main.sp b/tests/compile-only/defines/ok-main.sp new file mode 100644 index 000000000..bb15b1e5c --- /dev/null +++ b/tests/compile-only/defines/ok-main.sp @@ -0,0 +1,9 @@ +// defines: ["A=10"] + +#if defined A +#define B 20 +#endif + +public int DefinesFailTest() { + return A + B; +} diff --git a/tests/runtests.py b/tests/runtests.py index eaef13cee..a64984256 100644 --- a/tests/runtests.py +++ b/tests/runtests.py @@ -1,11 +1,12 @@ # vim: set ts=2 sw=2 tw=99 et: import argparse +import ast import datetime import os import platform import re -import subprocess import sys + import testutil from testutil import manifest_get @@ -252,12 +253,13 @@ def find_tests_impl(self, local_folder, manifest): ### class Test(object): ManifestKeys = set([ - 'type', - 'returnCode', - 'warnings_are_errors', 'compiler', - 'force_old_parser', + 'defines', 'force_new_parser', + 'force_old_parser', + 'returnCode', + 'type', + 'warnings_are_errors', ]) def __init__(self, **kwargs): @@ -341,6 +343,22 @@ def expectedReturnCode(self): if 'returnCode' in self.local_manifest_: return int(self.local_manifest_['returnCode']) return 0 + + @property + def defines(self): + if 'defines' in self.local_manifest_: + value = self.local_manifest_['defines'] + if isinstance(value, str): + try: + value = ast.literal_eval(value) + if isinstance(value, list): + return value + except: + pass + + return [value] + + return [] def should_run(self, mode): compiler = self.local_manifest_.get('compiler', None) @@ -495,8 +513,12 @@ def run_compiler(self, mode, test): argv += mode['spcomp']['args'] argv += mode['args'] argv += ['-z', '1'] # Fast compilation for tests. + if test.warnings_are_errors: argv += ['-E'] + for define in test.defines: + argv += [define] + if mode['spcomp']['name'] == 'spcomp2': argv += ['-o', test.smx_path] argv += [self.fix_path(spcomp_path, test.path)]