summaryrefslogtreecommitdiffstats
path: root/tests/auto/tools/qmake/testdata/functions/functions.pro
blob: 9ec2ffe93f3e2cac60d0ad5b125b484836e9ec7a (plain)
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
CONFIG = qt thread

defineTest(testReplace) {
    !isEqual(1, $$2):message("FAILED: $$3: got $$1, expected $${2}.")
}

#count
!count( CONFIG, 2 ) {
   message( "FAILED: count function: $$CONFIG" )
}

#contains
!contains( CONFIG, thread ) {
   message( "FAILED: contains function: $$CONFIG" )
}

#exists
!exists( functions.pro ) {
   message( "FAILED: exists function" )
}

#isEmpty
isEmpty( CONFIG ) {
   message( "FAILED: isEmpty function: $CONFIG" )
}

#files
!equals($$list($$files(one/*.cpp)), "one/1.cpp one/2.cpp") {
   message( "FAILED: files function: one/*.cpp" )
}
!equals($$list($$files(one/1*.cpp)), "one/1.cpp") {
   message( "FAILED: files function: one/1*.cpp" )
}
!equals($$list($$files(two/*.cpp)), "two/1.cpp two/2.cpp") {
   message( "FAILED: files function: two/*.cpp" )
}
!equals($$list($$files(three/wildcard*.cpp)), "three/wildcard21.cpp three/wildcard22.cpp") {
   message( "FAILED: files function: three/wildcard*.cpp" )
}
!equals($$list($$files(*.cpp)), "1.cpp 2.cpp wildcard21.cpp wildcard22.cpp") {
   message( "FAILED: files function: *.cpp" )
}
!equals($$list($$files(wildcard*.cpp)), "wildcard21.cpp wildcard22.cpp") {
   message( "FAILED: files function: wildcard*.cpp" )
}

#infile
!infile( infiletest.pro, DEFINES, QT_DLL ){
   message( "FAILED: infile function" )
}

#include
include( infiletest.pro, "", true ) 
!contains( DEFINES, QT_DLL ) {
   message( "FAILED: include function: $$DEFINES" )
}

#replace
VERSION=1.0.0
VERSION_replaced=$$replace(VERSION,\\.,_)
!isEqual(VERSION_replaced, 1_0_0) {
   message( "FAILED: replace function: $$VERSION_replaced" )
}

#test functions
defineTest(myTestFunction) {
   RESULT =
   list=$$1
   for(l, list) {
       RESULT += $$l
   }
   export(RESULT)
}
myTestFunction(oink baa moo)
!equals($$list($$member(RESULT, 0)), "oink") {
     message("FAILED: myTestFunction: $$RESULT")
}
myTestFunction("oink baa" moo)
!equals($$list($$member(RESULT, 0)), "oink baa") {
     message("FAILED: myTestFunction: $$RESULT")
}
myTestFunction(oink "baa moo")
!equals($$list($$member(RESULT, 0)), "oink") {
     message("FAILED: myTestFunction: $$RESULT")
}
myTestFunction("oink baa moo")
!equals($$list($$member(RESULT, 0)), "oink baa moo") {
     message("FAILED: myTestFunction: $$RESULT")
}

moo = "this is a test" "for real"
fn = $$OUT_PWD/testdir/afile
write_file($$fn, moo)|message("FAILED: write_file() failed")
exists($$fn)|message("FAILED: write_file() didn't write anything")
mooout = $$cat($$fn, line)
equals(moo, $$mooout)|message("FAILED: write_file() wrote something wrong")
moo += "another line"
write_file($$fn, moo)|message("FAILED: write_file() failed (take 2)")
mooout = $$cat($$fn, line)
equals(moo, $$mooout)|message("FAILED: write_file() wrote something wrong (take 2)")
mooadd = "yet another line"
write_file($$fn, mooadd, append)|message("FAILED: write_file() failed (append)")
moo += $$mooadd
mooout = $$cat($$fn, line)
equals(moo, $$mooout)|message("FAILED: write_file() wrote something wrong when appending")

pn = $$OUT_PWD/testpath/subdir
mkpath($$pn)|message("FAILED: mkpath() failed")
exists($$pn)|message("FAILED: mkpath() didn't create anything")

in = easy "less easy" sca$${LITERAL_HASH}ry crazy$$escape_expand(\\t\\r\\n) $$escape_expand(\\t)shit \'no\"way\\here
out = "easy \"less easy\" sca\$\${LITERAL_HASH}ry crazy\$\$escape_expand(\\\\t\\\\r\\\\n) \$\$escape_expand(\\\\t)shit \\\'no\\\"way\\\\here"
testReplace($$val_escape(in), $$out, "val_escape")

testReplace($$shadowed($$PWD/something), $$OUT_PWD/something, "shadowed")

#format_number
spc = " "
testReplace($$format_number(13), 13, "simple number format")
testReplace($$format_number(-13), -13, "negative number format")
testReplace($$format_number(13, ibase=16), 19, "hex input number format")
testReplace($$format_number(13, obase=16), d, "hex output number format")
testReplace($$format_number(13, width=5), " $$spc 13", "right aligned number format")
testReplace($$format_number(13, width=5 leftalign), "13 $$spc ", "left aligned number format")
testReplace($$format_number(13, width=5 zeropad), "00013", "zero-padded number format")
testReplace($$format_number(13, width=5 alwayssign), "$$spc +13", "always signed number format")
testReplace($$format_number(13, width=5 alwayssign zeropad), "+0013", "zero-padded always signed number format")
testReplace($$format_number(13, width=5 padsign), " $$spc 13", "sign-padded number format")
testReplace($$format_number(13, width=5 padsign zeropad), " 0013", "zero-padded sign-padded number format")

testReplace($$clean_path("c:$${DIR_SEPARATOR}crazy//path/../trolls"), "c:/crazy/trolls", "clean_path")

testReplace($$native_path("/crazy/trolls"), "$${DIR_SEPARATOR}crazy$${DIR_SEPARATOR}trolls", "native_path")

testReplace($$absolute_path("crazy/trolls"), "$$PWD/crazy/trolls", "absolute_path")
testReplace($$absolute_path("crazy/trolls", "/fake/path"), "/fake/path/crazy/trolls", "absolute_path with base")
testReplace($$relative_path($$_PRO_FILE_PWD_), $$basename($$_PRO_FILE_), "relative_path")
testReplace($$relative_path("/fake/trolls", "/fake/path"), "../trolls", "relative_path with base")

#this test is very rudimentary. the backend function is thoroughly tested in qt creator
in = "some nasty\" path\\"
win32: \
    out = "\"some nasty\"\\^\"\" path\"\\"
else: \
    out = "'some nasty\" path\\'"
testReplace($$shell_quote($$in), $$out, "shell_quote")

testReplace($$reverse($$list(one two three)), three two one, "reverse")