Something with unittests.

main
Ben Niemann 2021-10-16 16:40:22 +02:00
parent 7e5718d9b5
commit 105ab5d05a
9 changed files with 164 additions and 20 deletions

View File

@ -1,9 +1,3 @@
; TODO:
; - add shortcuts to run tests
; - add tweaks to C++ indentation
; - no indentation for namespace
; - correct indentation for arg list continuation
((nil . (
; Projetile
(projectile-project-test-cmd . "./waf test")
@ -16,6 +10,9 @@
; Be more generous than 80 columns.
(fill-column . 100)
; Do not indent body of namespaces.
(eval . (add-to-list 'c-offsets-alist '(innamespace . 0)))
; Highlight tabs, so they don't slip in unnoticed.
; TODO: make this work correctly
; - should only show leading tabs

View File

@ -18,13 +18,16 @@
#
# @end:license
{ lib
, stdenv
, fetchFromGitHub
, python3
, wafHook
{ lib,
stdenv,
fetchFromGitHub,
python3,
wafHook,
gtest
}:
let
# gitignoreSource: Nix functions for filtering local git sources
# https://github.com/hercules-ci/gitignore.nix
gitignoreSrc = fetchFromGitHub {
owner = "hercules-ci";
repo = "gitignore.nix";
@ -41,5 +44,6 @@ in stdenv.mkDerivation {
nativeBuildInputs = [
python3
wafHook
gtest.dev
];
}

30
src/core/backend.cpp Normal file
View File

@ -0,0 +1,30 @@
/*
* @begin:license
*
* Copyright (c) 2015-2021, Ben Niemann <pink@odahoda.de>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* @end:license
*/
namespace noisicaa {
int back_me(int a) {
return a + 1;
}
} // namespace noisicaa

28
src/core/backend.h Normal file
View File

@ -0,0 +1,28 @@
/*
* @begin:license
*
* Copyright (c) 2015-2021, Ben Niemann <pink@odahoda.de>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* @end:license
*/
namespace noisicaa {
int back_me(int a);
} // namespace noisicaa

42
src/core/backend_test.cpp Normal file
View File

@ -0,0 +1,42 @@
/*
* @begin:license
*
* Copyright (c) 2015-2021, Ben Niemann <pink@odahoda.de>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* @end:license
*/
#include "gtest/gtest.h"
#include "backend.h"
namespace noisicaa {
namespace {
class BackendTest : public ::testing::Test {};
TEST_F(BackendTest, BackMe) {
EXPECT_EQ(back_me(2), 3);
}
} // namespace
} // namespace noisicaa
int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

View File

@ -1,7 +0,0 @@
#include <iostream>
int main() {
std::cout << "hello world\n";
return 0;
}

32
src/core/noisicaa-core.h Normal file
View File

@ -0,0 +1,32 @@
// -*- mode: c++ -*-
/*
* @begin:license
*
* Copyright (c) 2015-2021, Ben Niemann <pink@odahoda.de>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* @end:license
*/
#ifndef _NOISICAA_CORE_H
#define _NOISICAA_CORE_H
namespace noisicaa {
} // namespace noisicaa
#endif

View File

@ -20,5 +20,17 @@
def build(ctx):
ctx.program(source='hello.cpp', target='hello')
ctx.stlib(
target='noisicaa-core',
source=[
'backend.cpp',
],
)
ctx.program(
features='test',
target='backend_test',
source='backend_test.cpp',
linkflags='-lgtest',
use='noisicaa-core',
)

View File

@ -24,11 +24,17 @@ out = 'build'
def options(ctx):
ctx.load('compiler_cxx')
ctx.load('waf_unit_test')
def configure(ctx):
ctx.load('compiler_cxx')
ctx.check(header_name='stdio.h', features='cxx cxxprogram', mandatory=False)
ctx.load('waf_unit_test')
ctx.check(header_name='stdio.h', features='cxx cxxprogram', mandatory=True)
ctx.check(header_name='gtest/gtest.h', features='cxx cxxprogram', mandatory=True)
def build(ctx):
ctx(rule='touch ${TGT}', target='.nobackup')
ctx.recurse('src')
from waflib.Tools import waf_unit_test
ctx.add_post_fun(waf_unit_test.summary)