Skip to content

Commit dcb0446

Browse files
nehebbgilbert
andauthored
meson: fix tests under Windows (#192)
* fix Windows tests Need to use find_program to see if we can run this. Signed-off-by: Rosen Penev <[email protected]> * github: add basic MSVC CI Signed-off-by: Rosen Penev <[email protected]> * Fix Windows tests from git-archive tarball diff fails when run from a tarball: the unittest programs produce CRLF line endings and baseline_*.txt in the tarball uses LF. Reproduce this in CI by preventing Git from converting the text files to CRLF, then ensure the unittest programs produce Unix line endings. --------- Signed-off-by: Rosen Penev <[email protected]> Co-authored-by: Benjamin Gilbert <[email protected]>
1 parent a22f5b7 commit dcb0446

File tree

7 files changed

+40
-4
lines changed

7 files changed

+40
-4
lines changed

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Ensure MSVC CI tests with the same line endings that are used in the tarball
2+
/tests/baseline_*.txt eol=lf

.github/workflows/tests.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@ jobs:
2424
build-meson:
2525
runs-on: ubuntu-latest
2626

27+
steps:
28+
- uses: actions/checkout@v4
29+
- uses: actions/setup-python@v5
30+
- uses: BSFishy/[email protected]
31+
with:
32+
action: test
33+
meson-version: 1.4.1
34+
build-meson-msvc:
35+
runs-on: windows-latest
36+
2737
steps:
2838
- uses: actions/checkout@v4
2939
- uses: actions/setup-python@v5

tests/meson.build

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
runtest = files(join_paths(meson.project_source_root(), 'tests', 'runtest.sh'))
1+
runtest = find_program('runtest.sh', required: false)
2+
if not runtest.found()
3+
subdir_done()
4+
endif
25

36
tests = {
47
'multi': { 'args': [] },

tests/runtest.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#!/usr/bin/env bash
1+
#!/bin/sh
22

3-
set -euo pipefail
3+
set -eu
44

55
cd "$(dirname "${1}")"
6-
diff "${1}" <("${2}")
6+
"$2" | diff "${1}" -

tests/unittest.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ respectively).
1313
#include <stdio.h>
1414
#include <stdlib.h>
1515
#include <string.h>
16+
#ifdef _WIN32
17+
#include <io.h>
18+
#include <fcntl.h>
19+
#endif
1620
#include "../ini.h"
1721

1822
int User;
@@ -62,6 +66,9 @@ void parse(const char* fname) {
6266

6367
int main(void)
6468
{
69+
#ifdef _WIN32
70+
_setmode(_fileno(stdout), _O_BINARY);
71+
#endif
6572
parse("no_file.ini");
6673
parse("normal.ini");
6774
parse("bad_section.ini");

tests/unittest_alloc.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
#include <stdio.h>
44
#include <stdlib.h>
55
#include <string.h>
6+
#ifdef _WIN32
7+
#include <io.h>
8+
#include <fcntl.h>
9+
#endif
610
#include "../ini.h"
711

812
void* ini_malloc(size_t size) {
@@ -44,6 +48,9 @@ void parse(const char* name, const char* string) {
4448

4549
int main(void)
4650
{
51+
#ifdef _WIN32
52+
_setmode(_fileno(stdout), _O_BINARY);
53+
#endif
4754
parse("basic", "[section]\nfoo = bar\nbazz = buzz quxx");
4855
return 0;
4956
}

tests/unittest_string.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
#include <stdio.h>
44
#include <stdlib.h>
55
#include <string.h>
6+
#ifdef _WIN32
7+
#include <io.h>
8+
#include <fcntl.h>
9+
#endif
610
#include "../ini.h"
711

812
int User;
@@ -33,6 +37,9 @@ void parse(const char* name, const char* string) {
3337

3438
int main(void)
3539
{
40+
#ifdef _WIN32
41+
_setmode(_fileno(stdout), _O_BINARY);
42+
#endif
3643
parse("empty string", "");
3744
parse("basic", "[section]\nfoo = bar\nbazz = buzz quxx");
3845
parse("crlf", "[section]\r\nhello = world\r\nforty_two = 42\r\n");

0 commit comments

Comments
 (0)