This may happen in headless environments.

The return value of `gtk_init_check` was not examined before; according to 
[^1], _"calling any GTK function or instantiating any GTK type after this 
function returns FALSE results in undefined behavior."_

The value 77 can be returned to tell Automake that the test was skipped.[^2][^3]

---

Based on the example 
[here](https://www.gnu.org/software/automake/manual/automake.html#Use-TAP-with-the-Automake-test-harness),
 I assumed that Autotools would mark `test_sidebar` as `SKIP` if all test cases 
inside are marked as skipped using 
[`g_test_skip`](https://docs.gtk.org/glib/func.test_skip.html) despite the 
return value being `0`, but with the way it is plugged together (each binary 
being one test from the view of the harness without regard for the more 
granular test cases inside), this doesn't work without further ado:

`test_sidebar.log`:
```
TAP version 13
# random seed: R02Seafe1e22758e0c4a49fe548501665a2d
1..3
# Start of sidebar tests
ok 1 /sidebar/openfiles_none # SKIP Could not initizlize GTK, skipping. 
Headless environment?
ok 2 /sidebar/openfiles_path # SKIP Could not initizlize GTK, skipping. 
Headless environment?
ok 3 /sidebar/openfiles_tree # SKIP Could not initizlize GTK, skipping. 
Headless environment?
# End of sidebar tests
PASS test_sidebar (exit status: 0)
```

`test_sidebar.trs`:
```
:test-result: PASS
:global-test-result: PASS
:recheck: no
:copy-in-global-log: no
```

`geany-2.0/tests $ env TESTS="test_sidebar" make -e check SUBDIRS=`
```
PASS: test_sidebar
============================================================================
Testsuite summary for Geany 2.0
============================================================================
# TOTAL: 1
# PASS:  1
# SKIP:  0
# XFAIL: 0
# FAIL:  0
# XPASS: 0
# ERROR: 0
============================================================================
```

---

However, returning `77` works as intended:

`test_sidebar.log`:
```
GTK initialisation failed; skipping. Running inside a headless environment?
SKIP test_sidebar (exit status: 77)
```

`test_sidebar.trs`:
```
:test-result: SKIP
:global-test-result: SKIP
:recheck: no
:copy-in-global-log: yes
```

`geany-2.0/tests $ env TESTS="test_sidebar" make -e check SUBDIRS=`
```
SKIP: test_sidebar
============================================================================
Testsuite summary for Geany 2.0
============================================================================
# TOTAL: 1
# PASS:  0
# SKIP:  1
# XFAIL: 0
# FAIL:  0
# XPASS: 0
# ERROR: 0
============================================================================
```

Fixes #3674

[^1]: https://docs.gtk.org/gtk3/func.init_check.html
[^2]: 
https://www.gnu.org/software/automake/manual/automake.html#index-Exit-status-77_002c-special-interpretation
[^3]: https://docs.gtk.org/glib/func.test_run.html
You can view, comment on, or merge this pull request online at:

  https://github.com/geany/geany/pull/3676

-- Commit Summary --

  * Skip `tests/test_sidebar` if GTK initialisation fails

-- File Changes --

    M tests/test_sidebar.c (8)

-- Patch Links --

https://github.com/geany/geany/pull/3676.patch
https://github.com/geany/geany/pull/3676.diff

-- 
Reply to this email directly or view it on GitHub:
https://github.com/geany/geany/pull/3676
You are receiving this because you are subscribed to this thread.

Message ID: <geany/geany/pull/3...@github.com>

Reply via email to