Skip to content

Commit

Permalink
chore: test cleanup (#205)
Browse files Browse the repository at this point in the history
  • Loading branch information
WillLillis authored Dec 26, 2024
1 parent 94567eb commit 903a611
Show file tree
Hide file tree
Showing 20 changed files with 33 additions and 14 deletions.
10 changes: 7 additions & 3 deletions asm-lsp/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,16 @@ use url_escape::encode_www_form_urlencoded;
/// Current function assumes that the RST file is already read and that it's been given a reference
/// to its contents (`&str`).
///
/// # Errors
///
/// This function will not error, it maintains a `Result` return type for compatibility
/// with a macro in the server's test code
///
/// # Panics
///
/// This function is highly specialized to parse a specific file and will panic
/// for most mal-formed/unexpected inputs
#[must_use]
pub fn populate_riscv_registers(rst_contents: &str) -> Vec<Register> {
pub fn populate_riscv_registers(rst_contents: &str) -> Result<Vec<Register>> {
enum ParseState {
FileStart,
SectionStart,
Expand Down Expand Up @@ -136,7 +140,7 @@ pub fn populate_riscv_registers(rst_contents: &str) -> Vec<Register> {
}
}

registers
Ok(registers)
}

/// Parse all of the RISCV instruction rst files inside of `docs_dir`
Expand Down
Binary file modified asm-lsp/serialized/directives/avr
Binary file not shown.
Binary file modified asm-lsp/serialized/directives/gas
Binary file not shown.
Binary file modified asm-lsp/serialized/directives/masm
Binary file not shown.
Binary file modified asm-lsp/serialized/directives/nasm
Binary file not shown.
Binary file modified asm-lsp/serialized/opcodes/arm
Binary file not shown.
Binary file modified asm-lsp/serialized/opcodes/arm64
Binary file not shown.
Binary file modified asm-lsp/serialized/opcodes/riscv
Binary file not shown.
Binary file modified asm-lsp/serialized/opcodes/x86
Binary file not shown.
Binary file modified asm-lsp/serialized/opcodes/x86_64
Binary file not shown.
Binary file modified asm-lsp/serialized/opcodes/z80
Binary file not shown.
Binary file modified asm-lsp/serialized/registers/6502
Binary file not shown.
Binary file modified asm-lsp/serialized/registers/arm
Binary file not shown.
Binary file modified asm-lsp/serialized/registers/arm64
Binary file not shown.
Binary file modified asm-lsp/serialized/registers/power-isa
Binary file not shown.
Binary file modified asm-lsp/serialized/registers/x86
Binary file not shown.
Binary file modified asm-lsp/serialized/registers/x86_64
Binary file not shown.
Binary file modified asm-lsp/serialized/registers/z80
Binary file not shown.
35 changes: 25 additions & 10 deletions asm-lsp/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ mod tests {
parser::{
populate_6502_instructions, populate_arm_instructions, populate_avr_directives,
populate_ca65_directives, populate_masm_nasm_directives,
populate_power_isa_instructions, populate_riscv_instructions,
populate_power_isa_instructions, populate_riscv_instructions, populate_riscv_registers,
},
populate_gas_directives, populate_instructions, populate_name_to_directive_map,
populate_name_to_instruction_map, populate_name_to_register_map, populate_registers, Arch,
Expand Down Expand Up @@ -2410,13 +2410,13 @@ Width: 8 bits",
* Serialization Tests
*************************************************************************/
macro_rules! serialized_registers_test {
($serialized_path:literal, $raw_path:literal) => {
($serialized_path:literal, $raw_path:literal, $populate_fn:expr) => {
let mut cmp_map = HashMap::new();
let regs_ser = include_bytes!($serialized_path);
let ser_vec = bincode::deserialize::<Vec<Register>>(regs_ser).unwrap();

let regs_raw = include_str!($raw_path);
let mut raw_vec = populate_registers(regs_raw).unwrap();
let mut raw_vec = $populate_fn(regs_raw).unwrap();

// HACK: Windows line endings...
if cfg!(target_os = "windows") {
Expand Down Expand Up @@ -2450,49 +2450,64 @@ Width: 8 bits",
fn serialized_x86_registers_are_up_to_date() {
serialized_registers_test!(
"serialized/registers/x86",
"../docs_store/registers/x86.xml"
"../docs_store/registers/x86.xml",
populate_registers
);
}
#[test]
fn serialized_x86_64_registers_are_up_to_date() {
serialized_registers_test!(
"serialized/registers/x86_64",
"../docs_store/registers/x86_64.xml"
"../docs_store/registers/x86_64.xml",
populate_registers
);
}
#[test]
fn serialized_arm_registers_are_up_to_date() {
serialized_registers_test!(
"serialized/registers/arm",
"../docs_store/registers/arm.xml"
"../docs_store/registers/arm.xml",
populate_registers
);
}
#[test]
fn serialized_arm64_registers_are_up_to_date() {
serialized_registers_test!(
"serialized/registers/arm64",
"../docs_store/registers/arm64.xml"
"../docs_store/registers/arm64.xml",
populate_registers
);
}
#[test]
fn serialized_z80_registers_are_up_to_date() {
serialized_registers_test!(
"serialized/registers/z80",
"../docs_store/registers/z80.xml"
"../docs_store/registers/z80.xml",
populate_registers
);
}
#[test]
fn serialized_riscv_registers_are_up_to_date() {
serialized_registers_test!(
"serialized/registers/riscv",
"../docs_store/registers/riscv.rst.txt",
populate_riscv_registers
);
}
#[test]
fn serialized_6502_registers_are_up_to_date() {
serialized_registers_test!(
"serialized/registers/6502",
"../docs_store/registers/6502.xml"
"../docs_store/registers/6502.xml",
populate_registers
);
}
#[test]
fn serialized_power_isa_registers_are_up_to_date() {
serialized_registers_test!(
"serialized/registers/power-isa",
"../docs_store/registers/power-isa.xml"
"../docs_store/registers/power-isa.xml",
populate_registers
);
}

Expand Down
2 changes: 1 addition & 1 deletion asm_docs_parsing/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ fn run(opts: &SerializeDocs) -> Result<()> {
}
(false, Some(arch_in)) => {
if arch_in == Arch::RISCV {
populate_riscv_registers(&conts)
populate_riscv_registers(&conts)?
} else {
populate_registers(&conts)?
}
Expand Down

0 comments on commit 903a611

Please sign in to comment.