ahgilak / deno_gi

Deno port of Gnome libraries (such as Gtk).
https://deno.land/x/deno_gi
33 stars 2 forks source link

Add tests #14

Closed vixalien closed 5 months ago

vixalien commented 11 months ago

It would be nice to add tests to this repo to ensure that progress made is not undone. Some tests could be copied over from GJS, and a CI runner can be added that tests for test regressions, and another CI runner can be added for style checks.

vixalien commented 8 months ago

In slight relation to #29, I also talked to ebassi, who's a prolific GObject-Introspection developer about testing. Here's what he said:

The "everything" is not an actual library: it's a set of files that are installed by gobject-introspection, and you're supposed to build into a test library in your own bindings https://gitlab.gnome.org/GNOME/gobject-introspection/-/blob/main/tests/meson.build?ref_type=heads#L29-47 The Regress and GIMarshalling API are useful to check that your bindings are correct You also want to ask questions about g-i in the GNOME Introspection channel

I think we should also look into that.

vixalien commented 8 months ago

I am still working on this, and realised we need to build the "everything" library so that we're able to test that everything works.

This means there should be a build of the everything library so that we see that fields, properties, arrays, etc... all work. Not sure about which approach to take, but we will get this.

vixalien commented 8 months ago

Here's how to build the Everything library:

First Install dependencies

Clone the gobject-introspection library.

git clone https://gitlab.gnome.org/GNOME/gobject-introspection.git

Build gobject-introspection

cd gobject-introspection
meson setup build
ninja -C build

Build the "everything" library's GIR and typelib.

cd build/tests
g-ir-scanner everything.c everything.h --namespace Everything --library libeverything-1.0.so --warn-all -L$(pwd) $(pkg-config --cflags gobject-2.0) -I../../tests -o Everything-1.0.gir --nsversion 1.0
g-ir-compiler Everything-1.0.gir -o Everything-1.0.typelib

(optional) generate the documentation for the library

I find reading GIRs, not the most straightforward task, but thankfully we can use gi-docgen to generate an excellent web documentation

First write the following to the everything.toml file.

# SPDX-License-Identifier: LGPL-2.1-or-later
# Copyright 2024 Angelo Verlain

[library]
name = "Everything"
version = "1.0"
browse_url = "https://gitlab.gnome.org/GNOME/gobject-introspection/-/blob/main/tests"
repository_url = "https://gitlab.gnome.org/GNOME/gobject-introspection.git"
license = "LGPL-2.1-or-later"
description = "The Everything test library"

dependencies = [
  "GObject-2.0",
]

[dependencies."GObject-2.0"]
name = "GObject"
description = "The base type system library"
docs_url = "https://developer.gnome.org/gobject/stable"

Generate the docs.

gi-docgen generate -C everything.toml ./Everything-1.0.gir

Serve the docs.

python -m http.server -d Everything-1.0

next steps

the next step is to figure out how to use the Everything library for testing. We will probably need to add some environment variables so that gobject-introspection can see the library while it's not installed.

Then, we can test that each method works correctly (basically everything in the src/bindings directory).

We must also set up the Github Action workflow to follow these steps later.

vixalien commented 7 months ago

Just found out we can use GIRepository.prepend_search_path