Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pawamoy committed Dec 4, 2016
1 parent effe263 commit 4d08087
Show file tree
Hide file tree
Showing 6 changed files with 302 additions and 5 deletions.
6 changes: 4 additions & 2 deletions src/shellman/doc.py
Expand Up @@ -166,8 +166,10 @@ def read(self):
current_tag, value, end=True)
elif tag in TAGS.keys():
in_function = False
in_tag = self._update_value(
current_tag, value, end=True)
if (TAGS[tag].occurrences == Tag.MANY or
self.doc[tag] is None or in_tag):
in_tag = self._update_value(
current_tag, value, end=True)
else:
continue # ignore invalid tags
else:
Expand Down
11 changes: 11 additions & 0 deletions tests/fakescripts/doc_breaks.sh
@@ -0,0 +1,11 @@
#!/usr/bin/env bash

## \desc first line
## second line

## third line (ignored)

## \usage first line
## second line
echo "break"
## third line (ignored)
71 changes: 71 additions & 0 deletions tests/fakescripts/function_tags.sh
@@ -0,0 +1,71 @@
#!/usr/bin/env bash

## \fn first occurrence
## testing multi line

## \fn first occurrence
## testing multi line


## \brief first occurrence
## testing multi line

## \brief first occurrence
## testing multi line


## \desc first occurrence
## testing multi line

## \desc first occurrence
## testing multi line


## \param first occurrence
## testing multi line

## \param first occurrence
## testing multi line


## \pre first occurrence
## testing multi line

## \pre first occurrence
## testing multi line


## \return first occurrence
## testing multi line

## \return first occurrence
## testing multi line


## \seealso first occurrence
## testing multi line

## \seealso first occurrence
## testing multi line


## \stderr first occurrence
## testing multi line

## \stderr first occurrence
## testing multi line


## \stdin first occurrence
## testing multi line

## \stdin first occurrence
## testing multi line


## \stdout first occurrence
## testing multi line

## \stdout first occurrence
## testing multi line

154 changes: 154 additions & 0 deletions tests/fakescripts/script_tags.sh
@@ -0,0 +1,154 @@
#!/usr/bin/env bash

## \author first occurrence
## testing multi line

## \author second occurrence
## testing multi line


## \bug first occurrence
## testing multi line

## \bug second occurrence
## testing multi line


## \brief first occurrence
## testing multi line

## \brief second occurrence
## testing multi line


## \caveat first occurrence
## testing multi line

## \caveat second occurrence
## testing multi line


## \copyright first occurrence
## testing multi line

## \copyright second occurrence
## testing multi line


## \date first occurrence
## testing multi line

## \date second occurrence
## testing multi line


## \desc first occurrence
## testing multi line

## \desc second occurrence
## testing multi line


## \env first occurrence
## testing multi line

## \env second occurrence
## testing multi line


## \error first occurrence
## testing multi line

## \error second occurrence
## testing multi line


## \example first occurrence
## testing multi line

## \example second occurrence
## testing multi line


## \exit first occurrence
## testing multi line

## \exit second occurrence
## testing multi line


## \file first occurrence
## testing multi line

## \file second occurrence
## testing multi line


## \history first occurrence
## testing multi line

## \history second occurrence
## testing multi line


## \license first occurrence
## testing multi line

## \license second occurrence
## testing multi line


## \note first occurrence
## testing multi line

## \note second occurrence
## testing multi line


## \option first occurrence
## testing multi line

## \option second occurrence
## testing multi line


## \seealso first occurrence
## testing multi line

## \seealso second occurrence
## testing multi line


## \stderr first occurrence
## testing multi line

## \stderr second occurrence
## testing multi line


## \stdin first occurrence
## testing multi line

## \stdin second occurrence
## testing multi line


## \stdout first occurrence
## testing multi line

## \stdout second occurrence
## testing multi line


## \usage first occurrence
## testing multi line

## \usage second occurrence
## testing multi line


## \version first occurrence
## testing multi line

## \version second occurrence
## testing multi line
63 changes: 62 additions & 1 deletion tests/test_shellman.py
Expand Up @@ -9,8 +9,69 @@
"""Main test script."""

from shellman.cli import main
from shellman.doc import Doc
from shellman.tag import TAGS, Tag


def test_main():
"""Main test method."""
"""Assert that reading a file with few docs returns 0."""
assert main(['tests/fakescripts/minimal.sh']) == 0


# liste des tests possibles !

# lecture

# tags uniques : le dernier est conservé
# tags multiples : tous sont gardés
# multi lignes : toutes les lignes sont gardées
# instructions entre docs : ce qu'il y a après n'est pas gardé
# ligne vide entre docs : idem
# fonctions

# écriture

# vérifier que l'écriture se passe bien

class TestScriptTags(object):
fakescript = 'tests/fakescripts/script_tags.sh'
doc = Doc(fakescript).read()

def test_tags_correctly_read(self):
"""Assert all tags present in script are correctly read."""
for name, tag in TAGS.items():
assert self.doc[name]

def test_multiple_tags(self):
"""Assert that all occurrences of multiple tag are kept."""
for name, tag in TAGS.items():
if tag.occurrences == Tag.MANY:
assert isinstance(self.doc[name], list)
assert len(self.doc[name]) == 2
if tag.lines == Tag.MANY:
assert isinstance(self.doc[name][0], list)
assert isinstance(self.doc[name][1], list)
assert len(self.doc[name][0]) == 2
assert len(self.doc[name][1]) == 2
assert self.doc[name][0] == ['first occurrence\n',
'testing multi line\n']
assert self.doc[name][1] == ['second occurrence\n',
'testing multi line\n']
else:
assert isinstance(self.doc[name][0], str)
assert isinstance(self.doc[name][1], str)
assert self.doc[name][0] == 'first occurrence'
assert self.doc[name][1] == 'second occurrence'

def test_unique_tags(self):
"""Assert that only first occurrence of unique tag is kept."""
for name, tag in TAGS.items():
if tag.occurrences == 1:
if tag.lines == Tag.MANY:
assert isinstance(self.doc[name], list)
assert len(self.doc[name]) == 2
assert self.doc[name][0] == 'first occurrence\n'
assert self.doc[name][1] == 'testing multi line\n'
else:
assert isinstance(self.doc[name], str)
assert self.doc[name] == 'first occurrence'
2 changes: 0 additions & 2 deletions tox.ini
Expand Up @@ -47,8 +47,6 @@ commands =
isort --check-only --diff --recursive src tests setup.py
prospector -0 {toxinidir}



[testenv:codecov]
deps = codecov
skip_install = true
Expand Down

0 comments on commit 4d08087

Please sign in to comment.