Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def runTest(self):
from pcpp import Preprocessor
import os, sys
start = clock()
p = Preprocessor()
p.parse(self.input)
oh = StringIO()
p.write(oh)
end = clock()
print("Preprocessed test in", end-start, "seconds")
if oh.getvalue() != self.output:
print("Should be:\n" + self.output, file = sys.stderr)
print("\n\nWas:\n" + oh.getvalue(), file = sys.stderr)
self.assertEqual(p.return_code, 0)
self.assertEqual(oh.getvalue(), self.output)
def runTest(self):
from pcpp import Preprocessor, OutputDirective
import os, sys
class PassThruPreprocessor(Preprocessor):
def on_include_not_found(self,is_system_include,curdir,includepath):
raise OutputDirective()
def on_unknown_macro_in_defined_expr(self,tok):
return None # Pass through as expanded as possible
def on_unknown_macro_in_expr(self,tok):
return None # Pass through as expanded as possible
def on_directive_handle(self,directive,toks,ifpassthru,precedingtoks):
super(PassThruPreprocessor, self).on_directive_handle(directive,toks,ifpassthru,precedingtoks)
return None # Pass through where possible
def on_directive_unknown(self,directive,toks,ifpassthru,precedingtoks):
if directive.value == 'error' or directive.value == 'warning':
super(PassThruPreprocessor, self).on_directive_unknown(directive,toks,ifpassthru,precedingtoks)
def runTest(self):
from pcpp import Preprocessor
import os
start = clock()
p = Preprocessor()
p.compress = 1
p.line_directive = '#'
p.define('__STDC__ 1')
p.define('__STDC_VERSION__ 199901L')
p.define('__DATE__ "Jan 13 2020"')
p.define('__TIME__ "10:47:38"')
p.define('NO_SYSTEM_HEADERS')
path = 'tests/test-c/n_std.c'
with open(path, 'rt') as ih:
p.parse(ih.read(), path)
with open('tests/n_std.i', 'w') as oh:
p.write(oh)
end = clock()
print("Preprocessed", path, "in", end-start, "seconds")
self.assertEqual(p.return_code, 0)
def on_directive_unknown(self,directive,toks,ifpassthru,precedingtoks):
if directive.value == 'error' or directive.value == 'warning':
super(PassThruPreprocessor, self).on_directive_unknown(directive,toks,ifpassthru,precedingtoks)
# Pass through
raise OutputDirective()
def on_include_not_found(self,is_system_include,curdir,includepath):
raise OutputDirective()
def runTest(self):
import doctest, pcpp.preprocessor
failurecount, testcount = doctest.testmod(pcpp.preprocessor)
#self.assertGreater(testcount, 0)
self.assertEqual(failurecount, 0)
def runTest(self):
from pcpp import CmdPreprocessor
p = CmdPreprocessor(['pcpp', '--time', '--passthru-comments',
'-o', 'tests/issue0037.i',
'tests/issue0037/inc.h'])
with open('tests/issue0037.i', 'rt') as ih:
output = ih.read()
if output != shouldbe:
print("Should be:\n" + shouldbe + "EOF\n", file = sys.stderr)
print("\nWas:\n" + output + "EOF\n", file = sys.stderr)
self.assertEqual(p.return_code, 0)
self.assertEqual(output, shouldbe)
def main():
p = CmdPreprocessor(sys.argv)
sys.exit(p.return_code)
def on_potential_include_guard(self,macro):
self.potential_include_guard = macro
return super(CmdPreprocessor, self).on_potential_include_guard(macro)
def on_comment(self,tok):
if self.args.passthru_comments:
return True # Pass through
return super(CmdPreprocessor, self).on_comment(tok)
def main():
p = CmdPreprocessor(sys.argv)
sys.exit(p.return_code)
if __name__ == "__main__":
p = CmdPreprocessor(sys.argv)
sys.exit(p.return_code)
self.on_potential_include_guard(args[n].value)
include_guard = (args[n].value, 0)
at_front_of_file = False
ifstack.append(ifstackentry(enable,iftrigger,ifpassthru,x))
if enable:
iftrigger = False
ifpassthru = False
result, rewritten = self.evalexpr(args)
if rewritten is not None:
x = x[:i+2] + rewritten + [x[-1]]
x[i+1] = copy.copy(x[i+1])
x[i+1].type = self.t_SPACE
x[i+1].value = ' '
ifpassthru = True
ifstack[-1].rewritten = True
raise OutputDirective(Action.IgnoreAndPassThrough)
if not result:
enable = False
else:
iftrigger = True
elif name == 'elif':
at_front_of_file = False
if ifstack:
if ifstack[-1].enable: # We only pay attention if outer "if" allows this
if enable and not ifpassthru: # If already true, we flip enable False
enable = False
elif not iftrigger: # If False, but not triggered yet, we'll check expression
result, rewritten = self.evalexpr(args)
if rewritten is not None:
enable = True
if not ifpassthru:
# This is a passthru #elif after a False #if, so convert to an #if