• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "gn/scope_per_file_provider.h"
6 #include "gn/build_settings.h"
7 #include "gn/settings.h"
8 #include "gn/test_with_scope.h"
9 #include "gn/toolchain.h"
10 #include "gn/variables.h"
11 #include "util/test/test.h"
12 
TEST(ScopePerFileProvider,Expected)13 TEST(ScopePerFileProvider, Expected) {
14   TestWithScope test;
15 
16 // Prevent horrible wrapping of calls below.
17 #define GPV(val) provider.GetProgrammaticValue(val)->string_value()
18 
19   // Test the default toolchain.
20   {
21     Scope scope(test.settings());
22     scope.set_source_dir(SourceDir("//source/"));
23     ScopePerFileProvider provider(&scope, true);
24 
25     EXPECT_EQ("//toolchain:default", GPV(variables::kCurrentToolchain));
26     // TODO(brettw) this test harness does not set up the Toolchain manager
27     // which is the source of this value, so we can't test this yet.
28     // EXPECT_EQ("//toolchain:default",    GPV(variables::kDefaultToolchain));
29     EXPECT_EQ("//out/Debug", GPV(variables::kRootBuildDir));
30     EXPECT_EQ("//out/Debug/gen", GPV(variables::kRootGenDir));
31     EXPECT_EQ("//out/Debug", GPV(variables::kRootOutDir));
32     EXPECT_EQ("//out/Debug/gen/source", GPV(variables::kTargetGenDir));
33     EXPECT_EQ("//out/Debug/obj/source", GPV(variables::kTargetOutDir));
34 
35     EXPECT_GE(provider.GetProgrammaticValue(variables::kGnVersion)->int_value(),
36               0);
37   }
38 
39   // Test some with an alternate toolchain.
40   {
41     Settings settings(test.build_settings(), "tc/");
42     Toolchain toolchain(&settings, Label(SourceDir("//toolchain/"), "tc"));
43     settings.set_toolchain_label(toolchain.label());
44 
45     Scope scope(&settings);
46     scope.set_source_dir(SourceDir("//source/"));
47     ScopePerFileProvider provider(&scope, true);
48 
49     EXPECT_EQ("//toolchain:tc", GPV(variables::kCurrentToolchain));
50     // See above.
51     // EXPECT_EQ("//toolchain:default", GPV(variables::kDefaultToolchain));
52     EXPECT_EQ("//out/Debug", GPV(variables::kRootBuildDir));
53     EXPECT_EQ("//out/Debug/tc/gen", GPV(variables::kRootGenDir));
54     EXPECT_EQ("//out/Debug/tc", GPV(variables::kRootOutDir));
55     EXPECT_EQ("//out/Debug/tc/gen/source", GPV(variables::kTargetGenDir));
56     EXPECT_EQ("//out/Debug/tc/obj/source", GPV(variables::kTargetOutDir));
57   }
58 }
59