Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Report non existent file #69

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions rflint/parser/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,7 @@ def __init__(self, path, parent=None):
self.tables = []
self.rows = []

try:
self._load(path)
except Exception as e:
sys.stderr.write("there was a problem reading '%s': %s\n" % (path, str(e)))
self._load(path)

def walk(self, *types):
'''
Expand Down
10 changes: 6 additions & 4 deletions rflint/rflint.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,6 @@ def run(self, args):
self.counts = { ERROR: 0, WARNING: 0, "other": 0}

for filename in self.args.args:
if not (os.path.exists(filename)):
sys.stderr.write("rflint: %s: No such file or directory\n" % filename)
continue
if os.path.isdir(filename):
self._process_folder(filename)
else:
Expand Down Expand Up @@ -154,7 +151,12 @@ def _process_file(self, filename):
# we process the next file.
self._print_filename = filename if self.args.print_filenames else None

robot_file = RobotFactory(filename)
try:
robot_file = RobotFactory(filename)
except Exception as e:
self.report(filename=filename, rulename="RfLint",
message=str(e), severity=ERROR, linenumber=0, char=0)

for rule in self.general_rules:
if rule.severity != IGNORE:
rule.apply(robot_file)
Expand Down
42 changes: 42 additions & 0 deletions tests/acceptance/rules/NonExistentFile.robot
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
*** Settings ***
| Documentation | Tests for the rule 'InvalidTable'
| Resource | ../SharedKeywords.robot
|
| Test Teardown
| ... | Run keyword if | "${TEST STATUS}" == "FAIL"
| ... | log | ${result.stdout}\n${result.stderr}

*** Test Cases ***
| Report an error on non-existent file
| | [Documentation]
| | ... | Check an error is raised when specifying a file that
| | ... | does not exist
| |
| | [Setup] | Run rf-lint with the following options:
| | ... | test_data/does/not/exist.robot
| |
| | rflint return code should be | 1
| | rflint should report 1 errors
| | rflint should report 0 warnings
| |
| | Output should contain
| | ... | + test_data/does/not/exist.robot
| | ... | E: 0, 0: * No such file or directory* (RfLint)

| Report an error on non-existent file with custom format
| | [Documentation]
| | ... | Check an error is raised when specifying a file that
| | ... | does not exist, and that the error message is formatted
| | ... | according to custom rule
| |
| | [Setup] | Run rf-lint with the following options:
| | ... | --no-filename
| | ... | --format={severity}: {filename}:{linenumber}: {message}
| | ... | test_data/does/not/exist.robot
| |
| | rflint return code should be | 1
| | rflint should report 1 errors
| | rflint should report 0 warnings
| |
| | Output should contain
| | ... | E: test_data/does/not/exist.robot:0: * No such file or directory*
2 changes: 1 addition & 1 deletion tests/acceptance/rules/TooManyTestCases.robot
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
| | ... | --no-filename
| | ... | --ignore | all
| | ... | --error | TooManyTestCases
| | ... | ${SUITE SOURCE} | use this file as input
| | ... | ${SUITE SOURCE}
| |
| | rflint return code should be | 0
| | rflint should report 0 errors
Expand Down
2 changes: 1 addition & 1 deletion tests/acceptance/rules/TooManyTestSteps.robot
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
| | ... | --no-filename
| | ... | --ignore | all
| | ... | --error | TooManyTestSteps
| | ... | ${SUITE SOURCE} | use this file as input
| | ... | ${SUITE SOURCE}
| |
| | No operation
| | No operation
Expand Down
1 change: 0 additions & 1 deletion tests/acceptance/self-test.robot
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
| tests/acceptance/rules/TooManyTestSteps.robot | 0
| tests/acceptance/rules/LineTooLong.robot | 0
| tests/acceptance/rules/FileTooLong.robot | 0
| tests/acceptance/rules/TrailingBlankLines.robot | 0

*** Keywords ***
| Run rflint and verify there are no errors or warnings
Expand Down