2020-11-26 01:06:39 +01:00
|
|
|
// Copyright 2020 Google Inc. 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 bp2build
|
|
|
|
|
|
|
|
import (
|
|
|
|
"sort"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2021-04-16 13:47:36 +02:00
|
|
|
type bazelFilepath struct {
|
2020-12-14 14:25:34 +01:00
|
|
|
dir string
|
|
|
|
basename string
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCreateBazelFiles_QueryView_AddsTopLevelFiles(t *testing.T) {
|
2023-08-04 22:52:14 +02:00
|
|
|
files := CreateBazelFiles(map[string]RuleShim{}, map[string]BazelTargets{}, QueryView)
|
2021-04-16 13:47:36 +02:00
|
|
|
expectedFilePaths := []bazelFilepath{
|
2020-11-26 01:06:39 +01:00
|
|
|
{
|
|
|
|
dir: "",
|
2021-05-18 13:47:15 +02:00
|
|
|
basename: "BUILD.bazel",
|
2020-11-26 01:06:39 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
dir: "",
|
|
|
|
basename: "WORKSPACE",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
dir: bazelRulesSubDir,
|
2021-05-18 13:47:15 +02:00
|
|
|
basename: "BUILD.bazel",
|
2020-11-26 01:06:39 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
dir: bazelRulesSubDir,
|
|
|
|
basename: "providers.bzl",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
dir: bazelRulesSubDir,
|
|
|
|
basename: "soong_module.bzl",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2021-04-01 09:11:11 +02:00
|
|
|
// Compare number of files
|
|
|
|
if a, e := len(files), len(expectedFilePaths); a != e {
|
|
|
|
t.Errorf("Expected %d files, got %d", e, a)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sort the files to be deterministic
|
|
|
|
sort.Slice(files, func(i, j int) bool {
|
|
|
|
if dir1, dir2 := files[i].Dir, files[j].Dir; dir1 == dir2 {
|
|
|
|
return files[i].Basename < files[j].Basename
|
|
|
|
} else {
|
|
|
|
return dir1 < dir2
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
// Compare the file contents
|
|
|
|
for i := range files {
|
|
|
|
actualFile, expectedFile := files[i], expectedFilePaths[i]
|
|
|
|
|
|
|
|
if actualFile.Dir != expectedFile.dir || actualFile.Basename != expectedFile.basename {
|
|
|
|
t.Errorf("Did not find expected file %s/%s", actualFile.Dir, actualFile.Basename)
|
2021-05-18 13:47:15 +02:00
|
|
|
} else if actualFile.Basename == "BUILD.bazel" || actualFile.Basename == "WORKSPACE" {
|
2021-04-01 09:11:11 +02:00
|
|
|
if actualFile.Contents != "" {
|
|
|
|
t.Errorf("Expected %s to have no content.", actualFile)
|
|
|
|
}
|
|
|
|
} else if actualFile.Contents == "" {
|
|
|
|
t.Errorf("Contents of %s unexpected empty.", actualFile)
|
|
|
|
}
|
|
|
|
}
|
2020-12-14 14:25:34 +01:00
|
|
|
}
|