Skip to content

Commit 78efecf

Browse files
committed
omit class file path from test
1 parent 893925a commit 78efecf

File tree

2 files changed

+40
-4
lines changed

2 files changed

+40
-4
lines changed

src/main.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ use std::io;
88
use std::ops::Deref;
99
use std::path::PathBuf;
1010

11-
use jvm_class_file_parser::{Attribute, AttributeSet, Bytecode, ClassAccess, ClassFile, ConstantPoolEntry, ExceptionTableEntry, Method};
11+
use jvm_class_file_parser::{
12+
Attribute, AttributeSet, Bytecode, ClassAccess, ClassFile, ConstantPoolEntry,
13+
ExceptionTableEntry, Method,
14+
};
1215

1316
const CONSTRUCTOR_NAME: &str = "<init>";
1417

@@ -25,6 +28,7 @@ fn javap(filepath: &str, print_code: bool) -> String {
2528
let mut file = File::open(filepath).unwrap();
2629
let class_file = ClassFile::from_file(&mut file).unwrap();
2730

31+
// as with Java's `javap`, we canonicalize the path
2832
let absolute_filepath = to_absolute_filepath(filepath).unwrap();
2933

3034
let mut output = String::new();
@@ -384,7 +388,10 @@ mod tests {
384388

385389
#[test]
386390
fn javap_dummy_runs_without_error() {
387-
insta::assert_debug_snapshot!(javap("classes/Dummy.class", true));
391+
let javap_output = javap("classes/Dummy.class", true);
392+
// remove the first line which contains an absolute path
393+
let end_of_first_line = javap_output.find("\n").unwrap_or(0);
394+
insta::assert_display_snapshot!(&javap_output[end_of_first_line + 1..]);
388395
}
389396

390397
#[test]
Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,34 @@
11
---
22
source: src/main.rs
3-
expression: "javap(\"classes/Dummy.class\", true)"
3+
expression: "&javap_output[end_of_first_line + 1..]"
44
---
5-
"Classfile /home/jbalint/sw/rust-sw/jvm-class-file-parser/classes/Dummy.class\n Compiled from: \"Dummy.java\"\nclass Dummy\n minor version: 0\n major version: 55\n flags: ACC_PUBLIC, ACC_SUPER\nConstant pool:\n #1 = Methodref #3.#10 // java/lang/Object.\"<init>\":()V\n #2 = Class #11 // Dummy\n #3 = Class #12 // java/lang/Object\n #4 = Utf8 <init>\n #5 = Utf8 ()V\n #6 = Utf8 Code\n #7 = Utf8 LineNumberTable\n #8 = Utf8 SourceFile\n #9 = Utf8 Dummy.java\n #10 = NameAndType #4:#5 // \"<init>\":()V\n #11 = Utf8 Dummy\n #12 = Utf8 java/lang/Object\nAttributes:\n SourceFile = \"Dummy.java\"\n{\n Dummy();\n descriptor: ()V\n flags: TODO\n Code: stack=1, locals=1, args_size=TODO 0: aload_0 \n 1: invokespecial #1 \n 4: return \n}\nSourceFile: \"Dummy.java\"\n"
5+
Compiled from: "Dummy.java"
6+
class Dummy
7+
minor version: 0
8+
major version: 55
9+
flags: ACC_PUBLIC, ACC_SUPER
10+
Constant pool:
11+
#1 = Methodref #3.#10 // java/lang/Object."<init>":()V
12+
#2 = Class #11 // Dummy
13+
#3 = Class #12 // java/lang/Object
14+
#4 = Utf8 <init>
15+
#5 = Utf8 ()V
16+
#6 = Utf8 Code
17+
#7 = Utf8 LineNumberTable
18+
#8 = Utf8 SourceFile
19+
#9 = Utf8 Dummy.java
20+
#10 = NameAndType #4:#5 // "<init>":()V
21+
#11 = Utf8 Dummy
22+
#12 = Utf8 java/lang/Object
23+
Attributes:
24+
SourceFile = "Dummy.java"
25+
{
26+
Dummy();
27+
descriptor: ()V
28+
flags: TODO
29+
Code: stack=1, locals=1, args_size=TODO 0: aload_0
30+
1: invokespecial #1
31+
4: return
32+
}
33+
SourceFile: "Dummy.java"
34+

0 commit comments

Comments
 (0)