summaryrefslogtreecommitdiffstatshomepage
path: root/src/regtests/jedutil/jedtest.wsf
blob: cb2e47b509f1123316c5e0083db3806e382f9567 (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
<?xml version="1.0"?>
<package>
    <job id="Test"><?job debug="true" error="true"?>
        <runtime>
            <description>This script runs regresion tests on the jedutil tool.</description>
        </runtime>

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

                function diffFiles(file1, file2)
                {
                    var WshShell = WScript.CreateObject("WScript.Shell");
                    var oExec;
                    
                    if (g_Verbose)
                    {                    
                        WScript.Echo("Diff File 1: " + file1);
                        WScript.Echo("Diff File 2: " + file2);
                        WScript.Echo();
                    }
                    
                    oExec = WshShell.Exec("diff " + file1 + " " + file2);

                    while (!oExec.Status)
                    {
                        WScript.Sleep(100);
                    }
                    
                    if (g_Verbose)
                    {
                        WScript.StdOut.WriteLine(oExec.StdOut.ReadAll());
                        WScript.StdErr.WriteLine(oExec.StdErr.ReadAll());
                    }

                    return oExec.ExitCode;
                }

                function runCommandAndCaptureOutput(command, outputFile)
                {
                    var WshShell = WScript.CreateObject("WScript.Shell");
                    var fullCommand;
                    
                    fullCommand = "%comspec% /c ";
                    fullCommand += command;
                    fullCommand += " > ";
                    fullCommand += outputFile;
                    fullCommand += " 2>&1";
                    
                    if (g_Verbose)
                    {
                        WScript.Echo("Running the command : " + command);
                        WScript.Echo("Output File:          " + outputFile);
                        WScript.Echo();
                    }

                    WshShell.Run(fullCommand, 0, true);
                }

                function findJedTests(jedsPath, baselinePath, outputPath)
                {
                    var fso = new ActiveXObject("Scripting.FileSystemObject");
                    var folder = fso.GetFolder(jedsPath)
                    var folderCollection = new Enumerator(folder.files);
                    var jedArray = new Array();
                    
                    while (!folderCollection.atEnd())
                    {
                        ++jedArray.length;

                        jedArray[jedArray.length - 1] = new Object;
                        
                        jedArray[jedArray.length - 1].name = fso.GetBaseName(folderCollection.item().name);
                        jedArray[jedArray.length - 1].jedfile = folderCollection.item().path;
                        jedArray[jedArray.length - 1].baselineFile = baselinePath + "\\" +
                                                                     jedArray[jedArray.length - 1].name +
                                                                     ".txt";
                        jedArray[jedArray.length - 1].outputFile = outputPath + "\\" +
                                                                   jedArray[jedArray.length - 1].name +
                                                                   ".txt";
 
                        folderCollection.moveNext();
                    }
                    
                    return jedArray;
                }
            
                function runViewJedTests(jedArray, jedUtilApp)
                {
                    var command;
                
                    for (i = 0; i < jedArray.length; ++i)
                    {
                        command = jedUtilApp + " -view " + jedArray[i].jedfile + " " +
                                  jedArray[i].name;
                    
                        if (g_Verbose)
                        {
                            WScript.Echo("Viewing the JED file: " + jedArray[i].jedfile);
                            WScript.Echo();
                        }
                    
                        runCommandAndCaptureOutput(command, jedArray[i].outputFile);
                    }
                }
                
                function runDiffJedTests(jedArray)
                {
                    var result = true;
                    
                    for (i = 0; i < jedArray.length; ++i)
                    {
                        if (g_Verbose)
                        {
                            WScript.Echo("Diffing the output from viewing the JED file: " + jedArray[i].jedfile);
                        }
                        
                        if (diffFiles(jedArray[i].baselineFile, jedArray[i].outputFile))
                        {
                            WScript.Echo("Results are different for " + jedArray[i].name);
                            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 (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("Emptying the output directory");
                            WScript.Echo();
                        }
                    
                        fso.DeleteFile(outputPath + "\\*.*");
                    }
                    else
                    {
                        if (g_Verbose)
                        {
                            WScript.Echo("Creating the output directory");
                            WScript.Echo();
                        }
                        
                        fso.CreateFolder(outputPath);
                    }
                    
                    jedArray = findJedTests(jedsPath, baselinePath, outputPath);

                    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>