xref: /aosp_15_r20/external/stardoc/update-stardoc-tests.sh (revision b2fa42943c124aa9c7163734493fc7a7559681cf)
1*b2fa4294SXin Li#!/usr/bin/env bash
2*b2fa4294SXin Li# Copyright 2019 The Bazel Authors. All rights reserved.
3*b2fa4294SXin Li#
4*b2fa4294SXin Li# Licensed under the Apache License, Version 2.0 (the "License");
5*b2fa4294SXin Li# you may not use this file except in compliance with the License.
6*b2fa4294SXin Li# You may obtain a copy of the License at
7*b2fa4294SXin Li#
8*b2fa4294SXin Li#    http://www.apache.org/licenses/LICENSE-2.0
9*b2fa4294SXin Li#
10*b2fa4294SXin Li# Unless required by applicable law or agreed to in writing, software
11*b2fa4294SXin Li# distributed under the License is distributed on an "AS IS" BASIS,
12*b2fa4294SXin Li# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*b2fa4294SXin Li# See the License for the specific language governing permissions and
14*b2fa4294SXin Li# limitations under the License.
15*b2fa4294SXin Li#
16*b2fa4294SXin Li# Renerates most Stardoc golden files for Stardoc golden tests.
17*b2fa4294SXin Li#
18*b2fa4294SXin Li# When run, every golden file which is changed as a result of this script should
19*b2fa4294SXin Li# be manually examined and *heavily* scrutinized, as this usually indicates a large
20*b2fa4294SXin Li# in-place change of core rendering functionality of Stardoc.
21*b2fa4294SXin Li
22*b2fa4294SXin Liset -eu
23*b2fa4294SXin Li
24*b2fa4294SXin Li# Some tests cannot be automatically regenerated using this script, as they don't fall under the normal
25*b2fa4294SXin Li# golden test pattern
26*b2fa4294SXin LiEXCLUDED_TESTS="namespace_test_with_whitelist|proto_format_test|multi_level_namespace_test_with_whitelist|local_repository_test"
27*b2fa4294SXin Liecho "** Querying for tests..."
28*b2fa4294SXin Liregen_targets=$(bazel query //test:all | grep regenerate_with_jar | grep -vE "$EXCLUDED_TESTS")
29*b2fa4294SXin Li
30*b2fa4294SXin Liecho "** Building goldens..."
31*b2fa4294SXin Libazel build $regen_targets
32*b2fa4294SXin Li
33*b2fa4294SXin Liecho "** Copying goldens..."
34*b2fa4294SXin Lifor regen_target in $regen_targets; do
35*b2fa4294SXin Li  base_target_name=$(echo $regen_target | sed 's/\/\/test://g')
36*b2fa4294SXin Li  testdata_pkg_name=$(echo $base_target_name | sed 's/regenerate_with_jar_//g' | sed 's/_golden//g')
37*b2fa4294SXin Li  out_file="bazel-bin/test/${base_target_name}.out"
38*b2fa4294SXin Li  cp $out_file "test/testdata/${testdata_pkg_name}/golden.md"
39*b2fa4294SXin Lidone
40*b2fa4294SXin Li
41*b2fa4294SXin Liecho "** Files copied."
42*b2fa4294SXin Liecho "Please note that not all golden files are correctly copied by this script."
43*b2fa4294SXin Liecho "You may want to manually run:"
44*b2fa4294SXin Liecho ""
45*b2fa4294SXin Liecho "bazel test //test:all"
46*b2fa4294SXin Liecho ""
47*b2fa4294SXin Liecho "...and manually update tests which are still broken."
48