Commit c7c07828 authored by Kirill Smelkov's avatar Kirill Smelkov

fmt: tests: Move into fmt_test.cpp from <- libgolang_test.cpp

parent 666bc325
...@@ -12,6 +12,7 @@ include golang/errors.h ...@@ -12,6 +12,7 @@ include golang/errors.h
include golang/errors.cpp include golang/errors.cpp
include golang/fmt.h include golang/fmt.h
include golang/fmt.cpp include golang/fmt.cpp
include golang/fmt_test.cpp
include golang/strings.h include golang/strings.h
include golang/strings.cpp include golang/strings.cpp
include golang/strings_test.cpp include golang/strings_test.cpp
......
/_context.cpp /_context.cpp
/_fmt_test.cpp
/_golang.cpp /_golang.cpp
/_golang_test.cpp /_golang_test.cpp
/_strings_test.cpp /_strings_test.cpp
......
# -*- coding: utf-8 -*-
# cython: language_level=2
# distutils: language=c++
#
# 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.
from __future__ import print_function, absolute_import
from golang cimport topyexc
# fmt_test.cpp
cdef extern from * nogil:
"""
extern void _test_fmt_sprintf_cpp();
extern void _test_fmt_errorf_cpp();
"""
void _test_fmt_sprintf_cpp() except +topyexc
void _test_fmt_errorf_cpp() except +topyexc
def test_fmt_sprintf_cpp():
with nogil:
_test_fmt_sprintf_cpp()
def test_fmt_errorf_cpp():
with nogil:
_test_fmt_errorf_cpp()
...@@ -228,8 +228,6 @@ cdef extern from * nogil: ...@@ -228,8 +228,6 @@ cdef extern from * nogil:
extern void _test_defer(); extern void _test_defer();
extern void _test_refptr(); extern void _test_refptr();
extern void _test_global(); extern void _test_global();
extern void _test_fmt_sprintf_cpp();
extern void _test_fmt_errorf_cpp();
""" """
void _test_chan_cpp_refcount() except +topyexc void _test_chan_cpp_refcount() except +topyexc
void _test_chan_cpp() except +topyexc void _test_chan_cpp() except +topyexc
...@@ -242,8 +240,6 @@ cdef extern from * nogil: ...@@ -242,8 +240,6 @@ cdef extern from * nogil:
void _test_defer() except +topyexc void _test_defer() except +topyexc
void _test_refptr() except +topyexc void _test_refptr() except +topyexc
void _test_global() except +topyexc void _test_global() except +topyexc
void _test_fmt_sprintf_cpp() except +topyexc
void _test_fmt_errorf_cpp() except +topyexc
def test_chan_cpp_refcount(): def test_chan_cpp_refcount():
with nogil: with nogil:
_test_chan_cpp_refcount() _test_chan_cpp_refcount()
...@@ -277,12 +273,6 @@ def test_refptr(): ...@@ -277,12 +273,6 @@ def test_refptr():
def test_global(): def test_global():
with nogil: with nogil:
_test_global() _test_global()
def test_fmt_sprintf_cpp(): # TODO move -> _fmt_test.pyx
with nogil:
_test_fmt_sprintf_cpp()
def test_fmt_errorf_cpp():
with nogil:
_test_fmt_errorf_cpp()
# helpers for pychan(dtype=X) py <-> c tests. # helpers for pychan(dtype=X) py <-> c tests.
......
// 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/fmt.h"
#include "golang/_testing.h"
using namespace golang;
void _test_fmt_sprintf_cpp() {
// NOTE not using vargs helper, since sprintf itself uses vargs and we want
// to test varg logic there for correctness too.
ASSERT_EQ(fmt::sprintf("hello world") , "hello world");
ASSERT_EQ(fmt::sprintf("hello %d zzz", 123) , "hello 123 zzz");
ASSERT_EQ(fmt::sprintf("%s %s: %s", "read", "myfile", "myerror") , "read myfile: myerror");
// with string format (not `const char *`)
const char *myerror = "myerror";
string f = "%s %s: %s";
const char *myfile = "myfile";
ASSERT_EQ(fmt::sprintf(f, "read", myfile, myerror) , "read myfile: myerror");
}
void _test_fmt_errorf_cpp() {
ASSERT_EQ(fmt::errorf("hello world")->Error() , "hello world");
ASSERT_EQ(fmt::errorf("hello %d zzz", 123)->Error() , "hello 123 zzz");
ASSERT_EQ(fmt::errorf("%s %s: %s", "read", "myfile", "myerror")->Error() , "read myfile: myerror");
// with string format (not `const char *`)
const char *myerror = "myerror";
string f = "%s %s: %s";
const char *myfile = "myfile";
ASSERT_EQ(fmt::errorf(f, "read", myfile, myerror)->Error() , "read myfile: myerror");
}
# -*- coding: utf-8 -*-
# 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.
from __future__ import print_function, absolute_import
from golang.golang_test import import_pyx_tests
import_pyx_tests("golang._fmt_test")
...@@ -20,7 +20,6 @@ ...@@ -20,7 +20,6 @@
// Test that exercises C++-level libgolang.h API and functionality. // Test that exercises C++-level libgolang.h API and functionality.
#include "golang/libgolang.h" #include "golang/libgolang.h"
#include "golang/fmt.h"
#include "golang/time.h" #include "golang/time.h"
#include <stdio.h> #include <stdio.h>
...@@ -676,31 +675,3 @@ void _test_global() { ...@@ -676,31 +675,3 @@ void _test_global() {
} }
ASSERT(obj->refcnt() == 3); ASSERT(obj->refcnt() == 3);
} }
// ---- fmt:: ----
void _test_fmt_sprintf_cpp() {
// NOTE not using vargs helper, since sprintf itself uses vargs and we want
// to test varg logic there for correctness too.
ASSERT_EQ(fmt::sprintf("hello world") , "hello world");
ASSERT_EQ(fmt::sprintf("hello %d zzz", 123) , "hello 123 zzz");
ASSERT_EQ(fmt::sprintf("%s %s: %s", "read", "myfile", "myerror") , "read myfile: myerror");
// with string format (not `const char *`)
const char *myerror = "myerror";
string f = "%s %s: %s";
const char *myfile = "myfile";
ASSERT_EQ(fmt::sprintf(f, "read", myfile, myerror) , "read myfile: myerror");
}
void _test_fmt_errorf_cpp() {
ASSERT_EQ(fmt::errorf("hello world")->Error() , "hello world");
ASSERT_EQ(fmt::errorf("hello %d zzz", 123)->Error() , "hello 123 zzz");
ASSERT_EQ(fmt::errorf("%s %s: %s", "read", "myfile", "myerror")->Error() , "read myfile: myerror");
// with string format (not `const char *`)
const char *myerror = "myerror";
string f = "%s %s: %s";
const char *myfile = "myfile";
ASSERT_EQ(fmt::errorf(f, "read", myfile, myerror)->Error() , "read myfile: myerror");
}
...@@ -251,6 +251,10 @@ setup( ...@@ -251,6 +251,10 @@ setup(
Ext('golang._context', Ext('golang._context',
['golang/_context.pyx']), ['golang/_context.pyx']),
Ext('golang._fmt_test',
['golang/_fmt_test.pyx',
'golang/fmt_test.cpp']),
Ext('golang._strings_test', Ext('golang._strings_test',
['golang/_strings_test.pyx', ['golang/_strings_test.pyx',
'golang/strings_test.cpp']), 'golang/strings_test.cpp']),
......
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