Skip to content

Commit

Permalink
Merge pull request #32 from ansasaki/check
Browse files Browse the repository at this point in the history
Add check subcommand

Fixes #28
  • Loading branch information
ansasaki committed Apr 24, 2018
2 parents dbd9548 + df4a78a commit 5994f4a
Show file tree
Hide file tree
Showing 17 changed files with 509 additions and 4 deletions.
52 changes: 49 additions & 3 deletions src/symbol_version/symbol_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -1086,6 +1086,19 @@ def update(args):
unified in a new release. This is an incompatible change, the SONAME
of the library should be bumped
If --symbols is provided, the symbols provided are considered all the
exported symbols in the new version. Such set of symbols is compared to the
previous existing symbols. If symbols are added, but nothing removed, it is
a compatible change. Otherwise, it is an incompatible change and the SONAME
of the library should be bumped.
If --add is provided, the symbols provided are considered new symbols to be
added. This is a compatible change.
If --remove is provided, the symbols provided are considered the symbols to
be removed. This is an incompatible change and the SONAME of the library
should be bumped.
:param args: Arguments given in command line parsed by argparse
"""

Expand Down Expand Up @@ -1291,7 +1304,7 @@ def update(args):

def new(args):
"""
\'new\' subcommand implementation
\'new\' subcommand
Create a new version script file containing the provided symbols.
Expand Down Expand Up @@ -1398,6 +1411,33 @@ def new(args):
# warnings.warn(msg)


def check(args):
"""
\'check\' subcommand
Check the content of a symbol version script
:param args: Arguments given in command line parsed by argparse
"""

# Get logger
logger = Single_Logger.getLogger(__name__, filename=args.logfile)

logger.info("Command: check")
logger.debug("Arguments provided: ")
logger.debug(str(args))

# Set the verbosity if provided
if args.verbosity:
logger.setLevel(VERBOSITY_MAP[args.verbosity])

# Read the map file
smap = Map(filename=args.file, logger=logger)

# Check the map file
smap.check()


def get_arg_parser():
"""
Get a parser for the command line arguments
Expand All @@ -1417,8 +1457,6 @@ def get_arg_parser():
file_args.add_argument('-d', '--dry',
help='Do everything, but do not modify the files',
action='store_true')
file_args.add_argument('-l', '--logfile',
help='Log to this file')

# Common verbosity arguments
verb_args = argparse.ArgumentParser(add_help=False)
Expand All @@ -1432,6 +1470,8 @@ def get_arg_parser():
const='quiet')
group_verb.add_argument('--debug', help='Makes the program print debug info',
dest='verbosity', action='store_const', const='debug')
verb_args.add_argument('-l', '--logfile',
help='Log to this file')

# Common release name arguments
name_args = argparse.ArgumentParser(add_help=False)
Expand Down Expand Up @@ -1494,6 +1534,12 @@ def get_arg_parser():
" symbols are read from stdin.")
parser_new.set_defaults(func=new)

# Check subcommand parser
parser_check = subparsers.add_parser("check", help="Check the map file",
parents=[verb_args])
parser_check.add_argument("file", help="The map file to be checked")
parser_check.set_defaults(func=check)

return parser


Expand Down
17 changes: 16 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ def datadir(tmpdir, request):
Fixture responsible for searching a folder with the same name of test
module in the \'data\' directory and, if available, moving all contents
to a temporary directory so tests can use them freely.
:param tmpdir: fixture which creates a temporary directory
:param request: the test request context
"""

filename = request.module.__file__
Expand All @@ -37,6 +40,9 @@ def datadir(tmpdir, request):
def testcases(datadir, capsys):
"""
Returns the test cases for a given test
:param datadir: fixture which gives a temporary dir with the test files
:param capsys: fixture which captures the outputs to stderr and stdout
"""

input_list = datadir.listdir()
Expand All @@ -60,7 +66,15 @@ def testcases(datadir, capsys):


class cd:
"""Class used to manage the working directory"""
"""
Class used to manage the working directory
Use as context manager::
with cd(datadir):
# Here you are in the temporary working directory
"""

def __init__(self, new_path):
self.new_path = str(new_path)
Expand All @@ -80,6 +94,7 @@ def run_tc(tc, datadir, capsys, caplog):
:param tc: The tescase
:param datadir: The path to the directory where the test input are
:param capsys: The output capture fixture
:param caplog: The log capture fixture
"""

# Change directory to the temporary directory
Expand Down
7 changes: 7 additions & 0 deletions tests/data/test_check/baseless.map
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Map without base release and without wildcard

BASELESS_1_0_0
{
global:
one_symbol;
} ;
175 changes: 175 additions & 0 deletions tests/data/test_check/broken_maps.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
# Testing broken map files (some just give warnings)
-
input:
args:
- "check"
- "nameless.map"
stdin:
output:
file:
stdout:
warnings:
exceptions:
- "Invalid Release identifier"
-
input:
args:
- "check"
- "duplicated.map"
stdin:
output:
file:
stdout:
warnings:
- "Duplicated Release identifier"
exceptions:
-
input:
args:
- "check"
- "opening.map"
stdin:
output:
file:
stdout:
warnings:
exceptions:
- "Missing '{'"
-
input:
args:
- "check"
- "invalid_element.map"
stdin:
output:
file:
stdout:
warnings:
exceptions:
- "Invalid identifier"
-
input:
args:
- "check"
- "missing_semicolon.map"
stdin:
output:
file:
stdout:
warnings:
exceptions:
- "Missing ';' or ':' after"
-
input:
args:
- "check"
- "missing_visibility.map"
stdin:
output:
file:
stdout:
warnings:
- "Missing visibility scope before"
- "Symbols considered in 'global:'"
exceptions:
-
input:
args:
- "check"
- "invalid_previous.map"
stdin:
output:
file:
stdout:
warnings:
exceptions:
- "Invalid identifier"
-
input:
args:
- "check"
- "missing_previous_closer.map"
stdin:
output:
file:
stdout:
warnings:
exceptions:
- "Missing ';'"
-
input:
args:
- "check"
- "non_existing_previous.map"
stdin:
output:
file:
stdout:
warnings:
exceptions:
- "Release 'LIBTC5_8_0_0' not found"
-
input:
args:
- "check"
- "duplicated_dependency.map"
stdin:
output:
file:
stdout:
warnings:
- "Duplicated Release identifier 'LIBTC5_9_0_0'"
exceptions:
- "defined more than 1 release 'LIBTC5_9_0_0'"
-
input:
args:
- "check"
- "circular_dependency.map"
stdin:
output:
file:
stdout:
warnings:
exceptions:
- "Circular dependency detected!"
-
input:
args:
- "check"
- "wildcard_warnings.map"
stdin:
output:
file:
stdout:
warnings:
- "NOTBASE_1_1_0 should not contain the local wildcard because it is \
not the base version (it refers to version BASE_1_0_0 as its \
predecessor)"
- "GLOBAL_WILDCARD_1_2_0 contains the '*' wildcard in global scope. \
It is probably exporting symbols it should not."
- "SCOPES_1_3_0contains unknown scope named scope (different from \
'global' and 'local')"
- "The '*' wildcard was found in more than one place:"
- " NOTBASE_1_1_0: in 'local'"
- " BASE_1_0_0: in 'local'"
- " GLOBAL_WILDCARD_1_2_0: in 'global'"
- " OTHER_BASE_1_0_0: in 'local'"
- "More than one release seems the base version (contains the local \
wildcard and does not have a predecessor version):"
- " BASE_1_0_0"
- " OTHER_BASE_1_0_0"
exceptions:
-
input:
args:
- "check"
- "baseless.map"
stdin:
output:
file:
stdout:
warnings:
- "The '*' wildcard was not found"
- "No base version release found"
exceptions:
28 changes: 28 additions & 0 deletions tests/data/test_check/circular_dependency.map
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Broken map with circular dependency

LIBTC5_9_2_0
{
global:
one_symbol;
} LIBTC5_9_1_0;

LIBTC5_9_1_0
{
global:
two_symbol;
} LIBTC5_9_0_0;

LIBTC5_9_0_0
{
global:
three_symbol;
} LIBTC5_9_2_0;

LIBBASE_1_0_0
{
global:
zero_symbol;
local:
*;
} ;

18 changes: 18 additions & 0 deletions tests/data/test_check/duplicated.map
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Broken map with duplicated releases
# This is non-critical, only warning generated

LIBTC5_1_0_0
{
global:
other_symbol;
local:
*;
} ;

LIBTC5_1_0_0
{
global:
some_symbol;
local:
*;
} ;
23 changes: 23 additions & 0 deletions tests/data/test_check/duplicated_dependency.map
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Broken map with duplicated dependency

LIBTC5_9_1_0
{
global:
other_symbol;
} LIBTC5_9_0_0;

LIBTC5_9_0_0
{
global:
another_symbol;
local:
*;
} ;

LIBTC5_9_0_0
{
global:
one_more_symbol;
local:
*;
} ;
Loading

0 comments on commit 5994f4a

Please sign in to comment.