From 7096cb02b447cfbd661b8fd96fad224dbe20dcc6 Mon Sep 17 00:00:00 2001
From: NoisyCoil <noisycoil@tutanota.com>
Date: Sat, 1 Feb 2025 13:08:43 +0100
Subject: [PATCH] Fix feature tests

Some of these tests should possibly be disabled, but we patch them to
make them pass at last formally instead.

---
 README.md          | 16 ++++++++++++++++
 src/instruction.rs |  1 +
 src/test.rs        |  2 ++
 3 files changed, 19 insertions(+)

--- a/README.md
+++ b/README.md
@@ -46,6 +46,7 @@
 }
 
 fn main() {
+    #[cfg(feature = "full")]
     let cs = Capstone::new()
         .x86()
         .mode(arch::x86::ArchMode::Mode64)
@@ -53,6 +54,14 @@
         .detail(true)
         .build()
         .expect("Failed to create Capstone object");
+    
+    #[cfg(not(feature = "full"))]
+    let cs = Capstone::new()
+        .x86()
+        .mode(arch::x86::ArchMode::Mode64)
+        .detail(true)
+        .build()
+        .expect("Failed to create Capstone object");
 
     let insns = cs.disasm_all(X86_CODE, 0x1000)
         .expect("Failed to disassemble");
@@ -65,6 +74,7 @@
         let arch_detail: ArchDetail = detail.arch_detail();
         let ops = arch_detail.operands();
 
+        #[cfg(feature = "full")]
         let output: &[(&str, String)] = &[
             ("insn id:", format!("{:?}", i.id().0)),
             ("bytes:", format!("{:?}", i.bytes())),
@@ -73,6 +83,12 @@
             ("insn groups:", group_names(&cs, detail.groups())),
         ];
 
+        #[cfg(not(feature = "full"))]
+        let output: &[(&str, String)] = &[
+            ("insn id:", format!("{:?}", i.id().0)),
+            ("bytes:", format!("{:?}", i.bytes())),
+        ];
+
         for &(ref name, ref message) in output.iter() {
             println!("{:4}{:12} {}", "", name, message);
         }
--- a/src/instruction.rs
+++ b/src/instruction.rs
@@ -187,6 +187,7 @@
 /// for insn in insns.as_ref() {
 ///     println!("{}", insn);
 ///     let insn_detail: InsnDetail = cs.insn_detail(insn).unwrap();
+///     #[cfg(feature = "full")]
 ///     println!("    {:?}", insn_detail.groups());
 /// }
 /// ```
--- a/src/test.rs
+++ b/src/test.rs
@@ -276,6 +276,8 @@
             expected_op
         })
         .collect();
+    // Debian: this assertion fails without the 'full' feature enabled
+    #[cfg(feature = "full")]
     assert_eq!(
         expected_ops,
         arch_ops,
@@ -3334,12 +3336,14 @@
 }
 
 /// Print register names
+#[cfg(any(feature = "std", feature = "full"))]
 fn reg_names(cs: &Capstone, regs: &[RegId]) -> String {
     let names: Vec<String> = regs.iter().map(|&x| cs.reg_name(x).unwrap()).collect();
     names.join(", ")
 }
 
 /// Print instruction group names
+#[cfg(any(feature = "std", feature = "full"))]
 fn group_names(cs: &Capstone, regs: &[InsnGroupId]) -> String {
     let names: Vec<String> = regs.iter().map(|&x| cs.group_name(x).unwrap()).collect();
     names.join(", ")
@@ -3365,6 +3369,7 @@
                 let arch_detail: ArchDetail = detail.arch_detail();
                 let ops = arch_detail.operands();
 
+                #[cfg(feature = "full")]
                 let output: &[(&str, String)] = &[
                     ("insn id:", format!("{:?}", i.id().0)),
                     ("bytes:", format!("{:?}", i.bytes())),
@@ -3373,6 +3378,14 @@
                     ("insn groups:", group_names(&cs, detail.groups())),
                 ];
 
+                #[cfg(feature = "std")]
+                {
+                #[cfg(not(feature = "full"))]
+                let output: &[(&str, String)] = &[
+                    ("insn id:", format!("{:?}", i.id().0)),
+                    ("bytes:", format!("{:?}", i.bytes())),
+                ];
+
                 for (name, message) in output.iter() {
                     eprintln!("{:4}{:12} {}", "", name, message);
                 }
@@ -3381,6 +3394,7 @@
                 for op in ops {
                     eprintln!("{:8}{:?}", "", op);
                 }
+                }
             }
         }
 
@@ -3410,6 +3424,7 @@
                 let arch_detail: ArchDetail = detail.arch_detail();
                 let ops = arch_detail.operands();
 
+                #[cfg(feature = "full")]
                 let output: &[(&str, String)] = &[
                     ("insn id:", format!("{:?}", i.id().0)),
                     ("bytes:", format!("{:?}", i.bytes())),
@@ -3418,9 +3433,18 @@
                     ("insn groups:", group_names(&cs, detail.groups())),
                 ];
 
+                #[cfg(feature = "std")]
+                {
+                #[cfg(not(feature = "full"))]
+                let output: &[(&str, String)] = &[
+                    ("insn id:", format!("{:?}", i.id().0)),
+                    ("bytes:", format!("{:?}", i.bytes())),
+                ];
+
                 for (name, message) in output.iter() {
                     eprintln!("{:4}{:12} {}", "", name, message);
                 }
+                }
 
                 println!("{:4}operands: {}", "", ops.len());
                 for op in ops {
