Skip to content

Commit

Permalink
Add tests and Github workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
za-arthur committed Jan 16, 2024
1 parent 902098a commit 1730ed5
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 0 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: CI

on:
push:
branches:
- master
- main
pull_request:

jobs:
test:
strategy:
matrix:
pg: [16, 15, 14, 13, 12, 11, 10]
name: 🐘 PostgreSQL ${{ matrix.pg }}
runs-on: ubuntu-latest
container: pgxn/pgxn-tools
steps:
- run: pg-start ${{ matrix.pg }}
- uses: actions/checkout@v2
- run: pg-build-test
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@ OBJS = $(patsubst %.c,%.o,$(wildcard src/*.c))

PGXS := $(shell $(PG_CONFIG) --pgxs)

TESTS = $(sort $(wildcard test/sql/*.sql))
REGRESS = $(patsubst test/sql/%.sql,%,$(TESTS))
REGRESS_OPTS = --inputdir=test --outputdir=test

include $(PGXS)
9 changes: 9 additions & 0 deletions src/saturated_int.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
#include <limits.h>

#include "utils/builtins.h"
#if PG_VERSION_NUM < 150000
#include "utils/int8.h"
#endif

PG_MODULE_MAGIC;

Expand Down Expand Up @@ -36,7 +39,13 @@ sat_int4_in(PG_FUNCTION_ARGS)
{
char *arg = PG_GETARG_CSTRING(0);

#if PG_VERSION_NUM < 150000
int64 result;
(void) scanint8(arg, false, &result);
PG_RETURN_INT32(sat_int8to4_impl(result));
#else
PG_RETURN_INT32(sat_int8to4_impl(pg_strtoint64(arg)));
#endif
}

/*
Expand Down
7 changes: 7 additions & 0 deletions test/expected/001_saturated_int.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
create extension saturated_int;
select 2147483648::saturated_int;
saturated_int
---------------
2147483647
(1 row)

3 changes: 3 additions & 0 deletions test/sql/001_saturated_int.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
create extension saturated_int;

select 2147483648::saturated_int;

0 comments on commit 1730ed5

Please sign in to comment.