blob: 961795b075a29115900660ff423f3132a4bac28a [file] [log] [blame]
Jens Geyera4d458f2024-10-10 23:03:57 +02001#
2# Licensed to the Apache Software Foundation (ASF) under one
3# or more contributor license agreements. See the NOTICE file
4# distributed with this work for additional information
5# regarding copyright ownership. The ASF licenses this file
6# to you under the Apache License, Version 2.0 (the
7# "License"); you may not use this file except in compliance
8# with the License. You may obtain a copy of the License at
9# *
10# http://www.apache.org/licenses/LICENSE-2.0
11# *
12# Unless required by applicable law or agreed to in writing,
13# software distributed under the License is distributed on an
14# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15# KIND, either express or implied. See the License for the
16# specific language governing permissions and limitations
17# under the License.
18#
19
20#---- failing tests --------------------------------------------
21
22# expected to fail at Thrift Compiler
23$FAIL_THRIFT = @(
24 "BrokenConstants.thrift", # intended to break
25 "DuplicateImportsTest.thrift", # subdir includes don't work here
26 "Include.thrift") # subdir includes don't work here
27
28# expected to fail at Delphi Compiler
Jens Geyer0f0243e2024-10-20 17:52:28 +020029$FAIL_DELPHI = @(
30 "Thrift5320.thrift" # this conflicts with Delphi scopes, but it's a bad practice testcase anyway
31)
Jens Geyera4d458f2024-10-10 23:03:57 +020032
33# unexpected but known bugs (TODO: fix them)
Jens Geyer0f0243e2024-10-20 17:52:28 +020034$KNOWN_BUGS = @(
35 "IgnoreInitialismsTest.thrift",
36 "JavaDefinitionOrderB.thrift",
37 "NameConflictTest.thrift"
38 )
Jens Geyera4d458f2024-10-10 23:03:57 +020039
40
41
42#---- functions --------------------------------------------
43
44function FindThriftExe() {
45 # prefer debug over release over path
46 write-host -nonewline Looking for thrift.exe ...
47 $exe = "thrift.exe"
48
49 # if we have a freshly compiled one it might be a better choice
50 @("Release","Debug") | foreach{
51 if( test-path "$ROOTDIR\compiler\cpp\$_\thrift.exe") { $exe = "$ROOTDIR\compiler\cpp\$_\thrift.exe" }
52 if( test-path "$ROOTDIR\compiler\cpp\compiler\$_\thrift.exe") { $exe = "$ROOTDIR\compiler\cpp\$_\compiler\thrift.exe" }
53 }
54
55 return $exe
56}
57
58
59function FindDcc32Exe() {
60 # prefer debug over release over path
61 write-host -nonewline Looking for dcc32.exe ...
62 $exe = "dcc32.exe"
63
64 # TODO: add arbitraily complex code to locate a suitable dcc32.exe if it is not in the path
65
66 return $exe
67}
68
69
70function InitializeFolder([string] $folder, [string] $pattern) {
71 #write-host $folder\$pattern
72 if(-not (test-path $folder)) {
73 new-item $folder -type directory | out-null
74 }
75 pushd $folder
76 remove-item $pattern #-recurse
77 popd
78}
79
80
81function CopyFilesFrom([string] $source, $text) {
82 #write-host "$source"
83 if( ($source -ne "") -and (test-path $source)) {
84 if( $text -ne $null) {
85 write-host -foregroundcolor yellow Copying $text ...
86 }
87
88 pushd $source
89 # recurse dirs
90 gci . -directory | foreach {
91 CopyFilesFrom "$_"
92 }
93 # files within
94 gci *.thrift -file | foreach {
95 #write-host $_
96 $name = $_.name
97 copy-item $_ "$TARGET\$name"
98 }
99 popd
100 }
101}
102
103function TestIdlFile([string] $idl) {
104 # expected to fail at Thrift Compiler
105 $filter = $false
106 $FAIL_THRIFT | foreach {
107 if( $idl -eq $_) {
108 $filter = $true
109 write-host "Skipping $_"
110 }
111 }
112 if( $filter) { return $true }
113
114 # compile IDL
115 #write-host -nonewline " $idl"
116 InitializeFolder "$TARGET\gen-delphi" "*.pas"
117 &$THRIFT_EXE $VERBOSE -r --gen delphi:register_types,constprefix,events,xmldoc $idl | out-file "$TARGET\thrift.log"
118 if( -not $?) {
119 get-content "$TARGET\thrift.log" | out-default
120 write-host -foregroundcolor red "Thrift compilation failed: $idl"
121 return $false
122 }
123
124 # generate project dile
125 $units = gci "$TARGET\gen-delphi\*.pas"
126 $lines = @()
127 $lines += "program $TESTAPP;"
128 $lines += "{`$APPTYPE CONSOLE}"
129 $lines += ""
130 $lines += "uses"
131 $units | foreach { $name = $_.name.Replace(".pas",""); $lines += " $name," }
132 $lines += " Windows, Classes, SysUtils;"
133 $lines += ""
134 $lines += "begin"
135 $lines += " Writeln('Successfully compiled!');"
136 $lines += " Writeln('List of units:');"
137 $units | foreach { $name = $_.name.Replace(".pas",""); $lines += " Writeln('- $name');" }
138 $lines += " Writeln;"
139 $lines += ""
140 $lines += "end."
141 $lines += ""
142 $lines | set-content "$TARGET\gen-delphi\$TESTAPP.dpr"
143
144 # try to compile the DPR
145 # this should not throw any errors, warnings or hints
146 $exe = "$TARGET\gen-delphi\$TESTAPP.exe"
147 if( test-path $exe) { remove-item $exe }
148 &$DCC32_EXE -B "$TARGET\gen-delphi\$TESTAPP" -U"$UNITSEARCH" -I"$UNITSEARCH" -N"$OUTDCU" -E"$TARGET\gen-delphi" | out-file "$TARGET\compile.log"
149 if( -not (test-path $exe)) {
150
151 # expected to fail at Thrift Compiler
152 $filter = $false
153 $FAIL_DELPHI | foreach {
154 if( $idl -eq $_) {
155 $filter = $true
156 write-host ("Delphi compilation failed at "+$idl+" - as expected")
157 }
158 }
159 $KNOWN_BUGS | foreach {
160 if( $idl -eq $_) {
161 $filter = $true
162 write-host ("Delphi compilation failed at "+$idl+" - known issue (TODO)")
163 }
164 }
165 if( $filter) { return $true }
166
167 get-content "$TARGET\compile.log" | out-default
168 write-host -foregroundcolor red "Delphi compilation failed: $idl"
169 return $false
170 }
171
172 # The compiled program is now executed. If it hangs or crashes, we
173 # have a serious problem with the generated code. Expected output
174 # is "Successfully compiled:" followed by a list of generated units.
175 &"$exe" | out-file "$TARGET\exec.log"
176 if( -not $?) {
177 get-content "$TARGET\exec.log" | out-default
178 write-host -foregroundcolor red "Test execution failed: $idl"
179 return $false
180 }
181 return $true
182}
183
184#---- main -------------------------------------------------
185# CONFIGURATION BEGIN
186# configuration settings, adjust as necessary to meet your system setup
187$MY_THRIFT_FILES = ""
188$VERBOSE = "" # set any Thrift compiler debug/verbose flag you want
189
190# init
191$ROOTDIR = $PSScriptRoot + "\..\..\..\.."
192
193# try to find thrift.exe
194$THRIFT_EXE = FindThriftExe
195&$THRIFT_EXE -version
196if( -not $?) {
197 write-host -foregroundcolor red Missing thrift.exe
198 exit 1
199}
200
201# try to find dcc32.exe
202$DCC32_EXE = FindDcc32Exe
203&$DCC32_EXE --version
204if( -not $?) {
205 write-host -foregroundcolor red Missing dcc32.exe
206 exit 1
207}
208
209
210# some helpers
211$TARGET = "$ROOTDIR\..\thrift-testing"
212$TESTAPP = "TestProject"
213$UNITSEARCH = "$ROOTDIR\lib\pas\src;$ROOTDIR\lib\delphi\src"
214$OUTDCU = "$TARGET\dcu"
215
216# create and/or empty target dirs
217InitializeFolder "$TARGET" "*.thrift"
218InitializeFolder "$TARGET\gen-delphi" "*.pas"
219InitializeFolder "$OUTDCU" "*.dcu"
220
221# recurse through thrift WC and "my thrift files" folder
222# copies all .thrift files into thrift-testing
223CopyFilesFrom "$ROOTDIR" "Thrift IDL files"
224CopyFilesFrom "$MY_THRIFT_FILES" "Custom IDL files"
225
226# codegen and compile all thrift files, one by one to prevent side effects
227$count = 0
228write-host -foregroundcolor yellow Running codegen tests ..
229try {
230 pushd "$TARGET"
231 gci *.thrift -file | foreach {
232 $count += 1
233 $ok = TestIdlFile $_.name
234 if( -not $ok) {
235 throw "TEST FAILED" # automated tests
236 popd; pause; pushd "$TARGET" # interactive / debug
237 }
238 }
239 write-host -foregroundcolor green "Success ($count tests executed)"
240 exit 0
241} catch {
242 write-host -foregroundcolor red $_
243 exit 1
244} finally {
245 popd
246}
247
248#eof