1#!/usr/bin/python 2 3# Copyright (C) 2008. Jurko Gospodnetic 4# Distributed under the Boost Software License, Version 1.0. 5# (See accompanying file LICENSE_1_0.txt or copy at 6# http://www.boost.org/LICENSE_1_0.txt) 7 8# Tests for the Boost Jam builtin SORT rule. 9 10from __future__ import print_function 11 12import BoostBuild 13 14 15############################################################################### 16# 17# testSORTCorrectness() 18# --------------------- 19# 20############################################################################### 21 22def testSORTCorrectness(): 23 """Testing that Boost Jam's SORT builtin rule actually sorts correctly.""" 24 t = BoostBuild.Tester(["-ftest.jam", "-d1"], pass_toolset=False, 25 use_test_config=False) 26 27 t.write("test.jam", """\ 28NOCARE all ; 29source-data = 1 8 9 2 7 3 4 7 1 27 27 9 98 98 1 1 4 5 6 2 3 4 8 1 -2 -2 0 0 0 ; 30target-data = -2 -2 0 0 0 1 1 1 1 1 2 2 27 27 3 3 4 4 4 5 6 7 7 8 8 9 9 98 98 ; 31ECHO "starting up" ; 32sorted-data = [ SORT $(source-data) ] ; 33ECHO "done" ; 34if $(sorted-data) != $(target-data) 35{ 36 ECHO "Source :" $(source-data) ; 37 ECHO "Expected :" $(target-data) ; 38 ECHO "SORT returned:" $(sorted-data) ; 39 EXIT "SORT error" : -2 ; 40} 41""") 42 43 t.run_build_system() 44 t.expect_output_lines("starting up") 45 t.expect_output_lines("done") 46 t.expect_output_lines("SORT error", False) 47 48 t.cleanup() 49 50 51############################################################################### 52# 53# testSORTDuration() 54# ------------------ 55# 56############################################################################### 57 58def testSORTDuration(): 59 """ 60 Regression test making sure Boost Jam's SORT builtin rule does not get 61 quadratic behaviour again in this use case. 62 63 """ 64 t = BoostBuild.Tester(["-ftest.jam", "-d1"], pass_toolset=False, 65 use_test_config=False) 66 67 f = open(t.workpath("test.jam"), "w") 68 print("data = ", file=f) 69 for i in range(0, 20000): 70 if i % 2: 71 print('"aaa"', file=f) 72 else: 73 print('"bbb"', file=f) 74 print("""; 75 76ECHO "starting up" ; 77sorted = [ SORT $(data) ] ; 78ECHO "done" ; 79NOCARE all ; 80""", file=f) 81 f.close() 82 83 t.run_build_system(expected_duration=1) 84 t.expect_output_lines("starting up") 85 t.expect_output_lines("done") 86 87 t.cleanup() 88 89 90############################################################################### 91# 92# main() 93# ------ 94# 95############################################################################### 96 97testSORTCorrectness() 98testSORTDuration() 99