diff options
Diffstat (limited to 'src/engine/SCons/cppTests.py')
-rw-r--r-- | src/engine/SCons/cppTests.py | 145 |
1 files changed, 142 insertions, 3 deletions
diff --git a/src/engine/SCons/cppTests.py b/src/engine/SCons/cppTests.py index 2108277..6d41ab0 100644 --- a/src/engine/SCons/cppTests.py +++ b/src/engine/SCons/cppTests.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2001 - 2017 The SCons Foundation +# Copyright (c) 2001 - 2019 The SCons Foundation # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the @@ -23,7 +23,7 @@ from __future__ import absolute_import -__revision__ = "src/engine/SCons/cppTests.py rel_3.0.0:4395:8972f6a2f699 2017/09/18 12:59:24 bdbaddog" +__revision__ = "src/engine/SCons/cppTests.py e724ae812eb96f4858a132f5b8c769724744faf6 2019-07-21 00:04:47 bdeegan" import atexit import sys @@ -346,6 +346,80 @@ nested_ifs_input = """ +ifndef_input = """ +#define DEFINED 0 + +#ifndef DEFINED +#include "file45-no" +#else +#include "file45-yes" +#endif + +#ifndef NOT_DEFINED +#include <file46-yes> +#else +#include <file46-no> +#endif +""" + + +if_defined_no_space_input = """ +#define DEFINED 0 + +#if(defined DEFINED) +#include "file47-yes" +#endif + +#if(!defined DEFINED) +#include <file48-no> +#elif(!defined DEFINED) +#include <file49-no> +#else +#include <file50-yes> +#endif + +#if!(defined DEFINED) +#include "file51-no" +#elif!(defined DEFINED) +#include <file52-no> +#else +#include "file53-yes" +#endif +""" + +if_no_space_input = """ +#define DEFINED 0 + +#if(DEFINED) +#include "file54-no" +#endif + +#if!(DEFINED) +#include <file55-yes> +#elif!(DEFINED) +#include <file56-no> +#endif + +#if(DEFINED) +#include "file57-no" +#elif(!DEFINED) +#include <file58-yes> +#endif + +#if!( DEFINED) +#include "file59-yes" +#elif!( DEFINED) +#include <file60-no> +#endif + +#if( DEFINED) +#include "file61-no" +#elif(! DEFINED) +#include <file62-yes> +#endif +""" + + # pp_class = PreProcessor # #pp_class = DumbPreProcessor @@ -426,6 +500,25 @@ class cppTestCase(unittest.TestCase): result = self.cpp.process_contents(nested_ifs_input) assert expect == result, (expect, result) + def test_ifndef(self): + """Test basic #ifndef processing""" + expect = self.ifndef_expect + result = self.cpp.process_contents(ifndef_input) + assert expect == result, (expect, result) + + def test_if_defined_no_space(self): + """Test #if(defined, i.e.without space but parenthesis""" + expect = self.if_defined_no_space_expect + result = self.cpp.process_contents(if_defined_no_space_input) + assert expect == result, (expect, result) + + def test_if_no_space(self): + """Test #if(, i.e. without space but parenthesis""" + expect = self.if_no_space_expect + result = self.cpp.process_contents(if_no_space_input) + assert expect == result, (expect, result) + + class cppAllTestCase(cppTestCase): def setUp(self): self.cpp = self.cpp_class(current = ".", @@ -513,6 +606,24 @@ class PreProcessorTestCase(cppAllTestCase): ('include', '"', 'file7-yes'), ] + ifndef_expect = [ + ('include', '"', 'file45-yes'), + ('include', '<', 'file46-yes'), + ] + + if_defined_no_space_expect = [ + ('include', '"', 'file47-yes'), + ('include', '<', 'file50-yes'), + ('include', '"', 'file53-yes'), + ] + + if_no_space_expect = [ + ('include', '<', 'file55-yes'), + ('include', '<', 'file58-yes'), + ('include', '"', 'file59-yes'), + ('include', '<', 'file62-yes'), + ] + class DumbPreProcessorTestCase(cppAllTestCase): cpp_class = cpp.DumbPreProcessor @@ -625,7 +736,34 @@ class DumbPreProcessorTestCase(cppAllTestCase): ('include', '"', 'file7-yes') ] + ifndef_expect = [ + ('include', '"', 'file45-no'), + ('include', '"', 'file45-yes'), + ('include', '<', 'file46-yes'), + ('include', '<', 'file46-no'), + ] + + if_defined_no_space_expect = [ + ('include', '"', 'file47-yes'), + ('include', '<', 'file48-no'), + ('include', '<', 'file49-no'), + ('include', '<', 'file50-yes'), + ('include', '"', 'file51-no'), + ('include', '<', 'file52-no'), + ('include', '"', 'file53-yes'), + ] + if_no_space_expect = [ + ('include', '"', 'file54-no'), + ('include', '<', 'file55-yes'), + ('include', '<', 'file56-no'), + ('include', '"', 'file57-no'), + ('include', '<', 'file58-yes'), + ('include', '"', 'file59-yes'), + ('include', '<', 'file60-no'), + ('include', '"', 'file61-no'), + ('include', '<', 'file62-yes'), + ] import os import re @@ -679,7 +817,8 @@ class fileTestCase(unittest.TestCase): return '\n'.join(map(strip_spaces, lines)) def write(self, file, contents): - open(file, 'w').write(self.strip_initial_spaces(contents)) + with open(file, 'w') as f: + f.write(self.strip_initial_spaces(contents)) def test_basic(self): """Test basic file inclusion""" |