Skip to content
This repository has been archived by the owner on Aug 22, 2024. It is now read-only.

Commit

Permalink
fix: working append-match line
Browse files Browse the repository at this point in the history
  • Loading branch information
ASuciuX committed Nov 30, 2023
1 parent fd9e4c0 commit cf22f50
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 18 deletions.
3 changes: 2 additions & 1 deletion mutation-testing/scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ cd mutation-testing/scripts
sh append.sh
# can see on git how the trails folder files were modified
git status ./..

```

## steps to reproduce working version with different number lines:

in trials/mutants-stable/caught.txt replace line number 23 with 109
the append.sh won't work anymore
the append-match.sh
the append-match.sh works

```bash
sh append-match.sh
Expand Down
26 changes: 16 additions & 10 deletions mutation-testing/scripts/append-match.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
#!/bin/bash

PR_FOLDER="./../trials/mutants.out.old"
STABLE_FOLDER="./../mutants-stable"
STABLE_FOLDER="./../trials/mutants-stable"
FILES=("caught.txt" "missed.txt" "timeout.txt" "unviable.txt")

echo "Starting script..."
echo "PR Folder: $PR_FOLDER"
echo "STABLE Folder: $STABLE_FOLDER"
echo "Files to process: ${FILES[*]}"

# Function to escape forward slashes
escape_slashes() {
echo "$1" | sed 's_/_\\/_g'
# Function to escape special characters for awk
escape_for_awk() {
echo "$1" | sed -E 's/([][\/$*.^|])/\\&/g'
}

# Iterate over the specified files
Expand All @@ -27,24 +27,30 @@ for file in "${FILES[@]}"; do
while IFS= read -r line; do
echo "Reading line from PR file: $line"

# Extract the pattern without the line number and escape slashes
pattern=$(echo "$line" | sed -E 's/:[0-9]+:/::/' | escape_slashes)
echo "Extracted pattern: $pattern"
# Extract the core pattern without the line number and escape it for awk
core_pattern=$(echo "$line" | sed -E 's/^[^:]+:[0-9]+:(.+)/\1/')
escaped_pattern=$(escape_for_awk "$core_pattern")
echo "Extracted and escaped pattern: $escaped_pattern"

# Iterate over each file in the STABLE folder
for target_file in "${FILES[@]}"; do
target_path="$STABLE_FOLDER/$target_file"
echo "Checking against STABLE file: $target_path"
# Remove the matching line from the STABLE file, ignoring line numbers
# Adding '' for macOS compatibility
sed -i '' "/$pattern/d" "$target_path"

# Remove the line matching the pattern, ignoring line numbers
awk -v pat="$escaped_pattern" '$0 !~ pat' "$target_path" > temp_file && mv temp_file "$target_path"
done
done < "$pr_file"
else
echo "PR file $pr_file is empty or does not exist, skipping..."
fi
done

# After processing all lines, append contents from PR_DIR to STABLE_DIR
for file in "${FILES[@]}"; do
cat "$PR_FOLDER/$file" >> "$STABLE_FOLDER/$file"
done

# Echo the contents of the STABLE folder for verification
echo "Updated contents of STABLE folder:"
for file in "${FILES[@]}"; do
Expand Down
5 changes: 1 addition & 4 deletions mutation-testing/scripts/append.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,7 @@ for file in "${FILES[@]}"; do
done < "$PR_DIR/$file"
done

# # After processing all lines, append contents from PR_DIR to STABLE_DIR
# After processing all lines, append contents from PR_DIR to STABLE_DIR
for file in "${FILES[@]}"; do
cat "$PR_DIR/$file" >> "$STABLE_DIR/$file"
done



4 changes: 3 additions & 1 deletion mutation-testing/trials/mutants-stable/caught.txt
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
stx-genesis/src/lib.rs:23: replace <impl Iterator for LinePairReader>::count -> usize with 1
stx-genesis/src/lib.rs:23: replace <impl Iterator for LinePairReader>::count -> usize with 43
stx-genesis/src/lib.rs:109: replace <thi examepldas -> usize with 43
stx-genesis/src/mmmms.rs:109: replace <thi examepldas -> usize with 43
4 changes: 3 additions & 1 deletion mutation-testing/trials/mutants-stable/missed.txt
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
stx-genesis/src/lib.rs:23: replace <impl Iterator for LinePairReader>::count -> usize with 0
stx-genesis/src/lib.rs:23: replace <impl Iterator for LinePairReader>::count -> usize with 1
stx-genesis/src/lib.rs:109: replace <impl Iterator for LinePairReader>::count -> usize with 0
stx-genesis/src/lib.rs:109: replace <impl Iterator for LinePairReader>::count -> usize with 2
1 change: 1 addition & 0 deletions mutation-testing/trials/mutants-stable/unviable.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
stx-genesis/src/lib.rs:115: replace read_deflated_zonefiles -> Box<dyn Iterator<Item = GenesisZonefile>> with Box::new(Default::default())
3 changes: 2 additions & 1 deletion mutation-testing/trials/mutants.out.old/missed.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
stx-genesis/src/lib.rs:23: replace <impl Iterator for LinePairReader>::count -> usize with 1
stx-genesis/src/lib.rs:23: replace <impl Iterator for LinePairReader>::count -> usize with 0
stx-genesis/src/lib.rs:109: replace <impl Iterator for LinePairReader>::count -> usize with 0
stx-genesis/src/lib.rs:109: replace <impl Iterator for LinePairReader>::count -> usize with 2

0 comments on commit cf22f50

Please sign in to comment.