aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/BUILD105
-rw-r--r--tests/Bar.java25
-rw-r--r--tests/Hello.java26
-rw-r--r--tests/LICENSE6
-rw-r--r--tests/LICENSE.extra5
-rw-r--r--tests/bar.cc19
-rw-r--r--tests/hello.cc21
-rwxr-xr-xtests/hello_cc_copyrights.golden1
-rwxr-xr-xtests/hello_java_copyrights.golden2
9 files changed, 210 insertions, 0 deletions
diff --git a/tests/BUILD b/tests/BUILD
new file mode 100644
index 0000000..8bfdb19
--- /dev/null
+++ b/tests/BUILD
@@ -0,0 +1,105 @@
+# Test cases for license rules.
+
+load("@rules_license//rules:compliance.bzl", "check_license")
+load("@rules_license//rules:license.bzl", "license")
+load("@rules_license//rules:license_kind.bzl", "license_kind")
+load("@rules_license//tools:test_helpers.bzl", "golden_test")
+
+package(default_applicable_licenses = [":license"])
+
+# license_kind rules generally appear in a central location per workspace. They
+# are intermingled with normal target build rules
+license_kind(
+ name = "generic_notice_license",
+ conditions = [
+ "notice",
+ ],
+)
+
+license_kind(
+ name = "generic_restricted_license",
+ conditions = [
+ "restricted",
+ ],
+)
+
+# The default license for an entire package is typically named "license".
+license(
+ name = "license",
+ package_name = "A test case package",
+ # Note the UTF-8 encoded copyright symbol.
+ copyright_notice = "Copyright © 2019 Uncle Toasty",
+ license_kinds = [":generic_notice_license"],
+)
+
+license(
+ name = "license_for_extra_feature",
+ package_name = "A test case package",
+ license = "LICENSE.extra",
+ license_kinds = [":generic_restricted_license"],
+)
+
+cc_binary(
+ name = "hello",
+ srcs = ["hello.cc"],
+ deps = [
+ ":c_bar",
+ ],
+)
+
+cc_library(
+ name = "c_bar",
+ srcs = ["bar.cc"],
+)
+
+java_binary(
+ name = "hello_java",
+ srcs = ["Hello.java"],
+ # Add an addition license to this target, beyond what my deps have.
+ applicable_licenses = [
+ ":license_for_extra_feature",
+ ],
+ main_class = "Hello",
+ deps = [
+ ":j_bar",
+ ],
+)
+
+java_library(
+ name = "j_bar",
+ srcs = ["Bar.java"],
+)
+
+check_license(
+ name = "check_cc_app",
+ check_conditions = False,
+ copyright_notices = "hello_cc_copyrights.txt",
+ license_texts = "hello_cc_licenses.txt",
+ report = "hello_cc_report",
+ deps = [
+ ":hello",
+ ],
+)
+
+check_license(
+ name = "check_java_app",
+ check_conditions = False,
+ copyright_notices = "hello_java_copyrights.txt",
+ license_texts = "hello_java_licenses.txt",
+ report = "hello_java_report",
+ deps = [
+ ":hello_java",
+ ],
+)
+
+golden_test(
+ name = "verify_cc_app_test",
+ golden = "hello_cc_copyrights.golden",
+ subject = ":hello_cc_copyrights.txt",
+)
+
+golden_test(
+ name = "verify_java_app_test",
+ golden = "hello_java_copyrights.golden",
+ subject = ":hello_java_copyrights.txt",
+)
diff --git a/tests/Bar.java b/tests/Bar.java
new file mode 100644
index 0000000..fd57c7d
--- /dev/null
+++ b/tests/Bar.java
@@ -0,0 +1,25 @@
+// Copyright 2020 Google LLC
+//
+// 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
+//
+// https://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.
+
+/**
+ *
+ */
+final class Bar {
+
+ static final int PI = 3;
+
+ private Bar() {
+ }
+
+}
diff --git a/tests/Hello.java b/tests/Hello.java
new file mode 100644
index 0000000..b4a1037
--- /dev/null
+++ b/tests/Hello.java
@@ -0,0 +1,26 @@
+// Copyright 2020 Google LLC
+//
+// 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
+//
+// https://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.
+
+/**
+ *
+ */
+final class Hello {
+
+ private Hello() {
+ }
+
+ public static int main(String[] args) {
+ return Bar.PI;
+ }
+}
diff --git a/tests/LICENSE b/tests/LICENSE
new file mode 100644
index 0000000..bc6bc98
--- /dev/null
+++ b/tests/LICENSE
@@ -0,0 +1,6 @@
+Copyright © 2019 Uncle Toasty
+
+Example of a notice style license.
+
+You may use this software in any way as long as you include the copyright
+notice above.
diff --git a/tests/LICENSE.extra b/tests/LICENSE.extra
new file mode 100644
index 0000000..fbcdbbb
--- /dev/null
+++ b/tests/LICENSE.extra
@@ -0,0 +1,5 @@
+Copyright (c) 2020 The authors of this software
+
+A license for an extra feature to a package.
+For example, you might have most of the package with a notice license,
+but an additional feature is added under a restricted license.
diff --git a/tests/bar.cc b/tests/bar.cc
new file mode 100644
index 0000000..1cd1214
--- /dev/null
+++ b/tests/bar.cc
@@ -0,0 +1,19 @@
+// Copyright 2020 Google LLC
+//
+// 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
+//
+// https://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.
+
+
+
+int bar() {
+ return 42;
+}
diff --git a/tests/hello.cc b/tests/hello.cc
new file mode 100644
index 0000000..8833791
--- /dev/null
+++ b/tests/hello.cc
@@ -0,0 +1,21 @@
+// Copyright 2020 Google LLC
+//
+// 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
+//
+// https://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.
+
+
+#include <iostream>
+
+int main(int argc, char* argv[]) {
+ std::cout << "Hello foo." << std::endl;
+ return 0;
+}
diff --git a/tests/hello_cc_copyrights.golden b/tests/hello_cc_copyrights.golden
new file mode 100755
index 0000000..8dc3985
--- /dev/null
+++ b/tests/hello_cc_copyrights.golden
@@ -0,0 +1 @@
+package(A test case package), copyright(Copyright © 2019 Uncle Toasty)
diff --git a/tests/hello_java_copyrights.golden b/tests/hello_java_copyrights.golden
new file mode 100755
index 0000000..9df37e5
--- /dev/null
+++ b/tests/hello_java_copyrights.golden
@@ -0,0 +1,2 @@
+package(A test case package), copyright(Copyright © 2019 Uncle Toasty)
+package(A test case package), copyright()