Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/tools/build/v2/test/testing-primitives/bootstrap.jam @ 32

Last change on this file since 32 was 29, checked in by landauf, 17 years ago

updated boost from 1_33_1 to 1_34_1

File size: 4.0 KB
Line 
1# Copyright 2002 Dave Abrahams
2# Distributed under the Boost Software License, Version 1.0.
3# (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
4
5# Proof-of-concept for bjam-based testing mechanism. This file should
6# work on NT, Cygwin, and Linux. No promises for other platforms.
7
8# Set a variable which says how to dump a file to stdout
9if $(NT)
10{
11    CATENATE = type ;
12}
13else
14{
15    CATENATE = cat ;
16}
17
18# invoke the given action rule `act' to build target from sources
19rule do-make ( target : sources * : act )
20{
21    DEPENDS $(target) : $(sources) ;
22    $(act) $(target) : $(sources) ;
23}
24
25# top-level version of do-make which causes target to be built by
26# default
27rule make ( target : sources * : act )
28{
29    DEPENDS all : $(target) ;
30    do-make $(target) : $(sources) : $(act) ;
31}
32
33# cause `target' to exist and building to succeed if invoking
34#
35#    $(act) $(target) : $(sources)
36#
37# fails, and to fail if the action succeeds.
38rule make-fail ( target : sources * : act )
39{
40    # Establish another logical target which refers to the same file,
41    # by using different grist.
42    DEPENDS all : <different-grist>$(target) ;
43   
44    # Make the new logical target depend on the target
45    DEPENDS <different-grist>$(target) : $(target) ;
46   
47    # Cause the target to be built from sources using $(act).
48    do-make $(target) : $(sources) : $(act) ;
49   
50    # Note that we expect target to fail to build
51    FAIL_EXPECTED $(target) ;
52   
53    # Build a failure marker file. Because targets are only built if
54    # all their dependents "succeed", the marker will only be
55    # generated if $(target) failed to build, as expected.
56    failure-marker <different-grist>$(target) ;
57}
58
59# Simple action rules which write text into the target. Different
60# names for different purposes.
61actions failure-marker
62{
63    echo failed as expected > $(<)
64}
65
66actions create
67{
68    echo creating > $(<)
69}
70
71# An action which will always fail, for testing expected failure rules
72actions fail-to-create
73{
74    exit 1
75}
76
77# Basic rule-action pair which builds the target by executing the
78# given commands
79rule do-run ( target : commands + )
80{
81    COMMANDS on $(target) = $(commands) ;
82    NOTFILE $(commands) ;
83}
84
85# Run commands, leaving the output behind in $(<:S=.out). Echo to
86# stdout if the command fails.
87#
88#  Detailed explanation:
89#
90#  $(COMMANDS)                          Run commands
91#       > $(<:S=.out)                   into the output file
92#       2>&1                            including stderr
93#     &&                                and if that succeeds
94#       cp -f $(<:S=.out) $(<)          copy the output file into the target
95#  ||                                   otherwise
96#     ( $(CATENATE) $(<:S=.out)         dump any output to stdout
97#       && exit 1                       and exit with an error code
98#     )
99actions do-run
100{
101    $(COMMANDS) > $(<:S=.out) 2>&1 && cp -f $(<:S=.out) $(<) || ( $(CATENATE) $(<:S=.out) && exit 1 )
102}
103
104# top-level version of do-run which causes target to be built by
105# default
106rule run ( target : commands + )
107{
108    DEPENDS all : $(target) ;
109    do-run $(target) : $(commands) ;
110}
111
112# experimental expected-failure version of run. This doesn't have
113# quite the right semantics w.r.t. output dumping (it is still only
114# dumped if the run fails), but we don't need run-fail anyway so it
115# doesn't matter too much.
116rule run-fail ( target : commands + )
117{
118    make-fail $(target) : $(commands) : do-run ;
119}
120
121# A command which will always fail to run.  There is no file called
122# nonexistent, so executing $(error) always causes an error. We can't
123# just use `exit 1' below because that will cause all command
124# processing to stop, and we want the rest of the do-run action
125# command-line to execute.
126error = $(CATENATE)" nonexistent" ;
127
128make-fail t1.txt : : create ;
129make-fail t2.txt : : fail-to-create ;
130make t3.txt : : create ;
131make t4.txt : : fail-to-create ;
132
133run t5.txt : "( echo failing t5 && $(error) )" ;
134run t6.txt : echo hi ;
135
136run-fail t7.txt : "( echo failing t7 && $(error) )" ;
137run-fail t8.txt : echo hi ;
Note: See TracBrowser for help on using the repository browser.