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

Feature request: count lines of tests code #305

Open
gww-certik opened this issue Nov 25, 2021 · 8 comments
Open

Feature request: count lines of tests code #305

gww-certik opened this issue Nov 25, 2021 · 8 comments
Labels
enhancement New feature or request

Comments

@gww-certik
Copy link

Feature request: ability to count (maybe via optional flag --count-tests) lines of code that belong to tests.

@cycle20
Copy link

cycle20 commented Nov 25, 2021

Why don't you separate those analysis?
For example:

find src \
  -name "*.js" \
  -o -name "*.ts" \
  -o -name "*.php" \
  -o -name "*.bash" \
  | xargs scc
find test-e2e test-unit \
  -name "*.js" \
  -o -name "*.py" \
  -o -name "*.ts" \
  -o -name "*.php" \
  -o -name "*.bash" \
  | xargs scc

Furthermore --count-tests seems quite under-specified: there might be various project layouts and naming conventions.
Maybe *test* pattern can refer to test code hierarchy or a feature module of unit test framework, statistical library etc. in the name of a directory.

@gww-certik
Copy link
Author

In Rust tests are in same file , usually between :

#[cfg(test)]
mod tests {
...
}

https://doc.rust-lang.org/stable/rust-by-example/testing/unit_testing.html

@cycle20
Copy link

cycle20 commented Nov 27, 2021

In Rust tests are in same file , usually between :

Wow. Great. 🤔
Is it a legacy code?
Is there any chance to use integration tests instead of private testing of private code?
https://doc.rust-lang.org/stable/rust-by-example/testing/integration_testing.html

NOTE: I am not familiar with Rust at all.

@gww-certik
Copy link
Author

gww-certik commented Nov 27, 2021 via email

@boyter
Copy link
Owner

boyter commented Nov 29, 2021

Been thinking about this. I think it might be best served by what I was planning on doing eventually and have custom parsers for the more common file types. The reason being the languages.json works well for generic languages, but some such as Java, C, PHP, Python, Rust etc... could get some performance gains out of a specific parser for them.

In addition it would allow for some modifications such as this.

Now where I can see this being problematic is how it gets reported, as it would mean either reporting 2 lines in the output per language where this happens, or via adding a new column.

Consider the following,

$ scc --by-file
───────────────────────────────────────────────────────────────────────────────
Language                 Files     Lines   Blanks  Comments     Code Complexity
───────────────────────────────────────────────────────────────────────────────
Go                          53      9510     1370       809     7331       1358
───────────────────────────────────────────────────────────────────────────────
service/search.go                   1061      142       134      785        159
data/models/code.go                  736       72        13      651         71
service/search_test.go               434        8         0      426          2
service/background_cloner.go         431       73        45      313         92
index/caisson_test.go                420       75        25      320         63

Knowing where to put the new format is a problem there. Say I put the tests into service/search.go where should the test count go? I don't think another column is appropriate since tests can have blank lines or comments as well, but a new row is problematic too because where do the counts go? It also makes sorting a bit painful but thats not a huge issue.

Tokei might have the answer because it checks some language types for other languages and reports on them such as this,

$ tokei
===============================================================================
 Language            Files        Lines         Code     Comments       Blanks
===============================================================================
 HTML                   37         2021         1737           15          269
 |- JavaScript           2          366          295           13           58
 (Total)                           2387         2032           28          327

Which is a possibility although I am not sold on it. Its the best I can think of at the moment though.

@boyter boyter added the enhancement New feature or request label Nov 29, 2021
@gww-certik
Copy link
Author

gww-certik commented Dec 1, 2021 via email

@boyter
Copy link
Owner

boyter commented Oct 11, 2022

I just added the ability to exclude based on filename patterns, so for go you could exclude tests using the below

scc -n _test.go

You can also supply multiple

scc -n _test.go,main.go

The above would not count any main.go files or files containing _test.go.

Added because I needed it. But I thought it might be useful for this case as well. You will need to build off master to get this but if you are in a bind it might help.

@lcmgh
Copy link

lcmgh commented May 16, 2023

So far I could not find any tool that supports ignoring Rust test code so I am upvoting this.

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

No branches or pull requests

5 participants
@boyter @cycle20 @gww-certik @lcmgh and others