| Index: tools/gn/filesystem_utils_unittest.cc
|
| diff --git a/tools/gn/filesystem_utils_unittest.cc b/tools/gn/filesystem_utils_unittest.cc
|
| index 27ccab2ea4d0db453c217d1921db71729de58aac..2194016e3a72e0cc5d1333533d508ff604ce84b0 100644
|
| --- a/tools/gn/filesystem_utils_unittest.cc
|
| +++ b/tools/gn/filesystem_utils_unittest.cc
|
| @@ -3,8 +3,11 @@
|
| // found in the LICENSE file.
|
|
|
| #include "base/files/file_path.h"
|
| +#include "base/files/file_util.h"
|
| +#include "base/files/scoped_temp_dir.h"
|
| #include "base/strings/string_util.h"
|
| #include "base/strings/utf_string_conversions.h"
|
| +#include "base/threading/platform_thread.h"
|
| #include "build/build_config.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
| #include "tools/gn/filesystem_utils.h"
|
| @@ -554,6 +557,57 @@ TEST(FilesystemUtils, SourceDirForPath) {
|
| #endif
|
| }
|
|
|
| +TEST(FilesystemUtils, ContentsEqual) {
|
| + base::ScopedTempDir temp_dir;
|
| + ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
|
| +
|
| + std::string data = "foo";
|
| +
|
| + base::FilePath file_path = temp_dir.path().AppendASCII("foo.txt");
|
| + base::WriteFile(file_path, data.c_str(), static_cast<int>(data.size()));
|
| +
|
| + std::stringstream stream_1;
|
| + stream_1 << data;
|
| + EXPECT_TRUE(ContentsEqual(file_path, &stream_1));
|
| +
|
| + // Different length and contents.
|
| + stream_1 << "bar";
|
| + EXPECT_FALSE(ContentsEqual(file_path, &stream_1));
|
| +
|
| + // The same length, different contents.
|
| + std::stringstream stream_2("bar");
|
| + EXPECT_FALSE(ContentsEqual(file_path, &stream_2));
|
| +}
|
| +
|
| +TEST(FilesystemUtils, WriteFileIfChanged) {
|
| + base::ScopedTempDir temp_dir;
|
| + ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
|
| +
|
| + std::string data = "foo";
|
| + std::stringstream data_stream;
|
| + data_stream << data;
|
| +
|
| + // Write if file doesn't exist.
|
| + base::FilePath file_path = temp_dir.path().AppendASCII("foo.txt");
|
| + EXPECT_TRUE(WriteFileIfChanged(file_path, &data_stream));
|
| +
|
| + base::File::Info file_info;
|
| + ASSERT_TRUE(base::GetFileInfo(file_path, &file_info));
|
| + base::Time last_modified = file_info.last_modified;
|
| + base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(1));
|
| +
|
| + // Don't write if contents is the same.
|
| + EXPECT_TRUE(WriteFileIfChanged(file_path, &data_stream));
|
| + ASSERT_TRUE(base::GetFileInfo(file_path, &file_info));
|
| + EXPECT_EQ(last_modified, file_info.last_modified);
|
| +
|
| + // Write if contents changed.
|
| + data_stream << "bar";
|
| + EXPECT_TRUE(WriteFileIfChanged(file_path, &data_stream));
|
| + ASSERT_TRUE(base::GetFileInfo(file_path, &file_info));
|
| + EXPECT_NE(last_modified, file_info.last_modified);
|
| +}
|
| +
|
| TEST(FilesystemUtils, GetToolchainDirs) {
|
| BuildSettings build_settings;
|
| build_settings.SetBuildDir(SourceDir("//out/Debug/"));
|
|
|