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 some CLI tests and workflow #18

Merged
merged 1 commit into from
Dec 4, 2022
Merged

Conversation

liubin
Copy link
Contributor

@liubin liubin commented Dec 3, 2022

This commit adds

  • release action to release tarball for downloading
  • run CI on pull request

And the release will be triggered by pushing a tag:

$ git tag v0.2.1
$ git push origin v0.2.1

Here is the created release: https://github.com/liubin/toml-cli/releases/tag/v0.2.1

Signed-off-by: bin liu [email protected]

@liubin
Copy link
Contributor Author

liubin commented Dec 3, 2022

As said in #13, as the start, this PR will add some basic CLI interface tests and workflow to test it on new pull requests.

@gnprice
Copy link
Owner

gnprice commented Dec 3, 2022

Excellent, thanks!

It's getting late here, so I'll look at this in more detail tomorrow. One quick high-level request: would you try splitting this up into a series of commits for the different pieces of what it does?

That would help me understand the dependencies between the different parts of this PR, which will help me better understand and review it.

For example, I think something like the following sequence will work:

  • add new tests
  • add Makefile
  • add GitHub workflow for CI
  • add GitHub workflow for building a tarball and creating a release
  • add Dockerfile and GitHub workflow job for publishing a Docker image

But I could easily be missing something — please vary that sequence however seems appropriate. The idea is that each commit should work correctly on its own, and then later commits can build on that.

Copy link
Owner

@gnprice gnprice left a comment

Choose a reason for hiding this comment

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

OK, I've read through the test changes. There's one issue described below; otherwise, they look good! Thanks again.

I've made a revision to this branch that splits out the tests as their own commit at the start, and also drops the change that has the issue below. I'll push that back to your PR branch in a moment.

How about splitting out the workflows and Makefile as another separate PR? Then I'll be glad to go ahead and merge that first commit that adds the tests.

I also have some ideas for how to refactor the new tests so they're simpler and more concise to write, which I think will also make it easier and more fun to write additional tests. After these tests are merged, I can try pushing some more commits to make those refactors.

test/test.rs Outdated
Comment on lines 16 to 22
fn get_exec_path() -> PathBuf {
// TODO is there no cleaner way to get this from Cargo?
// Also should it really be "debug"?
let target_dir: PathBuf = env::var_os("CARGO_TARGET_DIR")
.unwrap_or_else(|| OsString::from("target"))
.into();
target_dir.join("debug").join("toml")
Copy link
Owner

Choose a reason for hiding this comment

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

So as the comment here says, I'd be glad to find a way to simplify this bit of code. One thing this PR does is to replace it with something much simpler, namely the constant string "toml".

But when I run cargo test from the project directory after this change, these tests fail:

     Running test/test.rs (target/debug/deps/test-f800c5db31d9f226)

running 3 tests
test integration_test_help_if_no_args ... FAILED
test integration_test_cmd_set ... FAILED
test integration_test_cmd_get ... FAILED

failures:

---- integration_test_help_if_no_args stdout ----
thread 'integration_test_help_if_no_args' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 2, kind: NotFound, message: "No such file or directory" }', test/test.rs:10:56

---- integration_test_cmd_set stdout ----
thread 'integration_test_cmd_set' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 2, kind: NotFound, message: "No such file or directory" }', test/test.rs:59:10
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

---- integration_test_cmd_get stdout ----
thread 'integration_test_cmd_get' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 2, kind: NotFound, message: "No such file or directory" }', test/test.rs:30:10

It looks like in CI this would work because before running tests, it builds and then installs into /usr/local/bin/. But I think it's important to arrange things so that when you're developing changes, you can quickly run the tests on them with a simple command like cargo test. I believe we can accomplish that by continuing to use this get_exec_path function.

Signed-off-by: bin liu <[email protected]>
[split from larger commit; new commit message]
Signed-off-by: Greg Price <[email protected]>
@gnprice
Copy link
Owner

gnprice commented Dec 4, 2022

OK:

  • I'm going to go ahead and merge the new tests, because those are great and I'm eager to have them in. (Then I'll make those refactors I mentioned above, and can also extend the tests to cover new features.)

  • Before I do that, I'll update this PR branch so that it contains only that change. That's because I want the GitHub metadata to properly credit you by showing this PR as merged.

  • Would you send the other changes as a fresh PR? Those are changes I'm also quite interested in seeing in.

    See also my comment above at Add some CLI tests and workflow #18 (comment) — I'd like to see those changes split up into several commits, to help me better see what's going on.

@gnprice gnprice merged commit da7b78c into gnprice:master Dec 4, 2022
@gnprice
Copy link
Owner

gnprice commented Dec 4, 2022

And done. Thanks again @liubin!

Eager to see that split-up version of the CI, release, and Docker changes, whenever you have a chance to do so.

@gnprice
Copy link
Owner

gnprice commented Dec 4, 2022

And pushed those refactors -- take a look:
a4f3703 test [nfc]: Fix typos; cut one comment
a2da1e3 test [nfc]: Factor out run_toml
36ab021 test [nfc]: Say "out" for std::process::Output locals
b75795d test [nfc]: Factor out toml_success, toml_error
18fdcad test [nfc]: Factor out prep_file

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.

2 participants