This is a simple C++ command-line tool to count lines of code in a given directory. It can distinguish between total lines, blank lines, comment lines, and code lines for various programming languages.
- Counts total lines, blank lines, comment lines, and code lines.
- Supports C++, Markdown, and Text files.
- Provides a per-file report or a summary report for the entire directory.
- Easily extendable to support more languages.
- C++17 compiler
- CMake 3.10 or higher
- Clone the repository:
git clone <repository-url>
- Navigate to the project directory:
cd code_counter
- Create a build directory:
mkdir build && cd build
- Run CMake to configure the project:
cmake ..
- Build the project:
cmake --build .
To run the code counter, execute the following command from the build directory:
./code_counter <directory_path> [--per-file]<directory_path>: The path to the directory you want to analyze.--per-file: (Optional) A flag to display a detailed report for each file.
The project includes a suite of unit tests to verify the functionality of the FileParser class. The tests are written using the Google Test framework and are located in the tests directory.
The current tests cover the following scenarios:
- Verifying that the
FileParsercorrectly identifies C++ source and header files (.cpp,.h). - Verifying that the
FileParsercorrectly identifies Markdown files (.md). - Verifying that the
FileParsercorrectly identifies text files (.txt).
To run the unit tests, execute the following command from the build directory:
ctestNote for Windows Users (MinGW):
If you are using MinGW on Windows, you might encounter an error where ctest cannot find the necessary runtime DLLs. If this happens, you can temporarily add the MinGW bin directory to your PATH for the current PowerShell session before running ctest:
# Add MinGW bin to the PATH for this session (adjust the path if necessary)
$env:PATH = "C:\msys64\ucrt64\bin;" + $env:PATH
# Run the tests
ctestAlternatively, you can run the tests by providing the full path to ctest.exe:
& "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\ctest.exe"