Skip to content

Commit 00e5ed5

Browse files
committed
Only store original java files for tests
Only store original java files for tests
1 parent 33b81ff commit 00e5ed5

File tree

95 files changed

+90
-6107
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+90
-6107
lines changed

.gitignore

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,7 @@ Cargo.lock
33
.idea
44
.vscode
55
*.log
6-
lib/target
7-
*.class
6+
*.class
7+
lib/testcases/*.json
8+
lib/testcases/*.txt
9+
lib/testcases/*-gen.java

lib/src/tests/mod.rs

+16-15
Original file line numberDiff line numberDiff line change
@@ -104,23 +104,24 @@ fn tast_to_ast(class: &Class) -> Class {
104104
pub fn single_class_test(ast: &Class, tast: Option<&Class>, name: &str) {
105105
// Write AST & TAST to files
106106
let mut file =
107-
File::create(format!("tests/{name}-AST.json")).expect("File failed to be created");
107+
File::create(format!("testcases/{name}-AST.json")).expect("File failed to be created");
108108
serde_json::to_writer_pretty(&mut file, &ast).expect("failed to serialize class");
109109

110110
if let Some(tast) = tast {
111111
let mut file =
112-
File::create(format!("tests/{name}-TAST.json")).expect("File failed to be created");
112+
File::create(format!("testcases/{name}-TAST.json")).expect("File failed to be created");
113113
serde_json::to_writer_pretty(&mut file, tast).expect("failed to serialize class");
114114
};
115115

116116
// Load orignal java code
117-
let file = File::open(format!("tests/{name}.java")).expect("failed to open original java file");
117+
let file =
118+
File::open(format!("testcases/{name}.java")).expect("failed to open original java file");
118119
let og_java_code = read_to_string(file).expect("failed to read original java file");
119120

120121
let res = test_helper(ast, tast, name, &og_java_code);
121122

122123
if let Err(msg) = res {
123-
let mut file = File::create(format!("tests/{name}.java"))
124+
let mut file = File::create(format!("testcases/{name}.java"))
124125
.expect("failed to open original java file for writing");
125126
file.write(og_java_code.as_bytes())
126127
.expect("failed to write the original java code back into its file");
@@ -136,32 +137,32 @@ fn test_helper(
136137
) -> Result<(), std::string::String> {
137138
// Generate Java Code from AST and write to file
138139
let class_code = class_to_java(ast);
139-
let mut file = File::create(format!("tests/{name}.java"))
140+
let mut file = File::create(format!("testcases/{name}.java"))
140141
.expect("failed to open original java file for writing generated code");
141142
file.write(class_code.as_bytes())
142143
.map_err(|x| "failed to write generated java code in original java file".to_string())?;
143-
let mut file = File::create(format!("tests/{name}-gen.java")) // Only for debugging tests
144+
let mut file = File::create(format!("testcases/{name}-gen.java")) // Only for debugging tests
144145
.expect("failed to open generated java file for writing generated code");
145146
file.write(class_code.as_bytes())
146147
.map_err(|x| "failed to write generated java code in generated java file".to_string())?;
147148

148149
// Compile generated java code
149150
let mut child = Command::new("javac")
150-
.arg(format!("tests/{name}.java"))
151+
.arg(format!("testcases/{name}.java"))
151152
.arg("-g:none")
152153
.spawn()
153154
.map_err(|x| "failed to compile generated java-code".to_string())?;
154155
let ecode = child
155156
.wait()
156157
.map_err(|x| "failed to wait on child compiling generated java code".to_string())?;
157158
assert!(ecode.success());
158-
let gen_clz_file = read(format!("tests/{name}.class"))
159+
let gen_clz_file = read(format!("testcases/{name}.class"))
159160
.map_err(|x| "failed to read generated java class file".to_string())?;
160-
let mut file = File::create(format!("tests/{name}-gen.txt")).unwrap();
161+
let mut file = File::create(format!("testcases/{name}-gen.txt")).unwrap();
161162
let mut child = Command::new("javap")
162163
.arg("-v")
163164
.arg("-c")
164-
.arg(format!("tests/{name}.class"))
165+
.arg(format!("testcases/{name}.class"))
165166
.stdout(Stdio::from(file))
166167
.spawn()
167168
.map_err(|x| "failed to disassemble generated java class file".to_string())?;
@@ -171,26 +172,26 @@ fn test_helper(
171172
assert!(ecode.success());
172173

173174
// Compile original java code
174-
let mut file = File::create(format!("tests/{name}.java"))
175+
let mut file = File::create(format!("testcases/{name}.java"))
175176
.expect("failed to open original java file for writing");
176177
file.write(og_java_code.as_bytes())
177178
.map_err(|x| "failed to write original java code back".to_string())?;
178179
let mut child = Command::new("javac")
179-
.arg(format!("tests/{name}.java"))
180+
.arg(format!("testcases/{name}.java"))
180181
.arg("-g:none")
181182
.spawn()
182183
.map_err(|x| "failed to compile original java-code".to_string())?;
183184
let ecode = child
184185
.wait()
185186
.map_err(|x| "failed to wait on child compiling original java code".to_string())?;
186187
assert!(ecode.success());
187-
let og_clz_file = read(format!("tests/{name}.class"))
188+
let og_clz_file = read(format!("testcases/{name}.class"))
188189
.map_err(|x| "failed to read original java class file".to_string())?;
189-
let mut file = File::create(format!("tests/{name}.txt")).unwrap();
190+
let mut file = File::create(format!("testcases/{name}.txt")).unwrap();
190191
let mut child = Command::new("javap")
191192
.arg("-v")
192193
.arg("-c")
193-
.arg(format!("tests/{name}.class"))
194+
.arg(format!("testcases/{name}.class"))
194195
.stdout(Stdio::from(file))
195196
.spawn()
196197
.map_err(|x| "failed to disassemble original java class file".to_string())?;
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
class NamingConflict {
2-
int x = 69;
3-
4-
int f(int x) {
5-
return this.x + x;
6-
}
7-
}
1+
class NamingConflict {
2+
int x = 69;
3+
4+
int f(int x) {
5+
return this.x + x;
6+
}
7+
}
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
class Negator {
2-
int neg1(int x) {
3-
return -x;
4-
}
5-
6-
int neg2(int x) {
7-
return -(+(-(-1 * x)));
8-
}
9-
}
1+
class Negator {
2+
int neg1(int x) {
3+
return -x;
4+
}
5+
6+
int neg2(int x) {
7+
return -(+(-(-1 * x)));
8+
}
9+
}
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
class Return {
2-
char id(char x) {
3-
return x;
4-
}
5-
6-
boolean id(boolean b) {
7-
return b;
8-
}
9-
}
1+
class Return {
2+
char id(char x) {
3+
return x;
4+
}
5+
6+
boolean id(boolean b) {
7+
return b;
8+
}
9+
}
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
1-
class SetterGetter {
2-
int x;
3-
boolean b;
4-
char c;
5-
String s;
6-
7-
int getX() {
8-
return this.x;
9-
}
10-
11-
void setX(int x) {
12-
this.x = x;
13-
}
14-
15-
boolean getB() {
16-
return this.b;
17-
}
18-
19-
void setB(boolean b) {
20-
this.b = b;
21-
}
22-
23-
char getC() {
24-
return this.c;
25-
}
26-
27-
void setC(char c) {
28-
this.c = c;
29-
}
30-
31-
String getS() {
32-
return this.s;
33-
}
34-
35-
void setS(String s) {
36-
this.s = s;
37-
}
38-
}
1+
class SetterGetter {
2+
int x;
3+
boolean b;
4+
char c;
5+
String s;
6+
7+
int getX() {
8+
return this.x;
9+
}
10+
11+
void setX(int x) {
12+
this.x = x;
13+
}
14+
15+
boolean getB() {
16+
return this.b;
17+
}
18+
19+
void setB(boolean b) {
20+
this.b = b;
21+
}
22+
23+
char getC() {
24+
return this.c;
25+
}
26+
27+
void setC(char c) {
28+
this.c = c;
29+
}
30+
31+
String getS() {
32+
return this.s;
33+
}
34+
35+
void setS(String s) {
36+
this.s = s;
37+
}
38+
}
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
class StrAdd {
2-
String hello = "Hi";
3-
4-
String helloWorld() {
5-
return hello + " World";
6-
}
7-
}
1+
class StrAdd {
2+
String hello = "Hi";
3+
4+
String helloWorld() {
5+
return hello + " World";
6+
}
7+
}
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)