1#!/usr/local/bin/python3.8
2
3# Copyright 2017 Steven Watanabe
4# Distributed under the Boost Software License, Version 1.0.
5# (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
6
7import BoostBuild
8
9def test_basic():
10    t = BoostBuild.Tester(pass_toolset=0)
11
12    t.write("file.jam", """\
13    actions fail
14    {
15        invalid-dd0eeb5899734622
16    }
17
18    FAIL_EXPECTED t1 ;
19    fail t1 ;
20
21    UPDATE t1 ;
22    """)
23
24    t.run_build_system(["-ffile.jam"])
25    t.expect_output_lines("...failed*", False)
26    t.expect_nothing_more()
27
28    t.cleanup()
29
30def test_error():
31    t = BoostBuild.Tester(pass_toolset=0)
32
33    t.write("file.jam", """\
34    actions pass
35    {
36        echo okay >$(<)
37    }
38
39    FAIL_EXPECTED t1 ;
40    pass t1 ;
41
42    UPDATE t1 ;
43    """)
44
45    t.run_build_system(["-ffile.jam"], status=1)
46    t.expect_output_lines("...failed pass t1...")
47    t.expect_nothing_more()
48
49    t.cleanup()
50
51def test_multiple_actions():
52    """FAIL_EXPECTED targets are considered to pass if the first
53    updating action fails.  Further actions will be skipped."""
54    t = BoostBuild.Tester(pass_toolset=0)
55
56    t.write("file.jam", """\
57    actions fail
58    {
59        invalid-dd0eeb5899734622
60    }
61
62    actions pass
63    {
64         echo okay >$(<)
65    }
66
67    FAIL_EXPECTED t1 ;
68    fail t1 ;
69    pass t1 ;
70
71    UPDATE t1 ;
72    """)
73
74    t.run_build_system(["-ffile.jam", "-d1"])
75    t.expect_output_lines("...failed*", False)
76    t.expect_output_lines("pass t1", False)
77    t.expect_nothing_more()
78
79    t.cleanup()
80
81def test_quitquick():
82    """Tests that FAIL_EXPECTED targets do not cause early exit
83    on failure."""
84    t = BoostBuild.Tester(pass_toolset=0)
85
86    t.write("file.jam", """\
87    actions fail
88    {
89        invalid-dd0eeb5899734622
90    }
91
92    actions pass
93    {
94        echo okay >$(<)
95    }
96
97    FAIL_EXPECTED t1 ;
98    fail t1 ;
99
100    pass t2 ;
101
102    UPDATE t1 t2 ;
103    """)
104
105    t.run_build_system(["-ffile.jam", "-q", "-d1"])
106    t.expect_output_lines("pass t2")
107    t.expect_addition("t2")
108    t.expect_nothing_more()
109
110    t.cleanup()
111
112def test_quitquick_error():
113    """FAIL_EXPECTED targets should cause early exit if they unexpectedly pass."""
114    t = BoostBuild.Tester(pass_toolset=0)
115
116    t.write("file.jam", """\
117    actions pass
118    {
119        echo okay >$(<)
120    }
121
122    FAIL_EXPECTED t1 ;
123    pass t1 ;
124    pass t2 ;
125
126    UPDATE t1 t2 ;
127    """)
128
129    t.run_build_system(["-ffile.jam", "-q", "-d1"], status=1)
130    t.expect_output_lines("pass t2", False)
131    t.expect_nothing_more()
132
133    t.cleanup()
134
135test_basic()
136test_error()
137test_multiple_actions()
138test_quitquick()
139test_quitquick_error()
140