• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2021 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.
14
15package no_srcs
16
17import (
18	"bytes"
19	"os"
20	"strings"
21	"testing"
22
23	"github.com/bazelbuild/rules_go/go/tools/bazel_testing"
24)
25
26func TestMain(m *testing.M) {
27	bazel_testing.TestMain(m, bazel_testing.Args{
28		Main: `
29-- BUILD.bazel --
30load("@io_bazel_rules_go//go:def.bzl", "go_library")
31
32[
33    go_library(
34        name = "lib_" + str(i),
35        srcs = [],
36        importpath = "example.com/some/path",
37    )
38    for i in range(1000)
39]
40`,
41	})
42}
43
44func Test(t *testing.T) {
45	commonArgs := []string{
46		"--spawn_strategy=local",
47		"--compilation_mode=dbg",
48	}
49
50	if err := bazel_testing.RunBazel(append([]string{"build", "//..."}, commonArgs...)...); err != nil {
51		t.Fatal(err)
52	}
53
54	out, err := bazel_testing.BazelOutput(append([]string{"cquery", "--output=files", "//..."}, commonArgs...)...)
55	if err != nil {
56		t.Fatal(err)
57	}
58	archives := strings.Split(strings.TrimSpace(string(out)), "\n")
59
60	if len(archives) != 1000 {
61		t.Fatalf("expected 1000 archives, got %d", len(archives))
62	}
63
64	referenceContent, err := os.ReadFile(archives[0])
65	if err != nil {
66		t.Fatal(err)
67	}
68
69	for _, archive := range archives {
70		content, err := os.ReadFile(archive)
71		if err != nil {
72			t.Fatal(err)
73		}
74		if !bytes.Equal(content, referenceContent) {
75			t.Fatalf("expected all archives to be identical, got:\n\n%s\n\n%s\n", string(content), string(referenceContent))
76		}
77	}
78}
79