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
6 changes: 6 additions & 0 deletions src/lib/c/factories.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ SourceFormatDetection detectSourceFormat(const RcnSourceFile* file) {
} else if (strcmp(extension, "json") == 0) {
detection.isSupportedFormat = true;
detection.format = RCN_TEXT_JSON;
} else if (strcmp(extension, "R") == 0
|| strcmp(extension, "r") == 0) {
// isProgrammingLanguage is false for R format due to missing
// support for logical line counting in R files
detection.isSupportedFormat = true;
detection.format = RCN_LANG_R;
} else if (strcmp(extension, "txt") == 0) {
detection.isSupportedFormat = true;
detection.format = RCN_TEXT_UNFORMATTED;
Expand Down
17 changes: 14 additions & 3 deletions src/lib/include/reckon/reckon.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ extern "C" {
* The total number of supported text formats, including
* supported programming languages.
*/
#define RECKON_NUM_SUPPORTED_FORMATS 7
#define RECKON_NUM_SUPPORTED_FORMATS 8

/**
* Macro to create a format option bitmask.
Expand Down Expand Up @@ -168,7 +168,12 @@ typedef enum RcnTextFormat {
/**
* Source files for the Python programming language.
*/
RCN_LANG_PYTHON
RCN_LANG_PYTHON,

/**
* Source files for the R programming language.
*/
RCN_LANG_R,

} RcnTextFormat;

Expand Down Expand Up @@ -732,7 +737,13 @@ typedef enum RcnFormatOption {
* Option to select statistics for source code files written in
* the Python programming language.
*/
RCN_OPT_LANG_PYTHON = RECKON_MK_FRMT_OPT(RCN_LANG_PYTHON)
RCN_OPT_LANG_PYTHON = RECKON_MK_FRMT_OPT(RCN_LANG_PYTHON),

/**
* Option to select statistics for source code files written in
* the R programming language.
*/
RCN_OPT_LANG_R = RECKON_MK_FRMT_OPT(RCN_LANG_R),

} RcnFormatOption;

Expand Down
13 changes: 13 additions & 0 deletions src/lib/tests/integration/c/test_fileio.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#define PATH_SAMPLE_DIR2_FILE2 PATH_DIR_RES2 "/2" FILE_SAMPLE2
#define PATH_SAMPLE_DIR3_FILE1 PATH_DIR_RES3 "/3" FILE_SAMPLE1
#define PATH_SAMPLE_JAVA_FILE RECKON_TEST_PATH_RES_BASE "/java/Sample.java"
#define PATH_SAMPLE_R_FILE RECKON_TEST_PATH_RES_BASE "/misc/sample.R"

void setUp(void) { }

Expand Down Expand Up @@ -233,6 +234,17 @@ void testDetectSourceFormatSupported(void) {
freeSourceFile(file);
}

void testDetectSourceFormatR(void) {
RcnSourceFile* file = newSourceFile(PATH_SAMPLE_R_FILE);
TEST_ASSERT_NOT_NULL(file);
SourceFormatDetection detection = detectSourceFormat(file);
TEST_ASSERT_TRUE(detection.isSupportedFormat);
// Special case: Missing support for LLC metric.
TEST_ASSERT_FALSE(detection.isProgrammingLanguage);
TEST_ASSERT_EQUAL_INT(RCN_LANG_R, detection.format);
freeSourceFile(file);
}

void testDetectSourceFormatUnsupported(void) {
RcnSourceFile* file = newSourceFile("/tmp/res/unknown.xyz");
TEST_ASSERT_NOT_NULL(file);
Expand Down Expand Up @@ -339,6 +351,7 @@ int main(void) {
RUN_TEST(testReadSourceFileContentIsNotReadIfAlreadyRead);
RUN_TEST(testReadSourceFileFailsWhenFilePathIsNull);
RUN_TEST(testDetectSourceFormatSupported);
RUN_TEST(testDetectSourceFormatR);
RUN_TEST(testDetectSourceFormatUnsupported);
RUN_TEST(testCreateSourceFileListOfEmptyDirectory);
RUN_TEST(testCreateSourceFileListFailsWhenInputPathIsNull);
Expand Down
4 changes: 4 additions & 0 deletions src/lib/tests/res/misc/sample.R

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

27 changes: 27 additions & 0 deletions src/lib/tests/unit/c/test_statistics.c
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,32 @@ void testCountResultsJson(void) {
rcnFreeCountStatistics(stats);
}

void testCountResultsR(void) {
char* path = RECKON_TEST_PATH_RES_BASE "/misc/sample.R";
RcnCountStatistics* stats = rcnCreateCountStatistics(path);
RcnStatOptions options = {
.formats = RCN_OPT_LANG_R
};

rcnCount(stats, options);

TEST_ASSERT_EQUAL_INT(1, stats->count.size);
RcnSourceFile* file = &stats->count.files[0];
RcnCountResultGroup* result = &stats->count.results[0];
TEST_ASSERT_TRUE(result->state.ok);
TEST_ASSERT_EQUAL_INT(RCN_ERR_NONE, result->state.errorCode);
TEST_ASSERT_NULL(result->state.errorMessage);
TEST_ASSERT_EQUAL_STRING("sample.R", file->name);
TEST_ASSERT_TRUE(result->isProcessed);
TEST_ASSERT_FALSE(result->hasLogicalLines);
TEST_ASSERT_EQUAL_INT(0, result->logicalLines);
TEST_ASSERT_EQUAL_INT(4, result->physicalLines);
TEST_ASSERT_EQUAL_INT(9, result->words);
TEST_ASSERT_EQUAL_INT(28, result->characters);
TEST_ASSERT_EQUAL_INT(28, result->sourceSize);
rcnFreeCountStatistics(stats);
}

// NOLINTEND(readability-magic-numbers)

int main(void) {
Expand All @@ -307,5 +333,6 @@ int main(void) {
RUN_TEST(testCountResultGroupLogicalLineCheckField);
RUN_TEST(testCountResultsXml);
RUN_TEST(testCountResultsJson);
RUN_TEST(testCountResultsR);
return UNITY_END();
}
3 changes: 3 additions & 0 deletions src/scount/c/print.c
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,9 @@ static void prSummaryRows(
case RCN_TEXT_JSON:
label = "JSON";
break;
case RCN_LANG_R:
label = "R";
break;
case RCN_LANG_C:
label = "C";
hasLogicalLines = true;
Expand Down
7 changes: 5 additions & 2 deletions src/scount/tests/functionality/res/expected/mixed.txt

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

4 changes: 4 additions & 0 deletions src/scount/tests/functionality/res/mixed/sample1.R

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

4 changes: 4 additions & 0 deletions src/scount/tests/functionality/res/mixed/sample2.r

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