Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b0255078 authored by Mårten Kongstad's avatar Mårten Kongstad
Browse files

aconfig: improve code diffs in tests

Implement a helper function to make it easier for unit tests to diff
(and find the first difference) generated code and expected code.

Bug: 283910447
Test: atest aconfig.test
Change-Id: I460e8fbf05e8f33e8a62ecef67b2d9d77051e876
parent 066575b9
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -35,4 +35,7 @@ rust_binary_host {
rust_test_host {
    name: "aconfig.test",
    defaults: ["aconfig.defaults"],
    rustlibs: [
        "libitertools",
    ],
}
+3 −0
Original line number Diff line number Diff line
@@ -18,3 +18,6 @@ tinytemplate = "1.2.1"

[build-dependencies]
protobuf-codegen = "3.2.0"

[dev-dependencies]
itertools = "0.10.5"
+5 −2
Original line number Diff line number Diff line
@@ -227,8 +227,11 @@ mod tests {
        let file = generate_cpp_code(&cache).unwrap();
        assert_eq!("aconfig/com_example.h", file.path.to_str().unwrap());
        assert_eq!(
            expect_content.replace(' ', ""),
            String::from_utf8(file.contents).unwrap().replace(' ', "")
            None,
            crate::test::first_significant_code_diff(
                expect_content,
                &String::from_utf8(file.contents).unwrap()
            )
        );
    }
}
+5 −2
Original line number Diff line number Diff line
@@ -135,8 +135,11 @@ mod tests {
        let file = generate_java_code(&cache).unwrap();
        assert_eq!("com/example/Flags.java", file.path.to_str().unwrap());
        assert_eq!(
            expect_content.replace(' ', ""),
            String::from_utf8(file.contents).unwrap().replace(' ', "")
            None,
            crate::test::first_significant_code_diff(
                expect_content,
                &String::from_utf8(file.contents).unwrap()
            )
        );
    }
}
+7 −1
Original line number Diff line number Diff line
@@ -126,6 +126,12 @@ pub fn r#enabled_rw() -> bool {
}
}
"#;
        assert_eq!(expected.trim(), String::from_utf8(generated.contents).unwrap().trim());
        assert_eq!(
            None,
            crate::test::first_significant_code_diff(
                expected,
                &String::from_utf8(generated.contents).unwrap()
            )
        );
    }
}
Loading