blob: bb7a8f693a2daf8438761d0368ea1163b531edf5 [file] [log] [blame]
Lukacs Berki840acb12017-01-25 14:01:33 +00001#!/bin/bash
2#
3# Copyright 2016 The Bazel Authors. All rights reserved.
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16#
17# Load the test setup defined in the parent directory
18CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
19source "${CURRENT_DIR}/../integration_test_setup.sh" \
20 || { echo "integration_test_setup.sh not found!" >&2; exit 1; }
21
22#### SETUP #############################################################
23
24set -e
25
26#### TESTS #############################################################
27
28function test_no_rebuild_on_irrelevant_header_change() {
29 mkdir -p a
30 cat > a/BUILD <<EOF
31cc_binary(name="a", srcs=["a.cc"], deps=["b"])
32cc_library(name="b", srcs=["b1.h", "b2.h"])
33EOF
34
35 cat > a/a.cc <<EOF
36#include "a/b1.h"
37
38int main(void) {
39 return B_RETURN_VALUE;
40}
41EOF
42
43 cat > a/b1.h <<EOF
44#define B_RETURN_VALUE 31
45EOF
46
47 cat > a/b2.h <<EOF
48=== BANANA ===
49EOF
50
51 bazel build //a || fail "build failed"
52 echo "CHERRY" > a/b2.h
53 bazel build //a >& $TEST_log || fail "build failed"
54 expect_not_log "Compiling a/a.cc"
55}
56
57function test_new_header_is_required() {
58 mkdir -p a
59 cat > a/BUILD <<EOF
60cc_binary(name="a", srcs=["a.cc"], deps=[":b"])
61cc_library(name="b", srcs=["b1.h", "b2.h"])
62EOF
63
64 cat > a/a.cc << EOF
65#include "a/b1.h"
66
67int main(void) {
68 return B1;
69}
70EOF
71
72 cat > a/b1.h <<EOF
73#define B1 3
74EOF
75
76 cat > a/b2.h <<EOF
77#define B2 4
78EOF
79
80 bazel build //a || fail "build failed"
81 cat > a/a.cc << EOF
82#include "a/b1.h"
83#include "a/b2.h"
84
85int main(void) {
86 return B1 + B2;
87}
88EOF
89
90 bazel build //a || fail "build failled"
91}
92
George Gensureabc93322017-02-27 12:16:39 +000093function test_no_recompile_on_shutdown() {
94 mkdir -p a
95 cat > a/BUILD <<EOF
96cc_binary(name="a", srcs=["a.cc"], deps=["b"])
97cc_library(name="b", includes=["."], hdrs=["b.h"])
98EOF
99
100 cat > a/a.cc <<EOF
101#include "b.h"
102
103int main(void) {
104 return B_RETURN_VALUE;
105}
106EOF
107
108 cat > a/b.h <<EOF
109#define B_RETURN_VALUE 31
110EOF
111
112 bazel build -s //a >& $TEST_log || fail "build failed"
113 expect_log "Compiling a/a.cc"
114 bazel shutdown >& /dev/null || fail "query failed"
115 bazel build -s //a >& $TEST_log || fail "build failed"
116 expect_not_log "Compiling a/a.cc"
117}
118
Lukacs Berki840acb12017-01-25 14:01:33 +0000119run_suite "Tests for Bazel's C++ rules"