Skip to content

Commit e1f4161

Browse files
committed
[FIX] tests
1 parent 2dbd481 commit e1f4161

12 files changed

+64
-256
lines changed

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ $ chmod +x build.sh
2020
$ ./build.sh
2121
--- Starting mygit build process ---
2222
Step 1: Configuring with CMake...
23-
-- The CXX compiler identification is GNU 11.4.0
23+
-- The CXX compiler identification is GNU 13.3.0
2424
...
2525
Step 2: Building the executable...
2626
[ 50%] Built target mygit
@@ -49,19 +49,19 @@ Initialized empty Git repository in /path/to/my-test-project/.git/
4949
# Create a file and add it to the object database as a "blob"
5050
$ echo "hello git" > hello.txt
5151
$ mygit hash-object -w hello.txt
52-
d90f1b40cf83b5d4313c4155abdaac3265b53026
52+
8d0e41234f24b6da002d962a26c2495ea16a425f
5353

5454
# Create a "tree" object that captures the state of the directory
5555
$ mygit write-tree
56-
7c7394336c9966133c945b63cf476902d28f0b9f
56+
07ed5a7aebb914e3a02edf6d622b82d364037e3c
5757

5858
# Create a "commit" object, linking the tree with a message
59-
$ mygit commit-tree 7c7394336c9966133c945b63cf476902d28f0b9f -m "Initial commit"
60-
1b2e67a423e8b0ed5d46924d567027582b12367d
59+
$ mygit commit-tree 07ed5a7aebb914e3a02edf6d622b82d364037e3c -m "Initial commit"
60+
2103525aff710463c0981ca9dc37c0ebb027335a
6161

6262
# Inspect the final commit object we just created
63-
$ /mygit cat-file -p 1b2e67a423e8b0ed5d46924d567027582b12367d
64-
tree 7c7394336c9966133c945b63cf476902d28f0b9f
63+
$ mygit cat-file -p 2103525aff710463c0981ca9dc37c0ebb027335a
64+
tree 07ed5a7aebb914e3a02edf6d622b82d364037e3c
6565
author Mathis-L <mathislafon@gmail.com> 1721245200 +0000
6666
committer Mathis-L <mathislafon@gmail.com> 1721245200 +0000
6767

@@ -116,7 +116,7 @@ You will need a C++23 compatible compiler and the following dependencies:
116116
On Debian/Ubuntu, you can install them with:
117117
```bash
118118
sudo apt-get update
119-
sudo apt-get install -y build-essential cmake libssl-dev zlib1g-dev
119+
sudo apt-get install -y build-essential cmake libssl-dev zlib1g-dev libcurl4-openssl-dev
120120
```
121121

122122
And for cpr you will have to do :

build.sh

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,4 @@ echo "Step 2: Building the executable..."
1616
cmake --build ./build
1717

1818
echo ""
19-
echo "✅ Build complete!"
20-
echo " The executable is located at: ./build/mygit"
21-
echo " You can now run commands, for example: ./build/mygit --help"
19+
echo "✅ Build complete! You can now run commands, for example: ./build/mygit"

test.md

Lines changed: 0 additions & 202 deletions
This file was deleted.

tests/run_all_tests.sh

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,40 @@
11
#!/bin/bash
22
set -e
33

4+
# --- Colors for output ---
45
RED='\033[0;31m'
56
GREEN='\033[0;32m'
67
CYAN='\033[0;36m'
8+
YELLOW='\033[1;33m'
79
NC='\033[0m'
810

9-
echo -e "${CYAN}🔍 Running all tests...${NC}"
10-
echo "=========================================="
11+
# --- Step 1: Build the project ---
12+
echo -e "${CYAN}🚀 Step 1/2: Building the 'mygit' project...${NC}"
13+
# Go up one level to run the build script
14+
(cd .. && bash build.sh)
15+
echo "----------------------------------------"
1116

17+
# --- Step 2: Run the tests ---
18+
echo -e "${CYAN}🔍 Step 2/2: Running the test suite...${NC}"
19+
20+
# Define the path to the executable ONLY ONCE
21+
# The `export` makes the variable available to all child scripts
22+
PROJECT_ROOT=$(cd "$(dirname "$0")/.." && pwd)
23+
export MYGIT_EXEC="$PROJECT_ROOT/build/mygit"
24+
25+
# Check if the executable exists before continuing
26+
if [ ! -f "$MYGIT_EXEC" ]; then
27+
echo -e "${RED}[ERROR] The executable was not found at '$MYGIT_EXEC'. Aborting tests.${NC}"
28+
exit 1
29+
fi
30+
31+
# Loop through and run each test script
1232
for test in test_*.sh; do
1333
echo -e "${YELLOW}➡️ Running $test...${NC}"
1434
bash "$test"
35+
echo -e "${GREEN}Test $test completed successfully.${NC}"
1536
echo "=========================================="
1637
echo ""
1738
done
1839

19-
echo -e "${GREEN}✅ All tests passed.${NC}"
40+
echo -e "${GREEN}✅ All tests passed. Excellent work!${NC}"

tests/test_cat_file.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ rm -rf tmp_test && mkdir tmp_test && cd tmp_test
1010

1111
echo "hello world" > file.txt
1212

13-
sha=$(../../build.sh hash-object -w file.txt | tail -n 1)
13+
sha=$($MYGIT_EXEC hash-object -w file.txt | tail -n 1)
1414
expected=$(cat file.txt)
15-
actual=$(../../build.sh cat-file -p "$sha" | tail -n 1)
15+
actual=$($MYGIT_EXEC cat-file -p "$sha" | tail -n 1)
1616

1717
if [ "$expected" == "$actual" ]; then
1818
echo -e "${GREEN}[PASS] cat-file displays correct content${NC}"
@@ -23,4 +23,4 @@ else
2323
echo -e "${YELLOW}Expected: $expected${NC}"
2424
echo -e "${YELLOW}Actual: $actual${NC}"
2525
exit 1
26-
fi
26+
fi

0 commit comments

Comments
 (0)