FaisalAfroz / lines-of-code-counter

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Exercism's Lines of Code Counter

Tests

This is Exercism's Lines of Code (LoC) Counter. It takes a solution and counts its lines of code.

Implementation

By default, we'll only count the LoC of files submitted by the student. If the student submitted a test file (which we identify via the files.test array in the exercise's .meta/config.json file), we'll ignore those.

Ignore additional files

While this works well for most submissions, it doesn't work if the submission's exercise has test files with a different naming scheme than the files listed in the .meta/config.json file. This can only really occur for submission that are linked to older exercises which didn't have a .meta/config.json file at the time.

To ignore additional files (like the above test files) from being included in the LoC count, each track can define a <slug>.ignore file inside the tracks directory (e.g. tracks/csharp.ignore). Inside this file, you can define rules to exclude certain file paths from the LoC count. The rules are matched using File.fnmatch, which uses standard globbing syntax.

As an example, the C# track excludes old *Test.cs files (renamed since to *Tests.cs) using the following ignore file:

*Test.cs

Run the Lines of Code Counter

To count the lines of code of an arbitrary solution, do the following:

  1. Open a terminal in the project's root
  2. Run ./bin/run.sh <track-slug> <submission-dir>

Once the test runner has finished, its results will be written to <submission-dir>/response.json.

Run the Lines of Code Counter on a solution using Docker

This script is provided for testing purposes, as it mimics how the Lines of Code Counter runs in Exercism's production environment.

To count the lines of code of an arbitrary solution using the Docker image, do the following:

  1. Open a terminal in the project's root
  2. Run ./bin/run-in-docker.sh <track-slug> <submission-dir>

Once the test runner has finished, its results will be written to <submission-dir>/response.json.

Run the tests

To run the tests to verify the behavior of the Lines of Code Counter, do the following:

  1. Open a terminal in the project's root
  2. Run ./bin/run-tests.sh

These are golden tests that compare the response.json generated by running the current state of the code against the "known good" tests/<test-name>/response.json. All files created during the test run itself are discarded.

When you've made modifications to the code that will result in a new "golden" state, you'll need to generate and commit a new tests/<test-name>/response.json file.

Run the tests using Docker

This script is provided for testing purposes, as it mimics how the Lines of Code Counter runs in Exercism's production environment.

To run the tests to verify the behavior of the test runner using the Docker image, do the following:

  1. Open a terminal in the project's root
  2. Run ./bin/run-tests-in-docker.sh

These are golden tests that compare the response.json generated by running the current state of the code against the "known good" tests/<test-name>/response.json. All files created during the test run itself are discarded.

When you've made modifications to the code that will result in a new "golden" state, you'll need to generate and commit a new tests/<test-name>/response.json file.

Credit

This repo is built and maintained by Exercism.

Contributions are welcome!

The actual counting of the LoC is done using the tokei tool, which is both extremely fast and supports many languages.

About

License:GNU Affero General Public License v3.0


Languages

Language:C# 31.4%Language:Shell 31.0%Language:F# 19.4%Language:Ruby 12.6%Language:Pony 3.1%Language:Dockerfile 2.5%