From 7f1ee75851d2a0f19ce8fe993cd7e9e1ccfebf4e Mon Sep 17 00:00:00 2001 From: scottmg Date: Fri, 19 Dec 2014 14:11:18 -0800 Subject: 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} --- tools/gn/command_format_unittest.cc | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) (limited to 'tools/gn/command_format_unittest.cc') 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 -- cgit v1.1