From c0b5e62acfa7d4b611a20f26b415af664c22cc88 Mon Sep 17 00:00:00 2001 From: William Deegan Date: Tue, 26 Jun 2018 10:08:57 -0700 Subject: Add test for unicode strings it Configure Contexts TryAction calls --- src/engine/SCons/SConfTests.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/engine/SCons/SConfTests.py b/src/engine/SCons/SConfTests.py index 65c4b5f..e19abaf 100644 --- a/src/engine/SCons/SConfTests.py +++ b/src/engine/SCons/SConfTests.py @@ -300,10 +300,15 @@ int main(void) { """Test SConf.TryAction """ def actionOK(target, source, env): - open(str(target[0]), "w").write( "RUN OK\n" ) + open(str(target[0]), "w").write("RUN OK\n") return None def actionFAIL(target, source, env): return 1 + def actionUnicode(target, source, env): + open(str(target[0]), "wb").write('2\302\242\n') + return None + + self._resetSConfState() sconf = self.SConf.SConf(self.scons_env, conf_dir=self.test.workpath('config.tests'), @@ -313,6 +318,11 @@ int main(void) { assert ret and output.encode('utf-8') == bytearray("RUN OK"+os.linesep,'utf-8'), (ret, output) (ret, output) = sconf.TryAction(action=actionFAIL) assert not ret and output == "", (ret, output) + + # GH Issue #3141 - unicode text and py2.7 crashes. + (ret, output) = sconf.TryAction(action=actionUnicode) + assert ret and output == u'2\xa2\n', (ret, output) + finally: sconf.Finish() @@ -779,8 +789,7 @@ int main(void) { if __name__ == "__main__": - suite = unittest.makeSuite(SConfTestCase, 'test_') - TestUnit.run(suite) + unittest.main() # Local Variables: # tab-width:4 -- cgit v0.12 From 1a80d7b28f8d13798fceff57463c2223c8908c1e Mon Sep 17 00:00:00 2001 From: William Deegan Date: Tue, 26 Jun 2018 10:10:57 -0700 Subject: Fix Issue #3141. Unicode in TryAction crashing. Use get_text_contents instead of get_contents().decode() (get_contents should always be bytes, but not always decode()'able (without specifying encoding) --- src/CHANGES.txt | 1 + src/engine/SCons/SConf.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/CHANGES.txt b/src/CHANGES.txt index b0baecb..4be9068 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -45,6 +45,7 @@ RELEASE 3.1.0.alpha.yyyymmdd - NEW DATE WILL BE INSERTED HERE - Re-Enable parallel SCons (-j) when running via Pypy - Move SCons test framework files to testing/framework and remove all references to QMtest. QMTest has not been used by SCons for some time now. + - Fix GH Issue #3141 unicode string in a TryAction() with python 2.7 crashes. From Andrew Featherstone - Removed unused --warn options from the man page and source code. diff --git a/src/engine/SCons/SConf.py b/src/engine/SCons/SConf.py index 48eed8e..a14127e 100644 --- a/src/engine/SCons/SConf.py +++ b/src/engine/SCons/SConf.py @@ -609,7 +609,7 @@ class SConfBase(object): ok = self.TryBuild(self.env.SConfActionBuilder, text, extension) del self.env['BUILDERS']['SConfActionBuilder'] if ok: - outputStr = self.lastTarget.get_contents().decode() + outputStr = self.lastTarget.get_text_contents() return (1, outputStr) return (0, "") -- cgit v0.12 From 8245f89ad9f5bc564586ff58d680623161810177 Mon Sep 17 00:00:00 2001 From: William Deegan Date: Tue, 26 Jun 2018 10:16:26 -0700 Subject: Fix new test so it only runs with py2.7 as that's the reported crashing environment --- src/engine/SCons/SConfTests.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/engine/SCons/SConfTests.py b/src/engine/SCons/SConfTests.py index e19abaf..dd5b8b9 100644 --- a/src/engine/SCons/SConfTests.py +++ b/src/engine/SCons/SConfTests.py @@ -319,9 +319,10 @@ int main(void) { (ret, output) = sconf.TryAction(action=actionFAIL) assert not ret and output == "", (ret, output) - # GH Issue #3141 - unicode text and py2.7 crashes. - (ret, output) = sconf.TryAction(action=actionUnicode) - assert ret and output == u'2\xa2\n', (ret, output) + if not TestCmd.IS_PY3: + # GH Issue #3141 - unicode text and py2.7 crashes. + (ret, output) = sconf.TryAction(action=actionUnicode) + assert ret and output == u'2\xa2\n', (ret, output) finally: sconf.Finish() -- cgit v0.12