diff options
author | Pawel Bylica <chfast@gmail.com> | 2015-11-02 09:49:17 +0000 |
---|---|---|
committer | Pawel Bylica <chfast@gmail.com> | 2015-11-02 09:49:17 +0000 |
commit | 0e97e5cb1907ef55966fd27055698515e522c0f0 (patch) | |
tree | 96385d621315224f0adcac2af1413d7e64d7bb23 /llvm/unittests/Support | |
parent | 8671c6e03dc6a1e10d41ad825075cb912b05c570 (diff) | |
download | bcm5719-llvm-0e97e5cb1907ef55966fd27055698515e522c0f0.tar.gz bcm5719-llvm-0e97e5cb1907ef55966fd27055698515e522c0f0.zip |
[Support] Extend sys::path with user_cache_directory function.
Summary:
The new function sys::path::user_cache_directory tries to discover
a directory suitable for cache storage for current system user.
On Windows and Darwin it returns a path to system-specific user cache directory.
On Linux it follows XDG Base Directory Specification, what is:
- use non-empty $XDG_CACHE_HOME env var,
- use $HOME/.cache.
Reviewers: chapuni, aaron.ballman, rafael
Subscribers: rafael, aaron.ballman, llvm-commits
Differential Revision: http://reviews.llvm.org/D13801
llvm-svn: 251784
Diffstat (limited to 'llvm/unittests/Support')
-rw-r--r-- | llvm/unittests/Support/Path.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/llvm/unittests/Support/Path.cpp b/llvm/unittests/Support/Path.cpp index 992bba6bcd1..a7a6a4add7c 100644 --- a/llvm/unittests/Support/Path.cpp +++ b/llvm/unittests/Support/Path.cpp @@ -322,6 +322,35 @@ TEST(Support, HomeDirectory) { } } +TEST(Support, UserCacheDirectory) { + SmallString<13> CacheDir; + SmallString<20> CacheDir2; + auto Status = path::user_cache_directory(CacheDir, ""); + EXPECT_TRUE(Status ^ CacheDir.empty()); + + if (Status) { + EXPECT_TRUE(path::user_cache_directory(CacheDir2, "")); // should succeed + EXPECT_EQ(CacheDir, CacheDir2); // and return same paths + + EXPECT_TRUE(path::user_cache_directory(CacheDir, "A", "B", "file.c")); + auto It = path::rbegin(CacheDir); + EXPECT_EQ("file.c", *It); + EXPECT_EQ("B", *++It); + EXPECT_EQ("A", *++It); + auto ParentDir = *++It; + + // Test Unicode: "<user_cache_dir>/(pi)r^2/aleth.0" + EXPECT_TRUE(path::user_cache_directory(CacheDir2, "\xCF\x80r\xC2\xB2", + "\xE2\x84\xB5.0")); + auto It2 = path::rbegin(CacheDir2); + EXPECT_EQ("\xE2\x84\xB5.0", *It2); + EXPECT_EQ("\xCF\x80r\xC2\xB2", *++It2); + auto ParentDir2 = *++It2; + + EXPECT_EQ(ParentDir, ParentDir2); + } +} + class FileSystemTest : public testing::Test { protected: /// Unique temporary directory in which all created filesystem entities must |