From 60897300c5dd2bfcf0677c4746acda78a0093126 Mon Sep 17 00:00:00 2001 From: Adrian McCarthy Date: Mon, 25 Jan 2016 19:13:35 +0000 Subject: Fix TestSourceManager.py on Windows. Python 3.5 is picky about writing strings to binary files, so we now open the file in text mode, and we explicitly set the newline mode to avoid re-writing it with CR+LF on Windows (which causes git to think the file had changed). llvm-svn: 258704 --- .../lldbsuite/test/source-manager/TestSourceManager.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'lldb/packages/Python/lldbsuite/test/source-manager/TestSourceManager.py') diff --git a/lldb/packages/Python/lldbsuite/test/source-manager/TestSourceManager.py b/lldb/packages/Python/lldbsuite/test/source-manager/TestSourceManager.py index b4e7541a709..3b7dd8c8bce 100644 --- a/lldb/packages/Python/lldbsuite/test/source-manager/TestSourceManager.py +++ b/lldb/packages/Python/lldbsuite/test/source-manager/TestSourceManager.py @@ -80,13 +80,13 @@ class SourceManagerTestCase(TestBase): main_c_hidden = os.path.join("hidden", main_c) os.rename(main_c, main_c_hidden) + # Restore main.c after the test. + self.addTearDownHook(lambda: os.rename(main_c_hidden, main_c)) + if self.TraceOn(): system([["ls"]]) system([["ls", "hidden"]]) - # Restore main.c after the test. - self.addTearDownHook(lambda: os.rename(main_c_hidden, main_c)) - # Set target.source-map settings. self.runCmd("settings set target.source-map %s %s" % (os.getcwd(), os.path.join(os.getcwd(), "hidden"))) # And verify that the settings work. @@ -133,7 +133,7 @@ class SourceManagerTestCase(TestBase): self.assertTrue(int(m.group(1)) > 0) # Read the main.c file content. - with open('main.c', 'r') as f: + with io.open('main.c', 'r', newline='\n') as f: original_content = f.read() if self.TraceOn(): print("original content:", original_content) @@ -145,7 +145,7 @@ class SourceManagerTestCase(TestBase): def restore_file(): #print("os.path.getmtime() before restore:", os.path.getmtime('main.c')) time.sleep(1) - with open('main.c', 'wb') as f: + with io.open('main.c', 'w', newline='\n') as f: f.write(original_content) if self.TraceOn(): with open('main.c', 'r') as f: @@ -156,9 +156,8 @@ class SourceManagerTestCase(TestBase): print("os.path.getmtime() after restore:", os.path.getmtime('main.c')) - # Modify the source code file. - with open('main.c', 'wb') as f: + with io.open('main.c', 'w', newline='\n') as f: time.sleep(1) f.write(new_content) if self.TraceOn(): -- cgit v1.2.3