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

Add various tests for the library #114

Merged
merged 12 commits into from Jul 14, 2017
Merged

Add various tests for the library #114

merged 12 commits into from Jul 14, 2017

Conversation

neithernut
Copy link
Owner

Resolves #78.

@neithernut
Copy link
Owner Author

Meh. The CI fails for the old version because of language features which were unstable back then. As far as I can see, we have the following options:

  • Allow unstable features for old versions
  • Drop support for old versions
  • Disable tests for old versions

The first one would make sense, since we or libs we depend on might end up using now-stable features which were unstable before rust-1.17.0. However, at some point, we will drop support anyway as new versions of rust are released. Disabling tests doesn't make much sense, IMO.

Thoughts, @matthiasbeyer?

@neithernut
Copy link
Owner Author

Note: we'll also have to make Travis perform tests for libgitdit rather than for git-dit only.

@neithernut
Copy link
Owner Author

neithernut commented Jul 7, 2017

The Trailers iterator misbehaves. Apparently, the match clause in line 255 of trailer.rs does never encounter a plain line of text. I have yet to find out why.


Amend that. The problem appears to occur in the looping logic inside Trailers::next()


I apparently iterated over the Option returned by Iterator::next() at some point instead of the iterator itself -.-

@neithernut
Copy link
Owner Author

Note: I'll extract fixed from this PR into a separate one at some point.

Instead of iterating over all lines, we iterated only over one element
when scanning blocks. This lead to the algorithm only see a block of
text or trailers as a sequence of one-line blocks.

The resulting behaviour was the `Trailers` type not dumping lines which
looked like trailers but were embedded in blocks of texts. This commit
fixes the issue by properly iterating over all lines (until the next
blank one).
@neithernut
Copy link
Owner Author

Rebased due to CI fix.

#[should_panic]
fn malformed_message_format_check() {
vec!["Foo bar", "Baz"].into_iter().check_message_format().unwrap();
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you not using assert!() in the tests? If things do not panic (in the above tests) they might still not return what we would expect. Especially in this test case, if check_message_format() panics, we get a green test for this - which is clearly not valid!

assert!(vec[..].into_iter().check_message_format().is_err())

would be the way to go here.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point.

@neithernut
Copy link
Owner Author

The TestingRepo type I just introduced may be rebuild on basis of an in-memory key-value store once alexcrichton/git2-rs#222 is resolved.

pub fn repo(&mut self) -> &mut Repository {
&mut self.repo
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about implementing Drop to remove the repository after the test?

You could even make the removal dependent on an environment variable if you want to keep the repository after the test for debugging purposes.

Copy link
Owner Author

@neithernut neithernut Jul 9, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I originally planned implementing Drop then introducing TestingRepo. I didn't do it because I hoped it would be unnecessary to remove directories.

Well, keeping testing repos around has the advantage that it can be examined after a failure. If we implement the purging functionality in Drop and let users disable it for a single run, we may still have the repositories around in the next run. This would result in some tests failing.

Btw: if we migrate the testing repo to a key-value storage, we should implement Drop so that all objects are dumped to either stdout or some file, so we end up with something disectable after failed tests.

@neithernut neithernut changed the title [WIP] Add various tests for the library Add various tests for the library Jul 9, 2017
@neithernut
Copy link
Owner Author

Note: I originally intended extracting fixes resulting from this test-writing campaign. However, only a single bug surfaced and I think I'll keep the fix in this branch.

@neithernut
Copy link
Owner Author

@matthiasbeyer: could I get an ACK/comments?

@matthiasbeyer
Copy link
Collaborator

Not earlier than after my last exam + after the Party (so on friday, not earlier).

@neithernut
Copy link
Owner Author

Blocks #120 due to CI stuff.

Copy link
Collaborator

@matthiasbeyer matthiasbeyer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reviewed the tests and while I'm confused about expect() rather than assert!(...is_ok()), I can see that it is beneficial in most cases... and I don't care that much about the one or the other... so all I have to say is: GO! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants