blob: 3a9b722623558a0d1e822377318607135437751d [file] [log] [blame]
Kristina Chodorowaa8b1522015-10-12 14:43:05 +00001// Copyright 2015 The Bazel Authors. All rights reserved.
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.
14package com.google.devtools.build.lib.runtime;
15
lberkiaea56b32017-05-30 12:35:33 +020016import static com.google.common.truth.Truth.assertThat;
pcloudybdbf6402019-02-28 08:27:36 -080017import static java.util.Collections.singletonMap;
Kristina Chodorowaa8b1522015-10-12 14:43:05 +000018
ishikhman16972192019-03-04 02:01:37 -080019import com.google.common.collect.ImmutableMap;
Kristina Chodorowaa8b1522015-10-12 14:43:05 +000020import com.google.devtools.build.lib.analysis.BlazeVersionInfo;
21import com.google.devtools.build.lib.util.StringUtilities;
pcloudybdbf6402019-02-28 08:27:36 -080022import java.util.Collections;
Kristina Chodorowaa8b1522015-10-12 14:43:05 +000023import java.util.HashMap;
24import java.util.Map;
25import java.util.TreeMap;
lberkiaea56b32017-05-30 12:35:33 +020026import org.junit.Test;
27import org.junit.runner.RunWith;
28import org.junit.runners.JUnit4;
Kristina Chodorowaa8b1522015-10-12 14:43:05 +000029
30/**
31 * Tests {@link BlazeVersionInfo}.
32 */
33@RunWith(JUnit4.class)
34public class BlazeVersionInfoTest {
35
36 @Test
37 public void testEmptyVersionInfoMeansNotAvailable() {
pcloudybdbf6402019-02-28 08:27:36 -080038 BlazeVersionInfo info = new BlazeVersionInfo(Collections.<String, String>emptyMap());
lberkiaea56b32017-05-30 12:35:33 +020039 assertThat(info.isAvailable()).isFalse();
40 assertThat(info.getSummary()).isNull();
41 assertThat(info.getReleaseName()).isEqualTo("development version");
Kristina Chodorowaa8b1522015-10-12 14:43:05 +000042 }
43
44 @Test
45 public void testReleaseNameIsDevelopmentIfBuildLabelIsNull() {
pcloudybdbf6402019-02-28 08:27:36 -080046 Map<String, String> data = singletonMap("Build label", "");
Kristina Chodorowaa8b1522015-10-12 14:43:05 +000047 BlazeVersionInfo info = new BlazeVersionInfo(data);
lberkiaea56b32017-05-30 12:35:33 +020048 assertThat(info.getReleaseName()).isEqualTo("development version");
Kristina Chodorowaa8b1522015-10-12 14:43:05 +000049 }
50
51 @Test
52 public void testReleaseNameIfBuildLabelIsPresent() {
pcloudybdbf6402019-02-28 08:27:36 -080053 Map<String, String> data = singletonMap("Build label", "3/4/2009 (gold)");
Kristina Chodorowaa8b1522015-10-12 14:43:05 +000054 BlazeVersionInfo info = new BlazeVersionInfo(data);
lberkiaea56b32017-05-30 12:35:33 +020055 assertThat(info.getReleaseName()).isEqualTo("release 3/4/2009 (gold)");
Kristina Chodorowaa8b1522015-10-12 14:43:05 +000056 }
57
58 @Test
59 public void testFancySummaryFormatting() {
60 Map<String, String> data = new HashMap<>();
61 data.put("Some entry", "foo");
62 data.put("Another entry", "bar");
63 data.put("And a third entry", "baz");
64 BlazeVersionInfo info = new BlazeVersionInfo(data);
65 Map<String, String> sortedData = new TreeMap<>(data);
lberkiaea56b32017-05-30 12:35:33 +020066 assertThat(info.getSummary()).isEqualTo(StringUtilities.layoutTable(sortedData));
Kristina Chodorowaa8b1522015-10-12 14:43:05 +000067 }
ishikhman16972192019-03-04 02:01:37 -080068
69 @Test
70 public void testVersionIsHeadIfBuildLabelIsNull() {
71 BlazeVersionInfo info = new BlazeVersionInfo(ImmutableMap.of());
72 assertThat(info.getVersion()).isEmpty();
73 }
74
75 @Test
76 public void testVersionsIIfBuildLabelIsPresent() {
77 Map<String, String> data = ImmutableMap.of("Build label", "123.4");
78 BlazeVersionInfo info = new BlazeVersionInfo(data);
79 assertThat(info.getVersion()).isEqualTo("123.4");
80 }
Kristina Chodorowaa8b1522015-10-12 14:43:05 +000081}