File: sort_rule.py

package info (click to toggle)
boost1.88 1.88.0-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 576,932 kB
  • sloc: cpp: 4,149,234; xml: 136,789; ansic: 35,092; python: 33,910; asm: 5,698; sh: 4,604; ada: 1,681; makefile: 1,633; pascal: 1,139; perl: 1,124; sql: 640; yacc: 478; ruby: 271; java: 77; lisp: 24; csh: 6
file content (99 lines) | stat: -rwxr-xr-x 2,616 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/env python3

# Copyright (C) 2008. Jurko Gospodnetic
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE.txt or copy at
# https://www.bfgroup.xyz/b2/LICENSE.txt)

# Tests for the Boost Jam builtin SORT rule.

from __future__ import print_function

import BoostBuild


###############################################################################
#
# testSORTCorrectness()
# ---------------------
#
###############################################################################

def testSORTCorrectness():
    """Testing that Boost Jam's SORT builtin rule actually sorts correctly."""
    t = BoostBuild.Tester(["-ftest.jam", "-d1"], pass_toolset=False,
        use_test_config=False)

    t.write("test.jam", """\
NOCARE all ;
source-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 ;
target-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 ;
ECHO "starting up" ;
sorted-data = [ SORT $(source-data) ] ;
ECHO "done" ;
if $(sorted-data) != $(target-data)
{
    ECHO "Source       :" $(source-data) ;
    ECHO "Expected     :" $(target-data) ;
    ECHO "SORT returned:" $(sorted-data) ;
    EXIT "SORT error" : -2 ;
}
""")

    t.run_build_system()
    t.expect_output_lines("starting up")
    t.expect_output_lines("done")
    t.expect_output_lines("SORT error", False)

    t.cleanup()


###############################################################################
#
# testSORTDuration()
# ------------------
#
###############################################################################

def testSORTDuration():
    """
      Regression test making sure Boost Jam's SORT builtin rule does not get
    quadratic behaviour again in this use case.

    """
    t = BoostBuild.Tester(["-ftest.jam", "-d1"], pass_toolset=False,
        use_test_config=False)

    f = open(t.workpath("test.jam"), "w")
    print("data = ", file=f)
    # high value will cause stack exhaustion in compile_append_chain
    for i in range(0, 10000):
        if i % 2:
            print('"aaa"', file=f)
        else:
            print('"bbb"', file=f)
    print(""";

ECHO "starting up" ;
sorted = [ SORT $(data) ] ;
ECHO "done" ;
NOCARE all ;
""", file=f)
    f.close()

    t.run_build_system(expected_duration=1)
    t.expect_output_lines("starting up")
    t.expect_output_lines("done")

    t.cleanup()


###############################################################################
#
# main()
# ------
#
###############################################################################

testSORTCorrectness()
testSORTDuration()