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_util.h" | 5 #include "base/files/file_util.h" |
6 #include "base/path_service.h" | |
6 #include "base/strings/string_util.h" | 7 #include "base/strings/string_util.h" |
7 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
8 #include "tools/gn/commands.h" | 9 #include "tools/gn/commands.h" |
9 #include "tools/gn/setup.h" | 10 #include "tools/gn/setup.h" |
10 | 11 |
11 namespace commands { | 12 namespace commands { |
12 bool FormatFileToString(Setup* setup, | 13 bool FormatFileToString(Setup* setup, |
13 const SourceFile& file, | 14 const SourceFile& file, |
14 bool dump_tree, | 15 bool dump_tree, |
15 std::string* output); | 16 std::string* output); |
16 } // namespace commands | 17 } // namespace commands |
17 | 18 |
18 #define FORMAT_TEST(n) \ | 19 #define FORMAT_TEST(n) \ |
19 TEST(Format, n) { \ | 20 TEST(Format, n) { \ |
20 ::Setup setup; \ | 21 ::Setup setup; \ |
21 std::string out; \ | 22 std::string out; \ |
22 std::string expected; \ | 23 std::string expected; \ |
23 EXPECT_TRUE(commands::FormatFileToString( \ | 24 base::FilePath exe; \ |
24 &setup, \ | 25 PathService::Get(base::FILE_EXE, &exe); \ |
Dirk Pranke
2014/12/19 18:24:39
Can you use PathService::Get(base::DIR_SOURCE_ROOT
tfarina
2014/12/19 18:29:04
+1 for that. I found DIR_SOURCE_ROOT easier to und
scottmg
2014/12/19 18:31:45
Ah, indeed. Done.
(Sadly, it's doing the same thi
| |
25 SourceFile("//tools/gn/format_test_data/" #n ".gn"), \ | 26 base::FilePath src_dir = exe.DirName().DirName().DirName(); \ |
26 false, \ | 27 base::SetCurrentDirectory(src_dir); \ |
27 &out)); \ | 28 EXPECT_TRUE(commands::FormatFileToString( \ |
28 ASSERT_TRUE(base::ReadFileToString( \ | 29 &setup, SourceFile("//tools/gn/format_test_data/" #n ".gn"), false, \ |
29 base::FilePath(FILE_PATH_LITERAL("tools/gn/format_test_data/") \ | 30 &out)); \ |
30 FILE_PATH_LITERAL(#n) \ | 31 ASSERT_TRUE(base::ReadFileToString( \ |
31 FILE_PATH_LITERAL(".golden")), \ | 32 base::FilePath(FILE_PATH_LITERAL("tools/gn/format_test_data/") \ |
32 &expected)); \ | 33 FILE_PATH_LITERAL(#n) \ |
33 EXPECT_EQ(expected, out); \ | 34 FILE_PATH_LITERAL(".golden")), \ |
35 &expected)); \ | |
36 EXPECT_EQ(expected, out); \ | |
34 } | 37 } |
35 | 38 |
36 // These are expanded out this way rather than a runtime loop so that | 39 // These are expanded out this way rather than a runtime loop so that |
37 // --gtest_filter works as expected for individual test running. | 40 // --gtest_filter works as expected for individual test running. |
38 FORMAT_TEST(001) | 41 FORMAT_TEST(001) |
39 FORMAT_TEST(002) | 42 FORMAT_TEST(002) |
40 FORMAT_TEST(003) | 43 FORMAT_TEST(003) |
41 FORMAT_TEST(004) | 44 FORMAT_TEST(004) |
42 FORMAT_TEST(005) | 45 FORMAT_TEST(005) |
43 FORMAT_TEST(006) | 46 FORMAT_TEST(006) |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
90 FORMAT_TEST(052) | 93 FORMAT_TEST(052) |
91 FORMAT_TEST(053) | 94 FORMAT_TEST(053) |
92 FORMAT_TEST(054) | 95 FORMAT_TEST(054) |
93 FORMAT_TEST(055) | 96 FORMAT_TEST(055) |
94 FORMAT_TEST(056) | 97 FORMAT_TEST(056) |
95 FORMAT_TEST(057) | 98 FORMAT_TEST(057) |
96 FORMAT_TEST(058) | 99 FORMAT_TEST(058) |
97 FORMAT_TEST(059) | 100 FORMAT_TEST(059) |
98 FORMAT_TEST(060) | 101 FORMAT_TEST(060) |
99 FORMAT_TEST(061) | 102 FORMAT_TEST(061) |
OLD | NEW |