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

Refactor current tests and start to use assert_cmd #24

Merged
merged 23 commits into from Aug 1, 2018
Merged

Conversation

mssun
Copy link
Contributor

@mssun mssun commented Jul 12, 2018

This PR will refactor current test cases and change to assert_cmd, predicates, assert_fs, etc.

@codecov
Copy link

codecov bot commented Jul 13, 2018

Codecov Report

❗ No coverage uploaded for pull request base (master@d47ad31). Click here to learn what that means.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##             master      #24   +/-   ##
=========================================
  Coverage          ?   13.56%           
=========================================
  Files             ?       46           
  Lines             ?     4349           
  Branches          ?     1705           
=========================================
  Hits              ?      590           
  Misses            ?     3167           
  Partials          ?      592

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d47ad31...0c9293a. Read the comment docs.

@mssun mssun changed the title [WIP] Refactor current tests and change to assert_cli [WIP] Refactor current tests and change to assert_cmd Jul 13, 2018
@mssun
Copy link
Contributor Author

mssun commented Jul 15, 2018

@epage
Copy link

epage commented Jul 16, 2018

Blocking on a feature of assert_cmd (assert-rs/assert_cmd#24) to rewrite test cases of head.

Do you need to wait for that feature? The alternative is just to read the file and pass it in. The main benefits of that assert_cmd feature are (1) large file support and (2) convenience.

@mssun
Copy link
Contributor Author

mssun commented Jul 16, 2018

Do you need to wait for that feature? The alternative is just to read the file and pass it in. The main benefits of that assert_cmd feature are (1) large file support and (2) convenience.

Yes, reading file and pass it in is a solution. I think with the feature provided by assert_cmd, the testcases will looks more clean. (Current test framework supports pipe in a file). After that, I can safely say that assert_cmd have similar functions of current framework and fully rely on assert_cmd in the future.

Anyway, I will work on refactoring other test cases and come back to this when it is ready. @epage Do you think it will take much more time to have this feature done?

@epage
Copy link

epage commented Jul 16, 2018

Anyway, I will work on refactoring other test cases and come back to this when it is ready. @epage Do you think it will take much more time to have this feature done?

I probably won't get to it until tomorrow night. If that is too long, feel free to prepare a PR.

@Arcterus Arcterus mentioned this pull request Jul 18, 2018
new_cmd!()
.assert()
.success()
.stdout("x86_64\n")
Copy link

Choose a reason for hiding this comment

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

We're considering trimming whitespace for you.

Could you post your thoughts on assert-rs/assert_cmd#19

#[macro_export]
macro_rules! pred_str_contains {
($str:expr) => {
predicate::str::contains($str).from_utf8()
Copy link

Choose a reason for hiding this comment

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

RE from_utf8

Right now, the only automatic conversions that happen in our API are u8 slice to predicate and str to predicate.

Feel free to open an issue about converting Predicate<str> into Predicate<[u8]>. or any other ideas to simplify the use of the API.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, this one bother me a lot. I think it could work, but realize it doesn't when compile the code. It took me some time to find out the reason because the documentation of assert_cmd and predicates are mixed. I should check with these two docs.

Copy link

Choose a reason for hiding this comment

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

Could you open issues on any documentation problems you came across? We're wanting to make sure this is accessible for people starting a first Rust project to create a CLI. My challenge is the curse of knowledge: I'm too familiar with it to see know what pitfalls a new user will run into.

@mssun mssun changed the title [WIP] Refactor current tests and change to assert_cmd Refactor current tests and start to use assert_cmd Jul 31, 2018
@mssun
Copy link
Contributor Author

mssun commented Jul 31, 2018

I think I'm done with the refactoring. @Arcterus


#[test]
#[ignore]
fn test_chmod_reference_file() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add this back? It should be supported eventually (I just need to figure out how to get it to work with clap).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's OK, because I cannot test my rewrite right now. So, let's write test cases then when it's ready.

@Arcterus Arcterus merged commit 7c18432 into master Aug 1, 2018
@Arcterus
Copy link
Contributor

Arcterus commented Aug 1, 2018

The tests seem to run noticeably slower now, although this might just be due to fork+exec being slower than spawning a thread. On the other hand, it should be more resilient in the case of programs setting global state (e.g. we might be able to test the cd built-in for posix/sh now).

@mssun
Copy link
Contributor Author

mssun commented Aug 1, 2018

I don't why the first two cases are blocked.

test gnu::arch::test_x86_64 ... test gnu::arch::test_x86_64 has been running for over 60 seconds
test gnu::base32::test_decode ... test gnu::base32::test_decode has been running for over 60 seconds

Also, not sure if it is related with this issue: assert-rs/assert_cmd#6

@Arcterus
Copy link
Contributor

Arcterus commented Aug 1, 2018

Ah that may be related to some extent. Those test cases work fine for me locally so I’m not sure what’s up with Travis.

@mssun mssun deleted the tests/refactor branch August 1, 2018 23:32
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

3 participants