2 # SPDX-License-Identifier: EPL-1.0
3 ##############################################################################
4 # Copyright (c) 2017 The Linux Foundation and others.
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Eclipse Public License v1.0
8 # which accompanies this distribution, and is available at
9 # http://www.eclipse.org/legal/epl-v10.html
10 ##############################################################################
12 # This script tests jjb templates by comparing the result with expected output
13 # from global-jjb's origin/master branch.
16 script_dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/jjb
17 expected_xml_dir="$(mktemp -d -t gjjb-XXXXXXXX)"
19 echo "Script Directory: $script_dir"
20 echo "Test Directory: $test_dir"
21 echo "Expected XML Directory: $expected_xml_dir"
25 git worktree add --detach "$gittmp" origin/master
26 pushd "$gittmp" || exit
27 echo "Generating expected XML."
28 jenkins-jobs test --recursive -o "$expected_xml_dir" \
29 "$gittmp":.jjb-test > /dev/null 2>&1
33 echo "Generating test XML."
34 jenkins-jobs test --recursive -o "$test_dir" "$script_dir":.jjb-test
37 for xml in "$test_dir"/*; do
38 job=$(basename "$xml")
39 if ! cmp "$expected_xml_dir/$job" "$xml"; then
40 echo "Differences detected in $job"
41 diff "$expected_xml_dir/$job" "$xml"
46 echo "Checking for double curly braces..."
47 mapfile -t xml_files < <(find "$test_dir" -type f)
48 for xml in "${xml_files[@]}"; do
49 if grep '{{' "$xml"; then
50 echo "ERROR: Double curly braces discovered in output XML."
54 echo "No double curly braces found."
57 rm -rf "$test_dir" "$expected_xml_dir"
60 echo "WARN: Differences detected." \
61 "Check above for jobs that have been changed."