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/strings/string_util.h" | 6 #include "base/strings/string_util.h" |
7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 #include "tools/gn/commands.h" | 8 #include "tools/gn/commands.h" |
9 | 9 |
10 namespace commands { | 10 namespace commands { |
11 bool FormatFileToString(const std::string& input_filename, | 11 bool FormatFileToString(const std::string& input_filename, |
12 bool dump_tree, | 12 bool dump_tree, |
13 std::string* output); | 13 std::string* output); |
14 } // namespace commands | 14 } // namespace commands |
15 | 15 |
16 #define FORMAT_TEST(n) \ | 16 #define FORMAT_TEST(n) \ |
17 TEST(Format, n) { \ | 17 TEST(Format, n) { \ |
18 std::string out; \ | 18 std::string out; \ |
19 std::string expected; \ | 19 std::string expected; \ |
20 EXPECT_TRUE(commands::FormatFileToString( \ | 20 EXPECT_TRUE(commands::FormatFileToString( \ |
21 "//tools/gn/format_test_data/" #n ".gn", false, &out)); \ | 21 "//tools/gn/format_test_data/" #n ".gn", false, &out)); \ |
22 ASSERT_TRUE(base::ReadFileToString( \ | 22 ASSERT_TRUE(base::ReadFileToString( \ |
23 base::FilePath(FILE_PATH_LITERAL("tools/gn/format_test_data/") \ | 23 base::FilePath(FILE_PATH_LITERAL("tools/gn/format_test_data/") \ |
24 FILE_PATH_LITERAL(#n) \ | 24 FILE_PATH_LITERAL(#n) \ |
25 FILE_PATH_LITERAL(".golden")), \ | 25 FILE_PATH_LITERAL(".golden")), \ |
26 &expected)); \ | 26 &expected)); \ |
27 EXPECT_EQ(out, expected); \ | 27 EXPECT_EQ(expected, out); \ |
28 } | 28 } |
29 | 29 |
30 // These are expanded out this way rather than a runtime loop so that | 30 // These are expanded out this way rather than a runtime loop so that |
31 // --gtest_filter works as expected for individual test running. | 31 // --gtest_filter works as expected for individual test running. |
32 FORMAT_TEST(001) | 32 FORMAT_TEST(001) |
33 FORMAT_TEST(002) | 33 FORMAT_TEST(002) |
34 FORMAT_TEST(003) | 34 FORMAT_TEST(003) |
35 FORMAT_TEST(004) | 35 FORMAT_TEST(004) |
36 FORMAT_TEST(005) | 36 FORMAT_TEST(005) |
37 FORMAT_TEST(006) | 37 FORMAT_TEST(006) |
38 FORMAT_TEST(007) | 38 FORMAT_TEST(007) |
39 FORMAT_TEST(008) | 39 FORMAT_TEST(008) |
40 FORMAT_TEST(009) | 40 FORMAT_TEST(009) |
41 FORMAT_TEST(010) | 41 FORMAT_TEST(010) |
42 FORMAT_TEST(011) | 42 FORMAT_TEST(011) |
43 FORMAT_TEST(012) | 43 FORMAT_TEST(012) |
44 FORMAT_TEST(013) | 44 FORMAT_TEST(013) |
45 FORMAT_TEST(014) | 45 FORMAT_TEST(014) |
| 46 FORMAT_TEST(015) |
| 47 // TODO(scottmg): Requires precedence/parentheses FORMAT_TEST(016) |
| 48 FORMAT_TEST(017) |
OLD | NEW |