Skip to content

Commit

Permalink
Unit tests for libdnf5::utils::[is_glob_pattern | is_file_pattern]
Browse files Browse the repository at this point in the history
Includes C++, Perl, Python and Ruby tests.
  • Loading branch information
jrohel authored and kontura committed Oct 4, 2024
1 parent f384048 commit 463742d
Show file tree
Hide file tree
Showing 6 changed files with 197 additions and 0 deletions.
44 changes: 44 additions & 0 deletions test/libdnf5/utils/test_patterns.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
Copyright Contributors to the libdnf project.
This file is part of libdnf: https://github.com/rpm-software-management/libdnf/
Libdnf 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.
Libdnf 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 libdnf. If not, see <https://www.gnu.org/licenses/>.
*/

#include "test_patterns.hpp"

#include <libdnf5/utils/patterns.hpp>

using namespace libdnf5::utils;

CPPUNIT_TEST_SUITE_REGISTRATION(UtilsPatternsTest);


void UtilsPatternsTest::test_is_file_pattern() {
CPPUNIT_ASSERT(!is_file_pattern(""));
CPPUNIT_ASSERT(!is_file_pattern("no_file_pattern"));
CPPUNIT_ASSERT(!is_file_pattern("no_file/pattern"));
CPPUNIT_ASSERT(is_file_pattern("/pattern"));
CPPUNIT_ASSERT(is_file_pattern("*/pattern"));
}


void UtilsPatternsTest::test_is_glob_pattern() {
CPPUNIT_ASSERT(!is_glob_pattern(""));
CPPUNIT_ASSERT(!is_glob_pattern("no_glob_pattern"));
CPPUNIT_ASSERT(is_glob_pattern("glob*_pattern"));
CPPUNIT_ASSERT(is_glob_pattern("glob[sdf]_pattern"));
CPPUNIT_ASSERT(is_glob_pattern("glob?_pattern"));
}
37 changes: 37 additions & 0 deletions test/libdnf5/utils/test_patterns.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
Copyright Contributors to the libdnf project.
This file is part of libdnf: https://github.com/rpm-software-management/libdnf/
Libdnf 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.
Libdnf 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 libdnf. If not, see <https://www.gnu.org/licenses/>.
*/

#ifndef LIBDNF5_TEST_UTILS_PATTERNS_HPP
#define LIBDNF5_TEST_UTILS_PATTERNS_HPP

#include <cppunit/TestCase.h>
#include <cppunit/extensions/HelperMacros.h>

class UtilsPatternsTest : public CppUnit::TestCase {
CPPUNIT_TEST_SUITE(UtilsPatternsTest);
CPPUNIT_TEST(test_is_file_pattern);
CPPUNIT_TEST(test_is_glob_pattern);
CPPUNIT_TEST_SUITE_END();

public:
void test_is_file_pattern();
void test_is_glob_pattern();
};

#endif // LIBDNF5_TEST_UTILS_PATTERNS_HPP
41 changes: 41 additions & 0 deletions test/perl5/libdnf5/utils/test_patterns.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Copyright Contributors to the libdnf project.
#
# This file is part of libdnf: https://github.com/rpm-software-management/libdnf/
#
# Libdnf 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.
#
# Libdnf 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 libdnf. If not, see <https://www.gnu.org/licenses/>.

use strict;
use warnings;

use Test::More;

use libdnf5::utils;

{
ok(!libdnf5::utils::is_file_pattern(''), 'is_file_pattern ""');
ok(!libdnf5::utils::is_file_pattern('no_file_pattern'), 'is_file_pattern "no_file_pattern"');
ok(!libdnf5::utils::is_file_pattern('no_file/pattern'), 'is_file_pattern "no_file/pattern"');
ok(libdnf5::utils::is_file_pattern('/pattern') == 1, 'is_file_pattern "/pattern"');
ok(libdnf5::utils::is_file_pattern('*/pattern') == 1, 'is_file_pattern "*/pattern"');
}

{
ok(!libdnf5::utils::is_glob_pattern(''), 'is_glob_pattern ""');
ok(!libdnf5::utils::is_glob_pattern('no_glob_pattern'), 'is_glob_pattern "no_glob_pattern"');
ok(libdnf5::utils::is_glob_pattern('glob*_pattern'), 'is_glob_pattern "glob*_pattern"');
ok(libdnf5::utils::is_glob_pattern('glob[sdf]_pattern') == 1, 'is_glob_pattern "glob[sdf]_pattern"');
ok(libdnf5::utils::is_glob_pattern('glob?_pattern') == 1, 'is_glob_pattern "glob?_pattern"');
}

done_testing()
Empty file.
36 changes: 36 additions & 0 deletions test/python3/libdnf5/utils/test_patterns.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Copyright Contributors to the libdnf project.
#
# This file is part of libdnf: https://github.com/rpm-software-management/libdnf/
#
# Libdnf 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.
#
# Libdnf 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 libdnf. If not, see <https://www.gnu.org/licenses/>.

import unittest

import libdnf5.utils


class TestIsXPattern(unittest.TestCase):
def test_is_file_pattern(self):
self.assertFalse(libdnf5.utils.is_file_pattern(''))
self.assertFalse(libdnf5.utils.is_file_pattern('no_file_pattern'))
self.assertFalse(libdnf5.utils.is_file_pattern('no_file/pattern'))
self.assertTrue(libdnf5.utils.is_file_pattern('/pattern'))
self.assertTrue(libdnf5.utils.is_file_pattern('*/pattern'))

def test_is_glob_pattern(self):
self.assertFalse(libdnf5.utils.is_glob_pattern(''))
self.assertFalse(libdnf5.utils.is_glob_pattern('no_glob_pattern'))
self.assertTrue(libdnf5.utils.is_glob_pattern('glob*_pattern'))
self.assertTrue(libdnf5.utils.is_glob_pattern('glob[sdf]_pattern'))
self.assertTrue(libdnf5.utils.is_glob_pattern('glob?_pattern'))
39 changes: 39 additions & 0 deletions test/ruby/libdnf5/utils/test_patterns.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Copyright Contributors to the libdnf project.
#
# This file is part of libdnf: https://github.com/rpm-software-management/libdnf/
#
# Libdnf 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.
#
# Libdnf 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 libdnf. If not, see <https://www.gnu.org/licenses/>.

require 'test/unit'
include Test::Unit::Assertions

require 'libdnf5/utils'

class TestIsXPattern < Test::Unit::TestCase
def test_is_file_pattern()
assert(!Utils::is_file_pattern(''))
assert(!Utils::is_file_pattern('no_file_pattern'))
assert(!Utils::is_file_pattern('no_file/pattern'))
assert(Utils::is_file_pattern('/pattern'))
assert(Utils::is_file_pattern('*/pattern'))
end

def test_is_glob_pattern()
assert(!Utils::is_glob_pattern(''))
assert(!Utils::is_glob_pattern('no_glob_pattern'))
assert(Utils::is_glob_pattern('glob*_pattern'))
assert(Utils::is_glob_pattern('glob[sdf]_pattern'))
assert(Utils::is_glob_pattern('glob?_pattern'))
end
end

0 comments on commit 463742d

Please sign in to comment.