-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.sh
More file actions
executable file
·107 lines (93 loc) · 3.21 KB
/
test.sh
File metadata and controls
executable file
·107 lines (93 loc) · 3.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/bin/bash
# Simple test script for MVCS
set -e
echo "Running MVCS Tests..."
echo
# Get script directory and MVCS binary path
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
MVCS_BIN="$SCRIPT_DIR/mvcs"
# Build first
echo "Building MVCS..."
cd "$SCRIPT_DIR"
make clean > /dev/null 2>&1
make > /dev/null 2>&1
echo "✓ Build successful"
# Test 1: Init
echo
echo "Test 1: Repository Initialization"
TEST_DIR="/tmp/mvcs-test-$$"
rm -rf "$TEST_DIR"
mkdir -p "$TEST_DIR"
cd "$TEST_DIR"
$MVCS_BIN init > /dev/null
[ -d .mvcs ] || { echo "✗ .mvcs directory not created"; exit 1; }
[ -f .mvcs/HEAD ] || { echo "✗ HEAD file not created"; exit 1; }
[ -f .mvcs/index ] || { echo "✗ index file not created"; exit 1; }
[ -d .mvcs/objects ] || { echo "✗ objects directory not created"; exit 1; }
[ -d .mvcs/refs/heads ] || { echo "✗ refs/heads directory not created"; exit 1; }
echo "✓ Repository initialized correctly"
# Test 2: Add files
echo
echo "Test 2: Adding Files"
echo "test content" > test.txt
export MVCS_AUTHOR="Test User"
$MVCS_BIN add test.txt > /dev/null
[ -s .mvcs/index ] || { echo "✗ Index not updated"; exit 1; }
HASH=$($MVCS_BIN hash-object test.txt)
[ ${#HASH} -eq 64 ] || { echo "✗ Invalid hash length"; exit 1; }
echo "✓ File added successfully"
echo " Hash: $HASH"
# Test 3: Create commit
echo
echo "Test 3: Creating Commit"
$MVCS_BIN commit "Test commit" > /dev/null
[ -f .mvcs/refs/heads/master ] || { echo "✗ master ref not created"; exit 1; }
COMMIT_HASH=$(cat .mvcs/refs/heads/master)
[ ${#COMMIT_HASH} -eq 64 ] || { echo "✗ Invalid commit hash"; exit 1; }
echo "✓ Commit created successfully"
echo " Commit: $COMMIT_HASH"
# Test 4: View log
echo
echo "Test 4: Viewing Log"
LOG_OUTPUT=$($MVCS_BIN log)
echo "$LOG_OUTPUT" | grep -q "Test commit" || { echo "✗ Commit message not in log"; exit 1; }
echo "$LOG_OUTPUT" | grep -q "Test User" || { echo "✗ Author not in log"; exit 1; }
echo "$LOG_OUTPUT" | grep -q "$COMMIT_HASH" || { echo "✗ Commit hash not in log"; exit 1; }
echo "✓ Log displays correctly"
# Test 5: Multiple commits
echo
echo "Test 5: Multiple Commits"
echo "second file" > file2.txt
$MVCS_BIN add file2.txt > /dev/null
$MVCS_BIN commit "Second commit" > /dev/null
LOG_COUNT=$($MVCS_BIN log | grep -c "^commit ")
[ $LOG_COUNT -eq 2 ] || { echo "✗ Expected 2 commits, found $LOG_COUNT"; exit 1; }
echo "✓ Multiple commits working"
# Test 6: Object inspection
echo
echo "Test 6: Object Inspection"
BLOB_HASH=$($MVCS_BIN hash-object test.txt)
OBJ_OUTPUT=$($MVCS_BIN cat-file $BLOB_HASH)
echo "$OBJ_OUTPUT" | grep -q "Type: blob" || { echo "✗ Object type incorrect"; exit 1; }
echo "$OBJ_OUTPUT" | grep -q "test content" || { echo "✗ Object content incorrect"; exit 1; }
echo "✓ Object inspection working"
# Test 7: Empty commit check
echo
echo "Test 7: Empty Staging Area"
# Clear index by reinitializing
rm .mvcs/index
touch .mvcs/index
$MVCS_BIN commit "Should fail" 2>&1 | grep -q "staging area empty" && {
echo "✓ Empty staging area detected correctly"
} || {
echo "✗ Should reject empty commit"
exit 1
}
# Cleanup
echo
cd /
rm -rf "$TEST_DIR"
echo
echo "========================================="
echo "All tests passed! ✓"
echo "========================================="