Skip to content

Commit 821543b

Browse files
committed
changed back testing
1 parent 4579647 commit 821543b

1 file changed

Lines changed: 12 additions & 78 deletions

File tree

.github/workflows/build.yml

Lines changed: 12 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -7,98 +7,32 @@ on:
77
branches: [ "main" ]
88

99
jobs:
10-
test:
10+
build:
1111
runs-on: ubuntu-latest
1212
env:
1313
CI: "true"
1414

1515
steps:
1616
- name: Checkout code
17-
uses: actions/checkout@v4
17+
uses: actions/checkout@v3
1818

1919
- name: Install dependencies
2020
run: |
2121
sudo apt-get update
22-
sudo apt-get install -y make gcc libreadline-dev valgrind expect
23-
22+
sudo apt-get install -y make gcc libreadline-dev
23+
2424
- name: Build project
2525
run: |
2626
make re
27-
[ -f "minishell" ] || (echo "Build failed" && exit 1)
28-
29-
- name: Basic command tests
30-
run: |
31-
# Test echo
32-
echo 'echo hello' | ./minishell | grep -q "hello" || (echo "FAIL: echo" && exit 1)
33-
34-
# Test pwd
35-
echo 'pwd' | ./minishell | grep -q $(pwd) || (echo "FAIL: pwd" && exit 1)
3627
37-
# Test env
38-
echo 'env' | ./minishell | grep -q "PATH=" || (echo "FAIL: env" && exit 1)
39-
40-
# Test cd (using expect for interactive testing)
41-
echo 'spawn ./minishell
42-
send "cd ..\r"
43-
send "pwd\r"
44-
expect {
45-
"$(dirname $(pwd))" { exit 0 }
46-
timeout { exit 1 }
47-
}' > test_cd.exp
48-
expect test_cd.exp || (echo "FAIL: cd" && exit 1)
49-
50-
- name: Pipe and redirection tests
28+
- name: Run basic tests
5129
run: |
52-
# Test pipes
53-
echo 'ls | head -n 3 | wc -l' | ./minishell | grep -q "3" || (echo "FAIL: pipes" && exit 1)
30+
./minishell <<< "echo hello" | grep -q "hello"
31+
./minishell <<< "pwd" | grep -q $(pwd)
5432
55-
# Test output redirection
56-
echo 'echo test > testfile && cat testfile' | ./minishell | grep -q "test" || (echo "FAIL: output redirection" && exit 1)
57-
58-
# Test input redirection
59-
echo 'cat < Makefile | grep minishell' | ./minishell | grep -q "minishell" || (echo "FAIL: input redirection" && exit 1)
60-
rm -f testfile
61-
62-
- name: Error handling tests
33+
- name: Check for memory leaks (valgrind)
34+
if: ${{ !cancelled() }}
6335
run: |
64-
# Test invalid commands
65-
echo 'invalidcmd' | ./minishell 2>&1 | grep -q "command not found" || (echo "FAIL: invalid command" && exit 1)
66-
67-
# Test syntax errors
68-
echo 'echo |' | ./minishell 2>&1 | grep -q "syntax error" || (echo "FAIL: pipe syntax" && exit 1)
69-
echo 'echo >' | ./minishell 2>&1 | grep -q "syntax error" || (echo "FAIL: redirection syntax" && exit 1)
70-
71-
- name: Builtin tests
72-
run: |
73-
# Test export
74-
echo 'export TEST_VAR=123 && env' | ./minishell | grep -q "TEST_VAR=123" || (echo "FAIL: export" && exit 1)
75-
76-
# Test unset
77-
echo 'export TEST_VAR=123 && unset TEST_VAR && env' | ./minishell | grep -qv "TEST_VAR" || (echo "FAIL: unset" && exit 1)
78-
79-
# Test exit
80-
echo 'exit 42' | ./minishell
81-
[ $? -eq 42 ] || (echo "FAIL: exit code" && exit 1)
82-
83-
- name: Memory leak tests
84-
run: |
85-
mkdir -p logs
86-
# Test simple command
87-
echo 'echo hello' | valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes \
88-
--log-file=logs/valgrind_simple.log ./minishell
89-
90-
# Test pipe command
91-
echo 'ls | head -n 3' | valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes \
92-
--log-file=logs/valgrind_pipe.log ./minishell
93-
94-
# Check for leaks
95-
! grep -q "definitely lost" logs/valgrind_*.log || (echo "Memory leaks detected" && exit 1)
96-
97-
- name: Upload test results
98-
if: always()
99-
uses: actions/upload-artifact@v4
100-
with:
101-
name: test-results
102-
path: logs/
103-
retention-days: 1
104-
36+
sudo apt-get install -y valgrind
37+
valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes \
38+
--error-exitcode=1 ./minishell <<< "exit"

0 commit comments

Comments
 (0)