diff options
author | Googler <noreply@google.com> | 2018-07-16 08:48:39 -0700 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-07-16 08:50:01 -0700 |
commit | 7e703eca32b834edc677a926c2d440e49ffdadc2 (patch) | |
tree | 743caca03845e3b68f61ecc7632bcb0ed6912072 /src/test/java/com/google/devtools/build/lib/bazel | |
parent | d69b1c752587149269e9b0d1e7563bc5eb66be6a (diff) |
Second cl for verbose workspaces (ability to log certain potentially non-hermetic events that happen as part of repository rules).
Defining representation for Execute events for workspace logging.
In the future:
- Add more events
- Allowing to specify log file rather than dumping to INFO
- Log levels, full or alerts only
RELNOTES: None
PiperOrigin-RevId: 204748436
Diffstat (limited to 'src/test/java/com/google/devtools/build/lib/bazel')
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/bazel/debug/BUILD | 27 | ||||
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/bazel/debug/WorkspaceRuleEventTest.java | 101 |
2 files changed, 128 insertions, 0 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/bazel/debug/BUILD b/src/test/java/com/google/devtools/build/lib/bazel/debug/BUILD new file mode 100644 index 0000000000..b6623e611e --- /dev/null +++ b/src/test/java/com/google/devtools/build/lib/bazel/debug/BUILD @@ -0,0 +1,27 @@ +package( + default_testonly = 1, + default_visibility = ["//src:__subpackages__"], +) + +filegroup( + name = "srcs", + testonly = 0, + srcs = glob(["**"]), + visibility = ["//src/test/java/com/google/devtools/build/lib:__pkg__"], +) + +java_test( + name = "WorkspaceRuleEventTest", + size = "small", + srcs = ["WorkspaceRuleEventTest.java"], + deps = [ + "//src/main/java/com/google/devtools/build/lib:events", + "//src/main/java/com/google/devtools/build/lib/bazel/debug:workspace-rule-event", + "//src/main/java/com/google/devtools/build/lib/bazel/debug:workspace_log_java_proto", + "//src/main/java/com/google/devtools/build/lib/vfs:pathfragment", + "//third_party:guava", + "//third_party:junit4", + "//third_party:mockito", + "//third_party:truth", + ], +) diff --git a/src/test/java/com/google/devtools/build/lib/bazel/debug/WorkspaceRuleEventTest.java b/src/test/java/com/google/devtools/build/lib/bazel/debug/WorkspaceRuleEventTest.java new file mode 100644 index 0000000000..e13de8af9b --- /dev/null +++ b/src/test/java/com/google/devtools/build/lib/bazel/debug/WorkspaceRuleEventTest.java @@ -0,0 +1,101 @@ +// Copyright 2018 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License + +package com.google.devtools.build.lib.bazel.debug; + +import static com.google.common.truth.Truth.assertThat; + +import com.google.common.collect.ImmutableMap; +import com.google.devtools.build.lib.bazel.debug.proto.WorkspaceLogProtos; +import com.google.devtools.build.lib.events.Location; +import com.google.devtools.build.lib.vfs.PathFragment; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +/** Tests handling of WorkspaceRuleEvent */ +@RunWith(JUnit4.class) +public final class WorkspaceRuleEventTest { + static class DummyString { + @Override + public String toString() { + return "dummy string"; + } + } + + static class DummyLocation extends Location { + public DummyLocation() { + super(10, 20); + }; + + @Override + public PathFragment getPath() { + return null; + } + + @Override + public String print() { + return "location being printed"; + } + } + + @Before + public void setUp() {} + + @Test + public void newExecuteEvent_expectedResult() { + // Set up arguments, as a combination of String and SkylarkPath + ArrayList<Object> arguments = new ArrayList<>(); + arguments.add("argument 1"); + arguments.add(new DummyString()); + + Map<String, String> commonEnv = ImmutableMap.of("key1", "val1", "key3", "val3"); + Map<String, String> customEnv = ImmutableMap.of("key2", "val2!", "key3", "val3!"); + + WorkspaceLogProtos.WorkspaceEvent event = + WorkspaceRuleEvent.newExecuteEvent( + arguments, + 2042, + commonEnv, + customEnv, + "outputDir", + true, + "my_rule", + new DummyLocation()) + .getLogEvent(); + + List<String> expectedArgs = Arrays.asList("argument 1", "dummy string"); + + Map<String, String> expectedEnv = + ImmutableMap.of( + "key1", "val1", + "key2", "val2!", + "key3", "val3!"); + + assertThat(event.getRule()).isEqualTo("my_rule"); + assertThat(event.getLocation()).isEqualTo("location being printed"); + + WorkspaceLogProtos.ExecuteEvent executeEvent = event.getExecuteEvent(); + assertThat(executeEvent.getTimeoutSeconds()).isEqualTo(2042); + assertThat(executeEvent.getQuiet()).isEqualTo(true); + assertThat(executeEvent.getOutputDirectory()).isEqualTo("outputDir"); + assertThat(executeEvent.getArgumentsList()).isEqualTo(expectedArgs); + assertThat(executeEvent.getEnvironmentMap()).isEqualTo(expectedEnv); + } +} |