OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/files/file.h" | 5 #include "base/files/file.h" |
6 #include "base/files/file_util.h" | 6 #include "base/files/file_util.h" |
7 #include "base/files/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 #include "tools/gn/functions.h" | 9 #include "tools/gn/functions.h" |
| 10 #include "tools/gn/scheduler.h" |
10 #include "tools/gn/test_with_scope.h" | 11 #include "tools/gn/test_with_scope.h" |
11 | 12 |
12 namespace { | 13 namespace { |
13 | 14 |
14 // Returns true on success, false if write_file signaled an error. | 15 // Returns true on success, false if write_file signaled an error. |
15 bool CallWriteFile(Scope* scope, | 16 bool CallWriteFile(Scope* scope, |
16 const std::string& filename, | 17 const std::string& filename, |
17 const Value& data) { | 18 const Value& data) { |
18 Err err; | 19 Err err; |
19 | 20 |
20 std::vector<Value> args; | 21 std::vector<Value> args; |
21 args.push_back(Value(nullptr, filename)); | 22 args.push_back(Value(nullptr, filename)); |
22 args.push_back(data); | 23 args.push_back(data); |
23 | 24 |
24 FunctionCallNode function_call; | 25 FunctionCallNode function_call; |
25 Value result = functions::RunWriteFile(scope, &function_call, args, &err); | 26 Value result = functions::RunWriteFile(scope, &function_call, args, &err); |
26 EXPECT_EQ(Value::NONE, result.type()); // Should always return none. | 27 EXPECT_EQ(Value::NONE, result.type()); // Should always return none. |
27 | 28 |
28 return !err.has_error(); | 29 return !err.has_error(); |
29 } | 30 } |
30 | 31 |
31 } // namespace | 32 } // namespace |
32 | 33 |
33 TEST(WriteFile, WithData) { | 34 TEST(WriteFile, WithData) { |
| 35 Scheduler scheduler; |
34 TestWithScope setup; | 36 TestWithScope setup; |
35 | 37 |
36 // Make a real directory for writing the files. | 38 // Make a real directory for writing the files. |
37 base::ScopedTempDir temp_dir; | 39 base::ScopedTempDir temp_dir; |
38 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 40 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
39 setup.build_settings()->SetRootPath(temp_dir.path()); | 41 setup.build_settings()->SetRootPath(temp_dir.path()); |
40 setup.build_settings()->SetBuildDir(SourceDir("//out/")); | 42 setup.build_settings()->SetBuildDir(SourceDir("//out/")); |
41 | 43 |
42 Value some_string(nullptr, "some string contents"); | 44 Value some_string(nullptr, "some string contents"); |
43 | 45 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 base::File::Info original_info; | 79 base::File::Info original_info; |
78 foo_file.GetInfo(&original_info); | 80 foo_file.GetInfo(&original_info); |
79 | 81 |
80 EXPECT_TRUE(CallWriteFile(setup.scope(), "//out/foo.txt", some_list)); | 82 EXPECT_TRUE(CallWriteFile(setup.scope(), "//out/foo.txt", some_list)); |
81 | 83 |
82 // Verify that the last modified time is the same as before. | 84 // Verify that the last modified time is the same as before. |
83 base::File::Info new_info; | 85 base::File::Info new_info; |
84 foo_file.GetInfo(&new_info); | 86 foo_file.GetInfo(&new_info); |
85 EXPECT_EQ(original_info.last_modified, new_info.last_modified); | 87 EXPECT_EQ(original_info.last_modified, new_info.last_modified); |
86 } | 88 } |
OLD | NEW |