Commit 617b51b2 authored by Kirill Smelkov's avatar Kirill Smelkov

sync: tests: Move into sync_test.cpp from <- libgolang_test.cpp

parent ff2ed5fe
......@@ -16,6 +16,7 @@ include golang/strings.h
include golang/strings.cpp
include golang/sync.h
include golang/sync.cpp
include golang/sync_test.cpp
include golang/time.h
include golang/time.cpp
include golang/_testing.h
......
......@@ -235,7 +235,6 @@ cdef extern from * nogil:
extern void _test_strings_has_suffix();
extern void _test_strings_trim_suffix();
extern void _test_strings_split();
extern void _test_sync_once_cpp();
"""
void _test_chan_cpp_refcount() except +topyexc
void _test_chan_cpp() except +topyexc
......@@ -255,7 +254,6 @@ cdef extern from * nogil:
void _test_strings_has_suffix() except +topyexc
void _test_strings_trim_suffix() except +topyexc
void _test_strings_split() except +topyexc
void _test_sync_once_cpp() except +topyexc
def test_chan_cpp_refcount():
with nogil:
_test_chan_cpp_refcount()
......@@ -310,9 +308,6 @@ def test_strings_trim_suffix():
def test_strings_split():
with nogil:
_test_strings_split()
def test_sync_once_cpp(): # TODO move -> _sync_test.pyx
with nogil:
_test_sync_once_cpp()
# helpers for pychan(dtype=X) py <-> c tests.
......
......@@ -174,3 +174,14 @@ cdef void _test_once() nogil except +topyexc:
def test_once():
with nogil:
_test_once()
# sync_test.cpp
cdef extern from * nogil:
"""
extern void _test_sync_once_cpp();
"""
void _test_sync_once_cpp() except +topyexc
def test_sync_once_cpp():
with nogil:
_test_sync_once_cpp()
......@@ -22,7 +22,6 @@
#include "golang/libgolang.h"
#include "golang/fmt.h"
#include "golang/strings.h"
#include "golang/sync.h"
#include "golang/time.h"
#include <stdio.h>
......@@ -800,25 +799,3 @@ void _test_strings_split() {
ASSERT_EQ(strings::split(" ab cd e" , ' ') , V({"", "ab", "cd", "e"}));
ASSERT_EQ(strings::split(" ab cd e" , ' ') , V({"", "", "ab", "cd", "e"}));
}
// ---- sync:: ----
// verify that sync::Once works.
void _test_sync_once_cpp() {
sync::Once once;
int ncall = 0;
ASSERT(ncall == 0);
once.do_([&]() {
ncall++;
});
ASSERT(ncall == 1);
once.do_([&]() {
ncall++;
});
ASSERT(ncall == 1);
once.do_([&]() {
ncall++;
panic("should not panic");
});
ASSERT(ncall == 1);
}
// Copyright (C) 2019-2020 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com>
//
// This program is free software: you can Use, Study, Modify and Redistribute
// it under the terms of the GNU General Public License version 3, or (at your
// option) any later version, as published by the Free Software Foundation.
//
// You can also Link and Combine this program with other software covered by
// the terms of any of the Free Software licenses or any of the Open Source
// Initiative approved licenses and Convey the resulting work. Corresponding
// source of such a combination shall include the source code for all other
// software used.
//
// This program is distributed WITHOUT ANY WARRANTY; without even the implied
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//
// See COPYING file for full licensing terms.
// See https://www.nexedi.com/licensing for rationale and options.
#include "golang/sync.h"
#include "golang/_testing.h"
using namespace golang;
// verify that sync::Once works.
void _test_sync_once_cpp() {
sync::Once once;
int ncall = 0;
ASSERT(ncall == 0);
once.do_([&]() {
ncall++;
});
ASSERT(ncall == 1);
once.do_([&]() {
ncall++;
});
ASSERT(ncall == 1);
once.do_([&]() {
ncall++;
panic("should not panic");
});
ASSERT(ncall == 1);
}
......@@ -256,7 +256,8 @@ setup(
dsos = ['golang.runtime.libpyxruntime'],
define_macros = [('_LIBGOLANG_SYNC_INTERNAL_API', None)]),
Ext('golang._sync_test',
['golang/_sync_test.pyx']),
['golang/_sync_test.pyx',
'golang/sync_test.cpp']),
Ext('golang._time',
['golang/_time.pyx'],
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment