@@ -25,9 +25,25 @@ delete_line_mutants <- function(src_file,
2525 idx <- sample(valid_lines , 1 )
2626 out_file <- file.path(out_dir , sprintf(" %s_%03d.R" , file_base , start_idx + i - 1 ))
2727 writeLines(lines [- idx ], out_file )
28+
29+ deleted_text <- lines [idx ]
30+ if (length(deleted_text ) == 0 || is.na(deleted_text ) || ! nzchar(deleted_text )) {
31+ deleted_text <- NA_character_
32+ }
33+
2834 mutants [[i ]] <- list (
2935 path = out_file ,
30- info = sprintf(" deleted line %d" , idx )
36+ info = list (
37+ start_line = as.integer(idx ),
38+ start_col = 1L ,
39+ end_line = as.integer(idx ),
40+ end_col = 1L ,
41+ original_symbol = deleted_text ,
42+ new_symbol = NA_character_ ,
43+ file_path = normalizePath(src_file , mustWork = FALSE ),
44+ mutation_type = " line_deletion" ,
45+ deleted_line = as.integer(idx )
46+ )
3147 )
3248 }
3349 mutants
@@ -307,6 +323,56 @@ normalize_max_mutants <- function(max_mutants, arg = "max_mutants") {
307323 as.integer(max_mutants )
308324}
309325
326+ format_mutation_info <- function (src_file , raw_info = NULL ) {
327+ file_path <- normalizePath(src_file , mustWork = FALSE )
328+ if (is.list(raw_info ) && ! is.null(raw_info $ file_path ) && length(raw_info $ file_path ) > 0 &&
329+ ! is.na(raw_info $ file_path [1 ]) && nzchar(raw_info $ file_path [1 ])) {
330+ file_path <- as.character(raw_info $ file_path [1 ])
331+ }
332+
333+ parts <- c(sprintf(" File: %s" , file_path ))
334+
335+ if (is.list(raw_info ) && ! is.null(raw_info $ start_line ) && ! is.null(raw_info $ start_col ) &&
336+ ! is.null(raw_info $ end_line ) && ! is.null(raw_info $ end_col )) {
337+ start_line <- as.integer(raw_info $ start_line )
338+ start_col <- as.integer(raw_info $ start_col )
339+ end_line <- as.integer(raw_info $ end_line )
340+ end_col <- as.integer(raw_info $ end_col )
341+
342+ parts <- c(parts , sprintf(
343+ " Range: %d:%d-%d:%d" ,
344+ start_line ,
345+ start_col ,
346+ end_line ,
347+ end_col
348+ ))
349+ }
350+
351+ if (is.list(raw_info )) {
352+ if (! is.null(raw_info $ mutation_type ) &&
353+ length(raw_info $ mutation_type ) > 0 &&
354+ identical(as.character(raw_info $ mutation_type [1 ]), " line_deletion" ) &&
355+ ! is.null(raw_info $ deleted_line ) &&
356+ length(raw_info $ deleted_line ) > 0 ) {
357+ parts <- c(parts , sprintf(" Details: deleted line %d" , as.integer(raw_info $ deleted_line [1 ])))
358+ return (paste(parts , collapse = " \n " ))
359+ }
360+
361+ original_symbol <- if (! is.null(raw_info $ original_symbol ) && length(raw_info $ original_symbol ) > 0 ) raw_info $ original_symbol [1 ] else NA_character_
362+ new_symbol <- if (! is.null(raw_info $ new_symbol ) && length(raw_info $ new_symbol ) > 0 ) raw_info $ new_symbol [1 ] else NA_character_
363+
364+ if (! is.na(original_symbol ) || ! is.na(new_symbol )) {
365+ new_label <- if (is.na(new_symbol )) " <deleted>" else new_symbol
366+ old_label <- if (is.na(original_symbol )) " <unknown>" else original_symbol
367+ parts <- c(parts , sprintf(" Details: '%s' -> '%s'" , old_label , new_label ))
368+ }
369+ } else if (! is.null(raw_info ) && nzchar(raw_info )) {
370+ parts <- c(parts , sprintf(" Details: %s" , raw_info ))
371+ }
372+
373+ paste(parts , collapse = " \n " )
374+ }
375+
310376# Generate AST-based and line-deletion mutants for a single R file
311377mutate_file <- function (src_file , out_dir = " mutations" , max_mutants = NULL ) {
312378 max_mutants <- normalize_max_mutants(max_mutants )
@@ -348,7 +414,7 @@ mutate_file <- function(src_file, out_dir = "mutations", max_mutants = NULL) {
348414 writeLines(paste(code , collapse = " \n " ), out_file )
349415
350416 info <- attr(m , " mutation_info" )
351- if (is.null(info ) || info == " " ) info <- " <no info>"
417+ if (is.null(info ) || (is.character( info ) && length( info ) == 1 && info == " " ) ) info <- " <no info>"
352418
353419 results [[length(results ) + 1 ]] <- list (path = out_file , info = info )
354420 idx <- idx + 1L
@@ -367,6 +433,13 @@ mutate_file <- function(src_file, out_dir = "mutations", max_mutants = NULL) {
367433 results <- results [base :: sample.int(length(results ), max_mutants )]
368434 }
369435
436+ for (i in seq_along(results )) {
437+ results [[i ]]$ info <- format_mutation_info(
438+ src_file = src_file ,
439+ raw_info = results [[i ]]$ info
440+ )
441+ }
442+
370443 results
371444}
372445
0 commit comments