diff options
author | scottmg <scottmg@chromium.org> | 2014-12-19 14:11:18 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-12-19 22:12:12 +0000 |
commit | 7f1ee75851d2a0f19ce8fe993cd7e9e1ccfebf4e (patch) | |
tree | 1348ff53548721e4d59cb61dac6016743c3fd9b6 /tools/gn/command_format_unittest.cc | |
parent | ec844e47e2290c86e95a69471c10e89280484146 (diff) | |
download | chromium_src-7f1ee75851d2a0f19ce8fe993cd7e9e1ccfebf4e.zip chromium_src-7f1ee75851d2a0f19ce8fe993cd7e9e1ccfebf4e.tar.gz chromium_src-7f1ee75851d2a0f19ce8fe993cd7e9e1ccfebf4e.tar.bz2 |
Make running gn format unittests from anywhere work
This "works" but has two drawbacks:
- Relies on a 2-deep output directory which is true for gyp, but not
necessarily for gn (though I'm pretty sure other things are broken
for that case too).
- calls SetCurrentDirectory which is kind of icky. At first I tried setting
an absolute path for loading the .golden file which was OK, but then
it got messy to create the //gn path.
R=dpranke@chromium.org
BUG=443813
Review URL: https://codereview.chromium.org/818623002
Cr-Commit-Position: refs/heads/master@{#309277}
Diffstat (limited to 'tools/gn/command_format_unittest.cc')
-rw-r--r-- | tools/gn/command_format_unittest.cc | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/tools/gn/command_format_unittest.cc b/tools/gn/command_format_unittest.cc index 1b1c08e..d70e5a5 100644 --- a/tools/gn/command_format_unittest.cc +++ b/tools/gn/command_format_unittest.cc @@ -3,6 +3,7 @@ // found in the LICENSE file. #include "base/files/file_util.h" +#include "base/path_service.h" #include "base/strings/string_util.h" #include "testing/gtest/include/gtest/gtest.h" #include "tools/gn/commands.h" @@ -15,22 +16,23 @@ bool FormatFileToString(Setup* setup, std::string* output); } // namespace commands -#define FORMAT_TEST(n) \ - TEST(Format, n) { \ - ::Setup setup; \ - std::string out; \ - std::string expected; \ - EXPECT_TRUE(commands::FormatFileToString( \ - &setup, \ - SourceFile("//tools/gn/format_test_data/" #n ".gn"), \ - false, \ - &out)); \ - ASSERT_TRUE(base::ReadFileToString( \ - base::FilePath(FILE_PATH_LITERAL("tools/gn/format_test_data/") \ - FILE_PATH_LITERAL(#n) \ - FILE_PATH_LITERAL(".golden")), \ - &expected)); \ - EXPECT_EQ(expected, out); \ +#define FORMAT_TEST(n) \ + TEST(Format, n) { \ + ::Setup setup; \ + std::string out; \ + std::string expected; \ + base::FilePath src_dir; \ + PathService::Get(base::DIR_SOURCE_ROOT, &src_dir); \ + base::SetCurrentDirectory(src_dir); \ + EXPECT_TRUE(commands::FormatFileToString( \ + &setup, SourceFile("//tools/gn/format_test_data/" #n ".gn"), false, \ + &out)); \ + ASSERT_TRUE(base::ReadFileToString( \ + base::FilePath(FILE_PATH_LITERAL("tools/gn/format_test_data/") \ + FILE_PATH_LITERAL(#n) \ + FILE_PATH_LITERAL(".golden")), \ + &expected)); \ + EXPECT_EQ(expected, out); \ } // These are expanded out this way rather than a runtime loop so that |