repobee / repobee-sanitizer

A plugin for sanitizing master repositories before distribution to students
MIT License
2 stars 3 forks source link

Add test case for checking the syntax of an empty list #75

Closed slarse closed 4 years ago

slarse commented 4 years ago

A test just for check_syntax, which tests the corner case of an empty list (which corresponds to an empty file).

tohanss commented 4 years ago

One thing to do as well could be to just add an empty file to the invalid test case files

slarse commented 4 years ago

I think I had a reason for not doing that, but I can't recall what it was, so you could try it and see what happens.

tohanss commented 4 years ago

Ill keep the test, but this will not be a problem. We run the following code when sanitizing a file:

text = file_abs_path.read_text()
lines = text.split("\n")

So text becomes an empty string '' when we sanitize an empty file. Running text.split on that, however, makes lines a list containing an empty string [''] meaning lines[0] will not break if we have an empty list

slarse commented 4 years ago

Right, that's convenient. Might wanna put in an assert lines just to clarify that we actually expect it to be non-empty.

slarse commented 4 years ago

It's still a bit of an issue for check_syntax, however, as it's a public function in its module, and it will crash unexpectedly on being fed an empty list. It could potentially lead to unexpected issues down the line.