Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions man/scount.1
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ scount \- A tool to count logical lines of code and other metrics
.B scount
[\fB\-\-verbose\fR]
[\fB\-\-annotate\-counts\fR]
[\fB\-\-stop\-on\-error\fR]
.I <PATH>
.SH DESCRIPTION
scount counts source code lines in a single file
Expand Down Expand Up @@ -43,6 +44,12 @@ Mark counted logical lines and output the result.
.br
This option can only be used on a single file input.
.TP
.B \-\-stop\-on\-error
Stop the processing on the first encountered error,
even for non\-critical errors. Without this option (the default),
some errors are considered non-critical, in which case the corresponding
file is skipped and the processing continues.
.TP
.B \-\-verbose
Enable verbose output.
.TP
Expand Down
4 changes: 4 additions & 0 deletions src/lib/c/statistics.c
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,10 @@ static inline bool count(
if (!options.keepFileContent) {
freeSourceFileContent(file);
}
if (!ok && options.stopOnError) {
stats->state = result->state;
stats->state.ok = false;
}

RCN_LOG_DBG("Done processing file:")
RCN_LOG_DBG(file->path)
Expand Down
6 changes: 5 additions & 1 deletion src/scount/c/arguments.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ AppArgs parseArgs(int argc, char** argv) {
for (int i = 1; i < argc; ++i) {
if (strcmp(argv[i], "--annotate-counts") == 0) {
args.annotateCounts = true;
} else if (strcmp(argv[i], "--stop-on-error") == 0) {
args.stopOnError = true;
} else if (strcmp(argv[i], "--verbose") == 0) {
args.verbose = true;
} else if (strcmp(argv[i], "--help") == 0
Expand Down Expand Up @@ -58,7 +60,7 @@ AppArgs parseArgs(int argc, char** argv) {
}

void showUsage(void) {
logI("Usage: scount [--verbose] [--annotate-counts] <PATH>");
logI("Usage: scount [--verbose] [--annotate-counts] [--stop-on-error] <PATH>");
}

void showVersion(AppArgs args) {
Expand Down Expand Up @@ -95,6 +97,8 @@ void showHelpText(void) {
logI(" [--annotate-counts] Mark counted logical lines and output the result.");
logI(" This option can only be used on a single file input.");
logI(" ");
logI(" [--stop-on-error] Stop processing immediately when an error is encountered.");
logI(" ");
logI(" [--verbose] Enable verbose output.");
logI(" ");
logI(" [-#|--version] Show program version information.");
Expand Down
1 change: 1 addition & 0 deletions src/scount/c/scount.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ typedef struct AppArgs {
char* errorMessage; // Error message in case of invalid input
int indexUnknown; // Index into `argv` when unknown arg found, or zero
bool annotateCounts; // Option: `--annotate-counts`
bool stopOnError; // Option: `--stop-on-error`
bool verbose; // Option: `--verbose`
bool version; // Option: `-#|--version`
bool versionShort; // Option: `-#`
Expand Down
5 changes: 4 additions & 1 deletion src/scount/c/statistics.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,10 @@ ExitStatus outputStatistics(AppArgs args) {
reportInputVerbose(path, stats);
}

RcnStatOptions options = {0};
RcnStatOptions options = {
.stopOnError = args.stopOnError
};

rcnCount(stats, options);

const RcnErrorCode errorCode = stats->state.errorCode;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 16 additions & 1 deletion src/scount/tests/functionality/sh/test_scount.sh
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,26 @@ function test_scount_with_directory_that_contains_file_with_syntax_error() {
}

function test_scount_with_file_that_has_syntax_error() {
local file="${TEST_RES_DIR}/mixedWithSyntaxError/has_syntax_error.c";
local file="${TEST_RES_DIR}/mixedWithSyntaxError/02_has_syntax_error.c";
run_app "$file";
assert_exit_status $EXIT_INVALID_INPUT;
assert_stdout_is_empty;
assert_stderr_contains "An error has occurred for: ";
assert_stderr_contains "${file}";
assert_stderr_contains "Syntax error detected in source code (0x04)";
}

function test_scount_with_stop_on_error_option() {
run_app --stop-on-error "${TEST_RES_DIR}/mixedWithSyntaxError";
assert_exit_status $EXIT_INVALID_INPUT;
assert_stdout_is_empty;
assert_stderr_contains "An error has occurred";
assert_stderr_contains "Syntax error detected in source code";
}

function test_scount_with_valid_directory_input_and_stop_on_error_option() {
run_app --stop-on-error "${TEST_PROJECT_DIR}/src/lib/tests/res/java";
assert_exit_status $EXIT_SUCCESS;
assert_stdout_equals_file "expected/output_multiple_files.txt";
assert_stderr_is_empty;
}