From 9817fdd46dcb243ab135fbc79ecb60278bfbe821 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sat, 15 Jul 2023 15:06:31 -0400 Subject: [PATCH] Do not set the file property if -[BSSourceView setFile:] fails --- CHANGES.md | 1 + MacGDBp.xcodeproj/project.pbxproj | 10 +++++ Source/BSSourceView.m | 4 +- Source/BSSourceViewTest.m | 64 +++++++++++++++++++++++++++++++ 4 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 Source/BSSourceViewTest.m diff --git a/CHANGES.md b/CHANGES.md index df6ca36..690ee4a 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -4,6 +4,7 @@ MacGDBp CHANGE LOG 2.1.3 --------------------- - Minimum system version is now Mac OS X 10.13. +- Fix: #269 Source pane can appear blank when debugging remote files. 2.1.2 diff --git a/MacGDBp.xcodeproj/project.pbxproj b/MacGDBp.xcodeproj/project.pbxproj index 9bc55cc..d20b92c 100644 --- a/MacGDBp.xcodeproj/project.pbxproj +++ b/MacGDBp.xcodeproj/project.pbxproj @@ -48,6 +48,10 @@ 1EBE15B72438143B006D0D07 /* StepOutTemplate.png in Resources */ = {isa = PBXBuildFile; fileRef = 1EBE15B52438143B006D0D07 /* StepOutTemplate.png */; }; 1EC1337E127DBB00007946FC /* VariableNode.m in Sources */ = {isa = PBXBuildFile; fileRef = 1EC1337D127DBB00007946FC /* VariableNode.m */; }; 1EDA9CF812DD13B300596211 /* BSLineNumberRulerView.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1EDA9CF712DD13B300596211 /* BSLineNumberRulerView.mm */; }; + 1EE7C9B02A62FC2E00D8A9A5 /* BSSourceViewTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 1EE7C9AD2A62FBE500D8A9A5 /* BSSourceViewTest.m */; }; + 1EE7C9B12A62FDD200D8A9A5 /* BSSourceView.m in Sources */ = {isa = PBXBuildFile; fileRef = 1E7188650D839F6300969277 /* BSSourceView.m */; }; + 1EE7C9B22A62FDDC00D8A9A5 /* BSSourceViewTextView.m in Sources */ = {isa = PBXBuildFile; fileRef = 1E1181491319805E003BFEF1 /* BSSourceViewTextView.m */; }; + 1EE7C9B32A62FDE000D8A9A5 /* BSLineNumberRulerView.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1EDA9CF712DD13B300596211 /* BSLineNumberRulerView.mm */; }; 1EE97E55232B11CB000FA8E6 /* ValidatingNSToolbarItem.m in Sources */ = {isa = PBXBuildFile; fileRef = 1EE97E54232B11CB000FA8E6 /* ValidatingNSToolbarItem.m */; }; 1EEBE842176FEA80003622C3 /* MessageQueue.m in Sources */ = {isa = PBXBuildFile; fileRef = 1EEBE841176FEA80003622C3 /* MessageQueue.m */; }; 1EEBE845176FFE04003622C3 /* ProtocolClient.m in Sources */ = {isa = PBXBuildFile; fileRef = 1EEBE844176FFE04003622C3 /* ProtocolClient.m */; }; @@ -146,6 +150,7 @@ 1ED58817231CC66000F0A713 /* MacGDBp.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = MacGDBp.entitlements; sourceTree = ""; }; 1EDA9CF612DD13B300596211 /* BSLineNumberRulerView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BSLineNumberRulerView.h; path = Source/BSLineNumberRulerView.h; sourceTree = ""; }; 1EDA9CF712DD13B300596211 /* BSLineNumberRulerView.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = BSLineNumberRulerView.mm; path = Source/BSLineNumberRulerView.mm; sourceTree = ""; }; + 1EE7C9AD2A62FBE500D8A9A5 /* BSSourceViewTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = BSSourceViewTest.m; path = Source/BSSourceViewTest.m; sourceTree = ""; }; 1EE97E53232B11CB000FA8E6 /* ValidatingNSToolbarItem.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ValidatingNSToolbarItem.h; path = Source/ValidatingNSToolbarItem.h; sourceTree = ""; }; 1EE97E54232B11CB000FA8E6 /* ValidatingNSToolbarItem.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = ValidatingNSToolbarItem.m; path = Source/ValidatingNSToolbarItem.m; sourceTree = ""; }; 1EEBE840176FEA80003622C3 /* MessageQueue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MessageQueue.h; path = Source/MessageQueue.h; sourceTree = ""; }; @@ -287,6 +292,7 @@ children = ( 1E7188640D839F6300969277 /* BSSourceView.h */, 1E7188650D839F6300969277 /* BSSourceView.m */, + 1EE7C9AD2A62FBE500D8A9A5 /* BSSourceViewTest.m */, 1EDA9CF612DD13B300596211 /* BSLineNumberRulerView.h */, 1EDA9CF712DD13B300596211 /* BSLineNumberRulerView.mm */, 1E1181481319805E003BFEF1 /* BSSourceViewTextView.h */, @@ -533,8 +539,12 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 1EE7C9B32A62FDE000D8A9A5 /* BSLineNumberRulerView.mm in Sources */, + 1EE7C9B22A62FDDC00D8A9A5 /* BSSourceViewTextView.m in Sources */, + 1EE7C9B12A62FDD200D8A9A5 /* BSSourceView.m in Sources */, 1E87EFD1232B800900FF6348 /* BreakpointManager.m in Sources */, 1E8C70A41BDB183300D333DC /* StackFrame.m in Sources */, + 1EE7C9B02A62FC2E00D8A9A5 /* BSSourceViewTest.m in Sources */, 1E8C70A21BDB16A900D333DC /* DebuggerModelTest.m in Sources */, 1E87EFD5232B807000FF6348 /* PreferenceNames.m in Sources */, 1E8C70A31BDB173A00D333DC /* DebuggerModel.m in Sources */, diff --git a/Source/BSSourceView.m b/Source/BSSourceView.m index 915ff95..2fd3ebe 100644 --- a/Source/BSSourceView.m +++ b/Source/BSSourceView.m @@ -62,13 +62,13 @@ */ - (void)setFile:(NSString*)f { - _file = [f copy]; - if (![[NSFileManager defaultManager] fileExistsAtPath:f]) { + _file = nil; [_textView setString:@""]; return; } + _file = [f copy]; [self setSourceFile:f completionHandler:nil]; } diff --git a/Source/BSSourceViewTest.m b/Source/BSSourceViewTest.m new file mode 100644 index 0000000..82c4aa8 --- /dev/null +++ b/Source/BSSourceViewTest.m @@ -0,0 +1,64 @@ +/* + * MacGDBp + * Copyright (c) 2023, Blue Static + * + * This program is free software; you can redistribute it and/or modify it under the terms of the GNU + * General Public License as published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without + * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with this program; if not, + * write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#import + +#import "BSSourceView.h" + +@interface BSSourceViewTest : XCTestCase +@end + +@implementation BSSourceViewTest { + BSSourceView* __strong _sourceView; +} + +- (void)setUp +{ + _sourceView = [[BSSourceView alloc] initWithFrame:NSMakeRect(0, 0, 500, 1000)]; +} + +- (void)testSetFile +{ + NSString* thisFile = @(__FILE__); + [_sourceView setFile:thisFile]; + XCTAssertEqualObjects(thisFile, _sourceView.file); + XCTAssertTrue([_sourceView.textView.textStorage.string containsString:@"This very unique string."]); +} + +- (void)testSetNonExistentFile +{ + NSString* nonExistentFile = @"/this/path/does/not/exist"; + [_sourceView setFile:nonExistentFile]; + XCTAssertNil(_sourceView.file); + XCTAssertEqualObjects(@"", _sourceView.textView.textStorage.string); +} + +- (void)testSetAndThenNonExistentFile +{ + [self testSetFile]; + [self testSetNonExistentFile]; +} + +- (void)testSourceAsFile +{ + NSString* file = @"/file.php"; + NSString* source = @"