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

Test(git-brv): add unit test #1131

Open
vanpipy opened this issue Jan 26, 2024 · 5 comments
Open

Test(git-brv): add unit test #1131

vanpipy opened this issue Jan 26, 2024 · 5 comments
Assignees

Comments

@vanpipy
Copy link
Collaborator

vanpipy commented Jan 26, 2024

File

git-brv

Testcases

  1. If the repository has only one branch and its name is main, when invoke the git-brv command, the format of the result is {date} {branch_name} {upstream} {branch_short_hash} {commit_title_message} and output is just like 2024-01-05 main origin/main b54d8c7 test(git-browse): add unit tests (#1127)
  2. If the repository has multiple branches and the names are feature/2024-01-01, feature/2024-01-02, feature/2024-01-03 and suppose the branches created date are same to the branch name, when invoke the git-brv command, the result is
{date} feature/2024-01-03 {upstream} {branch_short_hash} {commit_title_message}
{date} feature/2024-01-02 {upstream} {branch_short_hash} {commit_title_message}
{date} feature/2024-01-01 {upstream} {branch_short_hash} {commit_title_message}
  1. Suppose the same as 2 and invoke the git-brv with --reverse argument, the result is
{date} feature/2024-01-01 {upstream} {branch_short_hash} {commit_title_message}
{date} feature/2024-01-02 {upstream} {branch_short_hash} {commit_title_message}
{date} feature/2024-01-03 {upstream} {branch_short_hash} {commit_title_message}

PS: It is a curious command, but I am more curious about the command name, what is the full name of the git-brv? The brv is not easy to explain the thing done with it.

Reference

@vanpipy vanpipy self-assigned this Jan 26, 2024
@vanpipy
Copy link
Collaborator Author

vanpipy commented Sep 29, 2024

Sorry for the late, and I will switch the pytest to shellspec cause do the code coverage generation hardly. I research lots of the existing unit test framework, then found the shellspec. It is suitable for our process to do unit test, but i will do more function testes and to rewrite the existing unit testes to test with it.

@hyperupcall
Copy link
Collaborator

hyperupcall commented Sep 29, 2024

@vanpipy What do you think about Bats? It's much more popular and more maintained (last release was in 2024 instead of shellspec's 2021). I'm really not personally a fan of shellspec's BDD-style tests, which I find hard to read and might discourage new contributors from adding to it. For code coverage for Bats, it looks like bashcov can be helpful.

To be honest, I have kind of been avoiding the pytest stuff in this repository because I had a difficult time working with it and reading it (compared to Bats). That made me wish I pushed for using Bats for testing a little harder.

If you are okay with switching to Bats (instead of shellspec) I would be able to help set things up! I've used Bats for dozens of projects so it's kind of like second-nature to me.

cc @spacewander

@spacewander
Copy link
Collaborator

I will vote for Bats too. It is used more widely.

@vanpipy
Copy link
Collaborator Author

vanpipy commented Sep 30, 2024

@vanpipy What do you think about Bats? It's much more popular and more maintained (last release was in 2024 instead of shellspec's 2021). I'm really not personally a fan of shellspec's BDD-style tests, which I find hard to read and might discourage new contributors from adding to it. For code coverage for Bats, it looks like bashcov can be helpful.

Yes, it is great one, i forget the starred one. It is the one choice i try to test.

bashcov it good for git-extras, but i took an error start point.. thanks a lot.

If you are okay with switching to Bats (instead of shellspec) I would be able to help set things up! I've used Bats for dozens of projects so it's kind of like second-nature to me.

Great, many thanks for this again. I think there is still a seperated test directory for the all unit tests. I will to do the research about the Bats together!

I think there are some concerns here,

  1. git-extras has the unit test files only
  2. Installing the bats easily when needed
  3. Good way or practice to extend the test utils

I have the answer for 1, but cannot answer the 2 and 3 even i review the bats document.

@hyperupcall
Copy link
Collaborator

@vanpipy Yes, there is still a separate test directory for all unit tests! About your concerns:

  1. If I understand correctly, we will probably continue to write unit files with Bats. Bats is not limited to just unit tests.
  2. I think we can give instructions in the CONTRIBUTING.md for installing Bats. Recent versions of Bats are easily downloadable on macOS with Homebrew. On Linux, Bats versions on the official repositories of Linux distributions are typically quite out of date, so we might have to recommend downloading a tarball of the latest release, and symlinking tarballs/bats-core/bin/bats to ~/.local/bin/bats or something like that
  3. With test utils, I usually put everything in a test_utils.sh file. (you can see a detailed explanation in the code i'll link down below)

I created a quick scaffold of what using Bats may look like for this project in this draft PR: #1170. I tried to add as many comments as possible explaining things. After reading the comments and Bats documentation, if you still have any other questions, let me know!

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

No branches or pull requests

3 participants