Skip to content
Open
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
33 changes: 32 additions & 1 deletion src/scount/c/statistics.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,29 @@
#include "reckon/reckon.h"
#include "scount.h"

static void reportError(const char* path, RcnCountStatistics* stats) {
static void reportFileError(
const RcnCountStatistics* stats,
const RcnSourceFile* file,
const RcnCountResultGroup* result
) {
logE("An error was encountered for the following file: '%s'", file->path);
const char* const statErr = (
stats->state.errorMessage
? stats->state.errorMessage
: ""
);
const char* const fileErr = (
result->state.errorMessage
? result->state.errorMessage
: ""
);
// Report only if it differs from the overall stats error message
if (strcmp(fileErr, "") != 0 && strcmp(statErr, fileErr) != 0) {
logE("%s (%#04x)", fileErr, result->state.errorCode); // LCOV_EXCL_LINE
}
}

static void reportError(const char* path, const RcnCountStatistics* stats) {
if (stats->state.errorCode == RCN_ERR_INVALID_INPUT) {
logE("Invalid input path: '%s'", path);
} else {
Expand All @@ -41,6 +63,15 @@ static void reportError(const char* path, RcnCountStatistics* stats) {
);
// LCOV_EXCL_STOP
}
if (stats->count.size > 1) {
for (size_t i = 0; i < stats->count.size; ++i) {
const RcnCountResultGroup* const result = &stats->count.results[i];
if (result->state.errorCode != RCN_ERR_NONE) {
reportFileError(stats, &stats->count.files[i], result);
break; // Show the first file-specific error only
}
}
}
}

static void reportInputVerbose(const char* path, RcnCountStatistics* stats) {
Expand Down
2 changes: 2 additions & 0 deletions src/scount/tests/functionality/sh/test_scount.sh
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ function test_scount_with_stop_on_error_option() {
assert_stdout_is_empty;
assert_stderr_contains "An error has occurred";
assert_stderr_contains "Syntax error detected in source code";
assert_stderr_contains "An error was encountered for the following file:";
assert_stderr_contains "mixedWithSyntaxError/02_has_syntax_error.c";
}

function test_scount_with_valid_directory_input_and_stop_on_error_option() {
Expand Down