forked from apache/hive
/
TestParseNegative.vm
executable file
·131 lines (111 loc) · 3.36 KB
/
TestParseNegative.vm
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
package org.apache.hadoop.hive.ql.parse;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import java.io.*;
import java.util.*;
import org.apache.hadoop.hive.ql.QTestUtil;
import org.apache.hadoop.hive.ql.exec.Task;
public class $className extends TestCase {
private QTestUtil qt;
static boolean miniMR = false;
static String hadoopVer;
static {
try {
if ("$clusterMode".equals("miniMR"))
miniMR = true;
hadoopVer = "$hadoopVersion";
} catch (Exception e) {
System.out.println("Exception: " + e.getMessage());
e.printStackTrace();
System.out.flush();
fail("Unexpected exception in static initialization");
}
}
public $className(String name) {
super(name);
qt = null;
}
@Override
protected void setUp() {
try {
qt = new QTestUtil("$resultsDir.getCanonicalPath()", "$logDir.getCanonicalPath()",
miniMR, hadoopVer);
}
catch (Exception e) {
System.out.println("Exception: " + e.getMessage());
e.printStackTrace();
System.out.flush();
fail("Unexpected exception in setup");
}
}
@Override
protected void tearDown() {
try {
if (getName().equals("testParseNegative_shutdown"))
qt.shutdown();
else
qt.clearPostTestEffects();
}
catch (Exception e) {
System.out.println("Exception: " + e.getMessage());
e.printStackTrace();
System.out.flush();
fail("Unexpected exception in tearDown");
}
}
/**
* Dummy last test. This is only meant to shutdown qt
*/
public void testParseNegative_shutdown() {
System.out.println ("Cleaning up " + "$className");
}
public static Test suite() {
TestSuite suite = new TestSuite();
#foreach ($qf in $qfiles)
#set ($fname = $qf.getName())
#set ($eidx = $fname.indexOf('.'))
#set ($tname = $fname.substring(0, $eidx))
suite.addTest(new $className("testParseNegative_$tname"));
#end
suite.addTest(new $className("testParseNegative_shutdown"));
return suite;
}
static String debugHint = "\nSee build/ql/tmp/hive.log, "
+ "or try \"ant test ... -Dtest.silent=false\" to get more logs.";
#foreach ($qf in $qfiles)
#set ($fname = $qf.getName())
#set ($eidx = $fname.indexOf('.'))
#set ($tname = $fname.substring(0, $eidx))
public void testParseNegative_$tname() throws Exception {
try {
System.out.println("Begin query: " + "$fname");
qt.addFile("$qf.getCanonicalPath()");
qt.init("$fname");
ASTNode tree = qt.parseQuery("$fname");
List<Task<? extends Serializable>> tasks = qt.analyzeAST(tree);
fail("Unexpected success for query: " + "$fname" + debugHint);
}
catch (ParseException pe) {
int ecode = qt.checkNegativeResults("$fname", pe);
if (ecode != 0) {
fail("failed with error code = " + ecode + debugHint);
}
}
catch (SemanticException se) {
int ecode = qt.checkNegativeResults("$fname", se);
if (ecode != 0) {
fail("failed with error code = " + ecode + debugHint);
}
}
catch (Throwable e) {
System.out.println("Exception: " + e.getMessage());
e.printStackTrace();
System.out.flush();
fail("Unexpected exception" + debugHint);
}
System.out.println("Done query: " + "$fname");
assertTrue("Test passed", true);
}
#end
}