Skip to content

Commit

Permalink
tests: add defines ManifestKey
Browse files Browse the repository at this point in the history
  • Loading branch information
PerfectLaugh committed Aug 19, 2023
1 parent ac7ba31 commit 080baf4
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 5 deletions.
7 changes: 7 additions & 0 deletions tests/compile-only/defines/fail-main.sp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#if defined A
#define B 20
#endif

public int DefinesFailTest() {
return A + B;
}
2 changes: 2 additions & 0 deletions tests/compile-only/defines/fail-main.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
(6) : error 017: undefined symbol "A"
(6) : error 017: undefined symbol "B"
9 changes: 9 additions & 0 deletions tests/compile-only/defines/ok-main.sp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// defines: ["A=10"]

#if defined A
#define B 20
#endif

public int DefinesFailTest() {
return A + B;
}
32 changes: 27 additions & 5 deletions tests/runtests.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)]
Expand Down

0 comments on commit 080baf4

Please sign in to comment.