jwharm / java-gi

GObject-Introspection bindings generator for Java
GNU Lesser General Public License v2.1
85 stars 7 forks source link

Building clean repo causes AssertionFailedError after GIO test #145

Open Tennessene opened 1 week ago

Tennessene commented 1 week ago

I have tried to build Java-GI on Ubuntu 24.04 and Fedora 40. I get the same error on each. I also tried multiple Java distributions. I have made sure I have all the required packages.

I get the following error:

> Task :gio:test

StrvArrayTest > testStrvArrayToJava() FAILED
    org.opentest4j.AssertionFailedError at StrvArrayTest.java:31

20 tests completed, 1 failed

Here is what the report says:

org.opentest4j.AssertionFailedError: expected: not equal but was: <>
    at app//org.junit.jupiter.api.AssertionFailureBuilder.build(AssertionFailureBuilder.java:152)
    at app//org.junit.jupiter.api.AssertionFailureBuilder.buildAndThrow(AssertionFailureBuilder.java:132)
    at app//org.junit.jupiter.api.AssertNotEquals.failEqual(AssertNotEquals.java:277)
    at app//org.junit.jupiter.api.AssertNotEquals.assertNotEquals(AssertNotEquals.java:263)
    at app//org.junit.jupiter.api.AssertNotEquals.assertNotEquals(AssertNotEquals.java:258)
    at app//org.junit.jupiter.api.Assertions.assertNotEquals(Assertions.java:2819)
    at app//io.github.jwharm.javagi.test.gio.StrvArrayTest.testStrvArrayToJava(StrvArrayTest.java:31)
    at java.base@22.0.2/java.lang.reflect.Method.invoke(Method.java:580)
    at java.base@22.0.2/java.util.ArrayList.forEach(ArrayList.java:1597)
    at java.base@22.0.2/java.util.ArrayList.forEach(ArrayList.java:1597)

I am quite sure it is something on Java-GI's end as I ran git clone --recurse-submodules https://github.com/jwharm/java-gi.git and ran ./gradlew build right after like the documentation says.

jwharm commented 1 week ago

That testcase checks if a C function with return type char*** (an array of String arrays) correctly results in a Java String[][]. The testcases uses the GIO function DesktopAppInfo.search("gnome") because that's literally the only function in the Gir files that returns a char***, and I hoped that a generic text like "gnome" would always return a few results.

To be absolutely sure that the resulting String[][] arrays contain valid strings, the testcase also checks that the strings are not null and at least one of them contains the text "org.gnome". On my machine, it succeeds. But apparently this is not always the case :-)

It's of course a very naughty testcase and it needs to be replaced with a better one, ideally one that is not as dependent on specific results of DesktopAppInfo.search(). Maybe you have any suggestions? Feel free to experiment with the current testcase - see StrvArrayTest.java.

One day I will implement a real regression suite for java-gi that uses the GObject-Introspection test suites (Regress and GIMarshallers).

Tennessene commented 1 week ago

Okay, now I know exactly what's happening. I will experiment with this tonight or later tomorrow