Skip to content

Commit a268b24

Browse files
authored
Merge pull request #140 from grische/feature/github-ci
add Github Actions CI
2 parents e6978af + 7da184c commit a268b24

File tree

2 files changed

+65
-4
lines changed

2 files changed

+65
-4
lines changed

.github/workflows/node-tests.yml

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
---
2+
name: json-to-go tests
3+
4+
on: # yamllint disable-line rule:truthy
5+
workflow_call:
6+
workflow_dispatch:
7+
push:
8+
branches:
9+
- "master"
10+
- "main"
11+
pull_request:
12+
13+
jobs:
14+
run-tests:
15+
runs-on: ubuntu-latest
16+
strategy:
17+
matrix:
18+
node-version: [12.x, 14.x, 16.x, 18.x, 20.x, 22.x]
19+
20+
steps:
21+
- uses: actions/checkout@v4
22+
- name: Use Node.js ${{ matrix.node-version }}
23+
uses: actions/setup-node@v4
24+
with:
25+
node-version: ${{ matrix.node-version }}
26+
27+
- name: Run tests
28+
run: |
29+
node json-to-go.test.js
30+
31+
- name: Run json-to-go using stdin
32+
shell: bash
33+
run: |
34+
set -eEuo pipefail
35+
got=$(node json-to-go.js < tests/double-nested-objects.json)
36+
exp=$(cat tests/double-nested-objects.go)
37+
echo "got: '${got}'"
38+
[[ "${got}" == "${exp}" ]]
39+
40+
- name: Run json-to-go with -big using stdin
41+
shell: bash
42+
run: |
43+
set -eEuo pipefail
44+
got=$(node json-to-go.js -big < tests/double-nested-objects.json)
45+
exp=$(cat tests/double-nested-objects.go)
46+
echo "got: '${got}'"
47+
[[ "${got}" == "${exp}" ]]
48+
49+
- name: Run json-to-go with a file
50+
shell: bash
51+
run: |
52+
set -eEuo pipefail
53+
got=$(node json-to-go.js tests/double-nested-objects.json)
54+
exp=$(cat tests/double-nested-objects.go)
55+
echo "got: '${got}'"
56+
[[ "${got}" == "${exp}" ]]

json-to-go.test.js

+9-4
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,14 @@ function test(includeExampleData) {
141141
const got = jsonToGo(testCase.input, null, null, includeExampleData);
142142
if (got.error) {
143143
console.assert(!got.error, `format('${testCase.input}'): ${got.error}`);
144+
process.exitCode = 16
144145
} else {
145146
const exp = includeExampleData ? testCase.expectedWithExample : testCase.expected
146-
console.assert(
147-
got.go === exp,
147+
const success = got.go === exp
148+
console.assert(success,
148149
`format('${testCase.input}'): \n\tgot: ${quote(got.go)}\n\twant: ${quote(exp)}`
149150
);
151+
if(!success) process.exitCode = 17
150152
}
151153
}
152154
console.log(includeExampleData ? "done testing samples with data" : "done testing samples without data")
@@ -169,14 +171,17 @@ function testFiles() {
169171
const got = jsonToGo(jsonData);
170172
if (got.error) {
171173
console.assert(!got.error, `format('${jsonData}'): ${got.error}`);
174+
process.exitCode = 18
172175
} else {
173-
console.assert(
174-
got.go === expectedGoData,
176+
const success = got.go === expectedGoData
177+
console.assert(success,
175178
`format('${jsonData}'): \n\tgot: ${quote(got.go)}\n\twant: ${quote(expectedGoData)}`
176179
);
180+
if(!success) process.exitCode = 19
177181
}
178182
} catch (err) {
179183
console.error(err);
184+
process.exitCode = 20
180185
}
181186
}
182187
console.log("done testing files")

0 commit comments

Comments
 (0)