diff options
author | Pavel Labath <labath@google.com> | 2016-04-04 14:39:12 +0000 |
---|---|---|
committer | Pavel Labath <labath@google.com> | 2016-04-04 14:39:12 +0000 |
commit | 144119b86d647f405159259bf4fbf5499578d648 (patch) | |
tree | fb961cf682fd35dd03348281de58e0d4f263e9d2 /lldb/unittests/Host/FileSpecTest.cpp | |
parent | 09464e63d842e1e0e6be300b6bb59bc9c1e7ecdf (diff) | |
download | bcm5719-llvm-144119b86d647f405159259bf4fbf5499578d648.tar.gz bcm5719-llvm-144119b86d647f405159259bf4fbf5499578d648.zip |
Make FileSpec handling platform-independent
Summary:
Even though FileSpec attempted to handle both kinds of path syntaxes (posix and windows) on both
platforms, it relied on the llvm path library to do its work, whose behavior differed on
different platforms. This led to subtle differences in FileSpec behavior between platforms. This
replaces the pieces of the llvm library with our own implementations. The functions are simply
copied from llvm, with #ifdefs replaced by runtime checks for ePathSyntaxWindows.
Reviewers: zturner
Subscribers: lldb-commits
Differential Revision: http://reviews.llvm.org/D18689
llvm-svn: 265299
Diffstat (limited to 'lldb/unittests/Host/FileSpecTest.cpp')
-rw-r--r-- | lldb/unittests/Host/FileSpecTest.cpp | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/lldb/unittests/Host/FileSpecTest.cpp b/lldb/unittests/Host/FileSpecTest.cpp index 461be60ff13..89092c4604d 100644 --- a/lldb/unittests/Host/FileSpecTest.cpp +++ b/lldb/unittests/Host/FileSpecTest.cpp @@ -22,7 +22,7 @@ TEST(FileSpecTest, FileAndDirectoryComponents) FileSpec fs_windows("F:\\bar", false, FileSpec::ePathSyntaxWindows); EXPECT_STREQ("F:\\bar", fs_windows.GetCString()); - EXPECT_STREQ("F:", fs_windows.GetDirectory().GetCString()); + EXPECT_STREQ("F:\\", fs_windows.GetDirectory().GetCString()); EXPECT_STREQ("bar", fs_windows.GetFilename().GetCString()); FileSpec fs_posix_root("/", false, FileSpec::ePathSyntaxPosix); @@ -30,10 +30,15 @@ TEST(FileSpecTest, FileAndDirectoryComponents) EXPECT_EQ(nullptr, fs_posix_root.GetDirectory().GetCString()); EXPECT_STREQ("/", fs_posix_root.GetFilename().GetCString()); - FileSpec fs_windows_root("F:", false, FileSpec::ePathSyntaxWindows); - EXPECT_STREQ("F:", fs_windows_root.GetCString()); - EXPECT_EQ(nullptr, fs_windows_root.GetDirectory().GetCString()); - EXPECT_STREQ("F:", fs_windows_root.GetFilename().GetCString()); + FileSpec fs_windows_drive("F:", false, FileSpec::ePathSyntaxWindows); + EXPECT_STREQ("F:", fs_windows_drive.GetCString()); + EXPECT_EQ(nullptr, fs_windows_drive.GetDirectory().GetCString()); + EXPECT_STREQ("F:", fs_windows_drive.GetFilename().GetCString()); + + FileSpec fs_windows_root("F:\\", false, FileSpec::ePathSyntaxWindows); + EXPECT_STREQ("F:\\", fs_windows_root.GetCString()); + EXPECT_STREQ("F:", fs_windows_root.GetDirectory().GetCString()); + EXPECT_STREQ("\\", fs_windows_root.GetFilename().GetCString()); FileSpec fs_posix_long("/foo/bar/baz", false, FileSpec::ePathSyntaxPosix); EXPECT_STREQ("/foo/bar/baz", fs_posix_long.GetCString()); @@ -43,7 +48,7 @@ TEST(FileSpecTest, FileAndDirectoryComponents) FileSpec fs_windows_long("F:\\bar\\baz", false, FileSpec::ePathSyntaxWindows); EXPECT_STREQ("F:\\bar\\baz", fs_windows_long.GetCString()); // We get "F:/bar" instead. - // EXPECT_STREQ("F:\\bar", fs_windows_long.GetDirectory().GetCString()); + EXPECT_STREQ("F:\\bar", fs_windows_long.GetDirectory().GetCString()); EXPECT_STREQ("baz", fs_windows_long.GetFilename().GetCString()); FileSpec fs_posix_trailing_slash("/foo/bar/", false, FileSpec::ePathSyntaxPosix); @@ -54,7 +59,7 @@ TEST(FileSpecTest, FileAndDirectoryComponents) FileSpec fs_windows_trailing_slash("F:\\bar\\", false, FileSpec::ePathSyntaxWindows); EXPECT_STREQ("F:\\bar\\.", fs_windows_trailing_slash.GetCString()); // We get "F:/bar" instead. - // EXPECT_STREQ("F:\\bar", fs_windows_trailing_slash.GetDirectory().GetCString()); + EXPECT_STREQ("F:\\bar", fs_windows_trailing_slash.GetDirectory().GetCString()); EXPECT_STREQ(".", fs_windows_trailing_slash.GetFilename().GetCString()); } @@ -66,11 +71,11 @@ TEST(FileSpecTest, AppendPathComponent) EXPECT_STREQ("/foo", fs_posix.GetDirectory().GetCString()); EXPECT_STREQ("bar", fs_posix.GetFilename().GetCString()); - FileSpec fs_windows("F:", false, FileSpec::ePathSyntaxWindows); - fs_windows.AppendPathComponent("bar"); - EXPECT_STREQ("F:\\bar", fs_windows.GetCString()); - EXPECT_STREQ("F:", fs_windows.GetDirectory().GetCString()); - EXPECT_STREQ("bar", fs_windows.GetFilename().GetCString()); + FileSpec fs_windows("F:\\bar", false, FileSpec::ePathSyntaxWindows); + fs_windows.AppendPathComponent("baz"); + EXPECT_STREQ("F:\\bar\\baz", fs_windows.GetCString()); + EXPECT_STREQ("F:\\bar", fs_windows.GetDirectory().GetCString()); + EXPECT_STREQ("baz", fs_windows.GetFilename().GetCString()); FileSpec fs_posix_root("/", false, FileSpec::ePathSyntaxPosix); fs_posix_root.AppendPathComponent("bar"); @@ -78,10 +83,10 @@ TEST(FileSpecTest, AppendPathComponent) EXPECT_STREQ("/", fs_posix_root.GetDirectory().GetCString()); EXPECT_STREQ("bar", fs_posix_root.GetFilename().GetCString()); - FileSpec fs_windows_root("F:", false, FileSpec::ePathSyntaxWindows); + FileSpec fs_windows_root("F:\\", false, FileSpec::ePathSyntaxWindows); fs_windows_root.AppendPathComponent("bar"); EXPECT_STREQ("F:\\bar", fs_windows_root.GetCString()); - EXPECT_STREQ("F:", fs_windows_root.GetDirectory().GetCString()); + EXPECT_STREQ("F:\\", fs_windows_root.GetDirectory().GetCString()); EXPECT_STREQ("bar", fs_windows_root.GetFilename().GetCString()); } |