Author: Alex Langford Date: 2023-04-07T13:50:27-07:00 New Revision: de5f96e99aedd641cc0bbb9ae4a156db4ae3c4c4
URL: https://github.com/llvm/llvm-project/commit/de5f96e99aedd641cc0bbb9ae4a156db4ae3c4c4 DIFF: https://github.com/llvm/llvm-project/commit/de5f96e99aedd641cc0bbb9ae4a156db4ae3c4c4.diff LOG: [lldb] Add unittests for a few FileSpec methods This adds tests for: - FileSpec::TestFileNameExtensions - FileSpec::TestFileNameStrippingExtension - FileSpec::IsSourceImplementationFile This additionally updates incorrect documentation. Differential Revision: https://reviews.llvm.org/D147801 Added: Modified: lldb/include/lldb/Utility/FileSpec.h lldb/unittests/Utility/FileSpecTest.cpp Removed: ################################################################################ diff --git a/lldb/include/lldb/Utility/FileSpec.h b/lldb/include/lldb/Utility/FileSpec.h index e4d3d12979c2..08fd1017eccd 100644 --- a/lldb/include/lldb/Utility/FileSpec.h +++ b/lldb/include/lldb/Utility/FileSpec.h @@ -253,7 +253,7 @@ class FileSpec { /// (files with a ".c", ".cpp", ".m", ".mm" (many more) extension). /// /// \return - /// \b true if the filespec represents an implementation source + /// \b true if the FileSpec represents an implementation source /// file, \b false otherwise. bool IsSourceImplementationFile() const; @@ -327,7 +327,7 @@ class FileSpec { /// Returns a ConstString that represents the extension of the filename for /// this FileSpec object. If this object does not represent a file, or the /// filename has no extension, ConstString(nullptr) is returned. The dot - /// ('.') character is not returned as part of the extension + /// ('.') character is the first character in the returned string. /// /// \return Returns the extension of the file as a ConstString object. ConstString GetFileNameExtension() const; diff --git a/lldb/unittests/Utility/FileSpecTest.cpp b/lldb/unittests/Utility/FileSpecTest.cpp index 76781246322c..96f19953c3b7 100644 --- a/lldb/unittests/Utility/FileSpecTest.cpp +++ b/lldb/unittests/Utility/FileSpecTest.cpp @@ -448,3 +448,59 @@ TEST(FileSpecTest, TestAbsoluteCaching) { file.PrependPathComponent("/tmp"); EXPECT_TRUE(file.IsAbsolute()); } + +TEST(FileSpecTest, TestFileNameExtensions) { + FileSpec dylib = PosixSpec("/tmp/foo.dylib"); + FileSpec exe = PosixSpec("/tmp/foo"); + FileSpec dSYM = PosixSpec("/tmp/foo.dSYM/"); + FileSpec just_dot = PosixSpec("/tmp/bar."); + + EXPECT_TRUE(dylib.GetFileNameExtension() == ".dylib"); + EXPECT_TRUE(exe.GetFileNameExtension() == ConstString(nullptr)); + EXPECT_TRUE(dSYM.GetFileNameExtension() == ".dSYM"); + EXPECT_TRUE(just_dot.GetFileNameExtension() == "."); + + FileSpec dll = WindowsSpec("C:\\tmp\\foo.dll"); + FileSpec win_noext = WindowsSpec("C:\\tmp\\foo"); + + EXPECT_TRUE(dll.GetFileNameExtension() == ".dll"); + EXPECT_TRUE(win_noext.GetFileNameExtension() == ConstString(nullptr)); +} + +TEST(FileSpecTest, TestFileNameStrippingExtension) { + FileSpec dylib = PosixSpec("/tmp/foo.dylib"); + FileSpec exe = PosixSpec("/tmp/foo"); + FileSpec just_dot = PosixSpec("/tmp/bar."); + + EXPECT_TRUE(dylib.GetFileNameStrippingExtension() == "foo"); + EXPECT_TRUE(exe.GetFileNameStrippingExtension() == "foo"); + EXPECT_TRUE(just_dot.GetFileNameStrippingExtension() == "bar"); + + FileSpec dll = WindowsSpec("C:\\tmp\\foo.dll"); + FileSpec win_noext = WindowsSpec("C:\\tmp\\foo"); + + EXPECT_TRUE(dll.GetFileNameStrippingExtension() == "foo"); + EXPECT_TRUE(win_noext.GetFileNameStrippingExtension() == "foo"); +} + +TEST(FileSpecTest, TestIsSourceImplementationFile) { + FileSpec c_src = PosixSpec("/tmp/foo.c"); + FileSpec txt_file = PosixSpec("/tmp/foo.txt"); + FileSpec executable = PosixSpec("/tmp/foo"); + FileSpec just_dot = PosixSpec("/tmp/bar."); + + EXPECT_TRUE(c_src.IsSourceImplementationFile()); + EXPECT_FALSE(txt_file.IsSourceImplementationFile()); + EXPECT_FALSE(executable.IsSourceImplementationFile()); + EXPECT_FALSE(just_dot.IsSourceImplementationFile()); + + FileSpec cpp_src = WindowsSpec("C:\\tmp\\foo.cpp"); + FileSpec dll = WindowsSpec("C:\\tmp\\foo.dll"); + FileSpec win_noext = WindowsSpec("C:\\tmp\\foo"); + FileSpec exe = WindowsSpec("C:\\tmp\\foo.exe"); + + EXPECT_TRUE(cpp_src.IsSourceImplementationFile()); + EXPECT_FALSE(dll.IsSourceImplementationFile()); + EXPECT_FALSE(win_noext.IsSourceImplementationFile()); + EXPECT_FALSE(exe.IsSourceImplementationFile()); +} _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits