Skip to content

Commit

Permalink
Make running gn format unittests from anywhere work
Browse files Browse the repository at this point in the history
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}
  • Loading branch information
sgraham authored and Commit bot committed Dec 19, 2014
1 parent ec844e4 commit 7f1ee75
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions tools/gn/command_format_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down

0 comments on commit 7f1ee75

Please sign in to comment.