blob: 21132c22f7c58fe4611e4ec76f3851291f5a487a [file] [log] [blame]
Damien Martin-Guillerezf88f4d82015-09-25 13:56:55 +00001// Copyright 2015 The Bazel Authors. All rights reserved.
Florian Weikert28da3652015-07-01 14:52:30 +00002//
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.
14package com.google.devtools.build.lib.testutil;
15
16import com.google.devtools.build.lib.events.EventHandler;
Laurent Le Brunbd9576a2016-11-18 15:10:51 +000017import com.google.devtools.build.lib.syntax.BazelLibrary;
Florian Weikert28da3652015-07-01 14:52:30 +000018import com.google.devtools.build.lib.syntax.Environment;
Francois-Rene Rideau89312fb2015-09-10 18:53:03 +000019import com.google.devtools.build.lib.syntax.Mutability;
Florian Weikert28da3652015-07-01 14:52:30 +000020
21/**
22 * Describes a particular testing mode by determining how the
Francois-Rene Rideau89312fb2015-09-10 18:53:03 +000023 * appropriate {@code Environment} has to be created
Florian Weikert28da3652015-07-01 14:52:30 +000024 */
25public abstract class TestMode {
Francois-Rene Rideau89312fb2015-09-10 18:53:03 +000026 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 Brunbd9576a2016-11-18 15:10:51 +000031 .setGlobals(environment == null ? BazelLibrary.GLOBALS : environment.getGlobals())
Francois-Rene Rideau89312fb2015-09-10 18:53:03 +000032 .setEventHandler(eventHandler)
33 .build();
34 }
35 };
Florian Weikert28da3652015-07-01 14:52:30 +000036
Francois-Rene Rideau89312fb2015-09-10 18:53:03 +000037 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 Brunbd9576a2016-11-18 15:10:51 +000042 .setGlobals(environment == null ? BazelLibrary.GLOBALS : environment.getGlobals())
Francois-Rene Rideau89312fb2015-09-10 18:53:03 +000043 .setEventHandler(eventHandler)
44 .build();
45 }
46 };
Florian Weikert28da3652015-07-01 14:52:30 +000047
Francois-Rene Rideau89312fb2015-09-10 18:53:03 +000048 public abstract Environment createEnvironment(EventHandler eventHandler, Environment environment);
49}