Damien Martin-Guillerez | f88f4d8 | 2015-09-25 13:56:55 +0000 | [diff] [blame] | 1 | // Copyright 2015 The Bazel Authors. All rights reserved. |
Florian Weikert | 28da365 | 2015-07-01 14:52:30 +0000 | [diff] [blame] | 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | package com.google.devtools.build.lib.testutil; |
| 15 | |
| 16 | import com.google.devtools.build.lib.events.EventHandler; |
Laurent Le Brun | bd9576a | 2016-11-18 15:10:51 +0000 | [diff] [blame] | 17 | import com.google.devtools.build.lib.syntax.BazelLibrary; |
Florian Weikert | 28da365 | 2015-07-01 14:52:30 +0000 | [diff] [blame] | 18 | import com.google.devtools.build.lib.syntax.Environment; |
Francois-Rene Rideau | 89312fb | 2015-09-10 18:53:03 +0000 | [diff] [blame] | 19 | import com.google.devtools.build.lib.syntax.Mutability; |
Florian Weikert | 28da365 | 2015-07-01 14:52:30 +0000 | [diff] [blame] | 20 | |
| 21 | /** |
| 22 | * Describes a particular testing mode by determining how the |
Francois-Rene Rideau | 89312fb | 2015-09-10 18:53:03 +0000 | [diff] [blame] | 23 | * appropriate {@code Environment} has to be created |
Florian Weikert | 28da365 | 2015-07-01 14:52:30 +0000 | [diff] [blame] | 24 | */ |
| 25 | public abstract class TestMode { |
Francois-Rene Rideau | 89312fb | 2015-09-10 18:53:03 +0000 | [diff] [blame] | 26 | public static final TestMode BUILD = |
| 27 | new TestMode() { |
| 28 | @Override |
| 29 | public Environment createEnvironment(EventHandler eventHandler, Environment environment) { |
| 30 | return Environment.builder(Mutability.create("build test")) |
Laurent Le Brun | bd9576a | 2016-11-18 15:10:51 +0000 | [diff] [blame] | 31 | .setGlobals(environment == null ? BazelLibrary.GLOBALS : environment.getGlobals()) |
Francois-Rene Rideau | 89312fb | 2015-09-10 18:53:03 +0000 | [diff] [blame] | 32 | .setEventHandler(eventHandler) |
| 33 | .build(); |
| 34 | } |
| 35 | }; |
Florian Weikert | 28da365 | 2015-07-01 14:52:30 +0000 | [diff] [blame] | 36 | |
Francois-Rene Rideau | 89312fb | 2015-09-10 18:53:03 +0000 | [diff] [blame] | 37 | public static final TestMode SKYLARK = |
| 38 | new TestMode() { |
| 39 | @Override |
| 40 | public Environment createEnvironment(EventHandler eventHandler, Environment environment) { |
| 41 | return Environment.builder(Mutability.create("skylark test")) |
Laurent Le Brun | bd9576a | 2016-11-18 15:10:51 +0000 | [diff] [blame] | 42 | .setGlobals(environment == null ? BazelLibrary.GLOBALS : environment.getGlobals()) |
Francois-Rene Rideau | 89312fb | 2015-09-10 18:53:03 +0000 | [diff] [blame] | 43 | .setEventHandler(eventHandler) |
| 44 | .build(); |
| 45 | } |
| 46 | }; |
Florian Weikert | 28da365 | 2015-07-01 14:52:30 +0000 | [diff] [blame] | 47 | |
Francois-Rene Rideau | 89312fb | 2015-09-10 18:53:03 +0000 | [diff] [blame] | 48 | public abstract Environment createEnvironment(EventHandler eventHandler, Environment environment); |
| 49 | } |