summaryrefslogtreecommitdiffstatshomepage
path: root/src/regtests/jedutil/jedtest.wsf
blob: 1a6d6d8ad643ed01089c0691c7eec2042b2bb081 (plain) (blame)
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
<?xml version="1.0"?>
<package>
    <job id="JEDTest"><?job debug="true" error="true"?>
        <runtime>
            <description>This script runs regresion tests on the jedutil tool.</description>
            
            <named name="verbose" type="boolean" helpstring="Generate a detailed log." required="false"/>
        </runtime>

        <script language="JScript">
            <![CDATA[
                var g_Verbose = false;

                function runAndCaptureOutput(command, outputFile)
                {
                    var fso = new ActiveXObject("Scripting.FileSystemObject");
                    var WshShell = WScript.CreateObject("WScript.Shell");
                    var file, oExec;
                    
                    if (g_Verbose)
                    {                    
                        WScript.Echo("Command:     " + command);
                        WScript.Echo("Output File: " + outputFile);
                        WScript.Echo();
                    }
                    
                    file = fso.CreateTextFile(outputFile, false, false);
                    
                    oExec = WshShell.Exec(command);
                    
                    if (!oExec.StdOut.AtEndOfStream)
                    {
                        file.Write(oExec.StdOut.ReadAll());
                    }

                    if (!oExec.StdErr.AtEndOfStream)
                    {
                        file.Write(oExec.StdErr.ReadAll());
                    }
                    
                    file.Close();
                    
                    while (!oExec.Status)
                    {
                        WScript.Sleep(100);
                    }
                    
                    return oExec.ExitCode;
                }

                function diffFiles(file1, file2, outputFile)
                {
                    var fso = new ActiveXObject("Scripting.FileSystemObject");
                    var command;
                    
                    if (g_Verbose)
                    {                    
                        WScript.Echo("Diff File 1: " + file1);
                        WScript.Echo("Diff File 2: " + file2);
                        WScript.Echo("Output File: " + outputFile);
                        WScript.Echo();
                    }

                    if (!fso.FileExists(file1))
                    {
                        if (g_Verbose)
                        {
                            WScript.Echo("Diff File 1 does not exist.");
                            WScript.Echo();
                        }
                    
                        return 1;
                    }
                    
                    if (!fso.FileExists(file2))
                    {
                        if (g_Verbose)
                        {
                            WScript.Echo("Diff File 2 does not exist.");
                            WScript.Echo();
                        }
                    
                        return 1;
                    }
                    
                    command = "diff \"" + file1 + "\" \"" + file2 + "\"";

                    return runAndCaptureOutput(command, outputFile);
                }

                function getFilesInFolder(folder)
                {
                    var fso = new ActiveXObject("Scripting.FileSystemObject");
                    var filesCollection = new Enumerator(folder.files);
                    var filesArray = new Array();

                    while (!filesCollection.atEnd())
                    {
                        ++filesArray.length;

                        filesArray[filesArray.length - 1] = new Object();

                        filesArray[filesArray.length - 1].name = fso.GetBaseName(filesCollection.item().name);
                        
                        filesCollection.moveNext();
                    }
                    
                    return filesArray;
                }

                function findJedTests(jedsPath, baselinePath, outputPath)
                {
                    var fso = new ActiveXObject("Scripting.FileSystemObject");
                    var folder = fso.GetFolder(jedsPath)
                    var folderCollection = new Enumerator(folder.Subfolders);
                    var jedArray = new Array();
                    var filesArray, file;

                    while (!folderCollection.atEnd())
                    {
                        ++jedArray.length;

                        jedArray[jedArray.length - 1] = new Object;

                        jedArray[jedArray.length - 1].type = folderCollection.item().name;
                        jedArray[jedArray.length - 1].files = new Array;

                        filesArray = getFilesInFolder(
                                         fso.GetFolder(
                                            fso.BuildPath(jedsPath,
                                                          folderCollection.item().name)));

                        jedArray[jedArray.length - 1].files.length = filesArray.length;

                        for (index = 0; index < filesArray.length; ++index)
                        {
                            file = new Object;

                            file.jedFile = fso.BuildPath(jedsPath,
                                                         folderCollection.item().name);
                            file.jedFile = fso.BuildPath(file.jedFile,
                                                         filesArray[index].name);
                            file.jedFile = file.jedFile + ".jed";
                            
                            file.baselineFile = fso.BuildPath(baselinePath,
                                                              folderCollection.item().name);
                            file.baselineFile = fso.BuildPath(file.baselineFile,
                                                              filesArray[index].name);
                            file.baselineFile = file.baselineFile + ".txt";

                            file.outputFile = fso.BuildPath(outputPath,
                                                            folderCollection.item().name);
                            file.outputFile = fso.BuildPath(file.outputFile,
                                                            filesArray[index].name);
                            file.outputFile = file.outputFile + ".txt";

                            file.diffFile = fso.BuildPath(outputPath,
                                                          folderCollection.item().name);
                            file.diffFile = fso.BuildPath(file.diffFile,
                                                          filesArray[index].name);
                            file.diffFile = file.diffFile + ".diff";

                            jedArray[jedArray.length - 1].files[index] = file;
                        }
                        
                        folderCollection.moveNext();
                    }
                
                    return jedArray;
                }

                function createJedOutputFolders(outputPath, jedArray)
                {
                    var fso = new ActiveXObject("Scripting.FileSystemObject");
                    
                    for (index = 0; index < jedArray.length; ++index)
                    {
                        fso.CreateFolder(fso.BuildPath(outputPath,
                                                       jedArray[index].type));
                    }
                }
            
                function runViewJedTests(jedArray, jedUtilApp)
                {
                    var files, file, command;
                
                    for (testIndex = 0; testIndex < jedArray.length; ++testIndex)
                    {
                        if (g_Verbose)
                        {
                            WScript.Echo("Running the view command on the type \"" +
                                             jedArray[testIndex].type + "\"");
                            WScript.Echo();
                        }
                        
                        files = jedArray[testIndex].files;
                        
                        for (fileIndex = 0; fileIndex < files.length; ++fileIndex)
                        {
                            file = files[fileIndex];

                            if (g_Verbose)
                            {                            
                                WScript.Echo("    JED File:      " + file.jedFile);
                                WScript.Echo("    Baseline File: " + file.baselineFile);
                                WScript.Echo("    Output File:   " + file.outputFile);
                                WScript.Echo("    Diff File:     " + file.diffFile);
                                WScript.Echo();
                            }
                            
                            command = jedUtilApp + " -view \"" + file.jedFile + "\" " +
                                      jedArray[testIndex].type;
 
                            runAndCaptureOutput(command, file.outputFile);
                        }
                    }
                }
                
                function runDiffJedTests(jedArray)
                {
                    var result = true;
                    var files, file;
                    
                    for (testIndex = 0; testIndex < jedArray.length; ++testIndex)
                    {
                        if (g_Verbose)
                        {
                            WScript.Echo("Running the diffs on the type \"" +
                                             jedArray[testIndex].type + "\"");
                            WScript.Echo();
                        }
                    
                        files = jedArray[testIndex].files;
                        
                        for (fileIndex = 0; fileIndex < files.length; ++fileIndex)
                        {
                            file = files[fileIndex];
                            
                            if (diffFiles(file.baselineFile, file.outputFile, file.diffFile))
                            {
                                WScript.Echo("Results are different for " + file.jedFile);
                                WScript.Echo();                        
                                
                                result = false;
                            }
                        }
                    }
                    
                    return result;
                }
            
                function main()
                {
                    var result = 0;
                    var WshShell = WScript.CreateObject("WScript.Shell");
                    var fso = new ActiveXObject("Scripting.FileSystemObject");
                    var jedsPath = WshShell.CurrentDirectory + "\\jeds";
                    var baselinePath = WshShell.CurrentDirectory + "\\baseline";
                    var outputPath = WshShell.CurrentDirectory + "\\output";
                    var jedUtilApp = WshShell.CurrentDirectory + "\\..\\..\\..\\jedutil.exe";
                    var jedArray = new Array();

                    if (WScript.Arguments.Count() > 0)
                    {
                        g_Verbose = true;
                    }

                    if (g_Verbose)
                    {
                        WScript.Echo("JED Path:      " + jedsPath);
                        WScript.Echo("Baseline Path: " + baselinePath);
                        WScript.Echo("Output Path:   " + outputPath);
                        WScript.Echo("jedutil App:   " + jedUtilApp);
                        WScript.Echo();
                    }
                  
                    if (fso.FolderExists(outputPath))
                    {
                        if (g_Verbose)
                        {
                            WScript.Echo("Removing the existing the output directory");
                            WScript.Echo();
                        }
                    
                        fso.DeleteFolder(outputPath);
                    }

                    if (g_Verbose)
                    {
                        WScript.Echo("Creating the root output directory");
                        WScript.Echo();
                    }
                    
                    fso.CreateFolder(outputPath);
                    
                    jedArray = findJedTests(jedsPath, baselinePath, outputPath);

                    createJedOutputFolders(outputPath, jedArray);

                    runViewJedTests(jedArray, jedUtilApp);
                    
                    if (!runDiffJedTests(jedArray))
                    {
                        result = 1;
                    }

                    if (!result)
                    {
                        WScript.Echo("All tests ran successfully.");
                    }

                    return result;
                }

                try
                {
                    var result = main();

                    WScript.Quit(result);
                }
                catch (e)
                {
                    WScript.Echo("Error Occurred");
                    WScript.Echo("");
                    WScript.Echo("Name:        " + e.name);
                    WScript.Echo("Message:     " + e.message);
                    WScript.Echo("Number:      " + e.number);
                    WScript.Echo("Description: " + e.description);

                    WScript.Quit(1);
                }
            ]]>
        </script>
    </job>
</package>