# Test #QJ0 fails all the time

**URL:** <https://forum.codecrafters.io/t/test-qj0-fails-all-the-time/3388>\
**Category:** Challenges\
**Tags:** challenge:shell\
**Created:** [December 9, 2024, 8:52pm UTC](https://forum.codecrafters.io/t/test-qj0-fails-all-the-time/3388 "2024-12-09T20:52:52Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![i-JRay-i](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/i-jray-i/32/3415_2.png) [@i-JRay-i](https://forum.codecrafters.io/u/i-JRay-i)\
**Post date:** [December 9, 2024, 8:52pm UTC](https://forum.codecrafters.io/t/test-qj0-fails-all-the-time/3388/1 "2024-12-09T20:52:52Z")

</div>

The test on Stage #QJ0 always prints the same error, saying that the expected output is not the shell prompt ($ ). The same error occurred spontaneously in the previous stages as well, but now it is constant.

Here are the logs :

remote: [tester::#QJ0] Running tests for Stage #QJ0 (Quoting - Executing a quoted executable)  
remote: [tester::#QJ0] Running ./your\_program.sh  
remote: [tester::#QJ0] Copying /tmp/custom\_cat\_executable to /tmp/quz/‘exe with space’  
remote: [tester::#QJ0] Copying /tmp/custom\_cat\_executable to /tmp/quz/‘exe with “quotes”’  
remote: [tester::#QJ0] Copying /tmp/custom\_cat\_executable to /tmp/quz/“exe with 'single quotes'”  
remote: [tester::#QJ0] Copying /tmp/custom\_cat\_executable to /tmp/quz/‘exe with \n newline’  
remote: [tester::#QJ0] Writing file “/tmp/quz/f1” with content “grape raspberry.”  
remote: [tester::#QJ0] Writing file “/tmp/quz/f2” with content “pineapple strawberry.”  
remote: [tester::#QJ0] Writing file “/tmp/quz/f3” with content “pear mango.”  
remote: [tester::#QJ0] Writing file “/tmp/quz/f4” with content “strawberry raspberry.”  
remote: [your-program] $  
remote: [tester::#QJ0] \> ‘exe with space’ /tmp/quz/f1  
remote: [your-program] grape raspberry.  
remote: [tester::#QJ0] ✓ Received expected response  
remote: [tester::#QJ0] Expected prompt ("$ ") to be printed, got “”  
remote: [tester::#QJ0] Test failed

my code is here:

> <https://github.com/i-JRay-i/shell/blob/main/main.c>

Edit: I tried my code with multiple different quoted executable examples on my local machine (Linux). The program seems to work all right and print the shell prompt just fine.

---

<div class="post-metadata">

**Author:** ![andy1li](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/andy1li/32/10_2.png) [@andy1li](https://forum.codecrafters.io/u/andy1li)\
**Post date:** [December 10, 2024, 4:31am UTC](https://forum.codecrafters.io/t/test-qj0-fails-all-the-time/3388/2 "2024-12-10T04:31:21Z")

</div>

Hi @i-JRay-i, I’ll take a look and get back to you before the end of the week.

---

<div class="post-metadata">

**Author:** ![i-JRay-i](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/i-jray-i/32/3415_2.png) [@i-JRay-i](https://forum.codecrafters.io/u/i-JRay-i)\
**Post date:** [December 11, 2024, 11:36pm UTC](https://forum.codecrafters.io/t/test-qj0-fails-all-the-time/3388/4 "2024-12-11T23:36:09Z")

</div>

Hello! Thank you for your consideration. I just wanted to inform that I tried several different solutions (also added some extra utilities) to my code. The error still persists as of now.

---

<div class="post-metadata">

**Author:** ![andy1li](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/andy1li/32/10_2.png) [@andy1li](https://forum.codecrafters.io/u/andy1li)\
**Post date:** [December 15, 2024, 4:09pm UTC](https://forum.codecrafters.io/t/test-qj0-fails-all-the-time/3388/5 "2024-12-15T16:09:05Z")

</div>

@i-JRay-i I experimented a bit and can confirm that the issue lies with the free calls. When I commented them out, everything worked as expected:

```c
    // Freeing the memory of previous tokens after the command is analyzed
    // for (int arg_idx = 0; arg_idx < num_args; arg_idx++) {
    // free(args[arg_idx]);
    // args[arg_idx] = NULL;
    // }
  }

```

---

<div class="post-metadata">

**Author:** ![i-JRay-i](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/i-jray-i/32/3415_2.png) [@i-JRay-i](https://forum.codecrafters.io/u/i-JRay-i)\
**Post date:** [December 15, 2024, 5:15pm UTC](https://forum.codecrafters.io/t/test-qj0-fails-all-the-time/3388/7 "2024-12-15T17:15:34Z")

</div>

Interesting, thank you so much for your help! I did not attempt to touch the free calls for the args (since I tried to keep the command arguments dynamically allocated for this example), but when I commented them on the code everything worked fine.

---

<div class="post-metadata">

**Author:** ![andy1li](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/andy1li/32/10_2.png) [@andy1li](https://forum.codecrafters.io/u/andy1li)\
**Post date:** [December 15, 2024, 7:45pm UTC](https://forum.codecrafters.io/t/test-qj0-fails-all-the-time/3388/8 "2024-12-15T19:45:44Z")

</div>

I could only identify the issue, but properly fixing it will likely require more than just commenting out the free calls, as that could lead to potential memory leaks.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex003/uploads/codecrafters/original/3X/7/0/700657133935c15703e22c7c8870394f6e6dc27d.svg) [@system](https://forum.codecrafters.io/u/system)\
**Post date:** [December 21, 2024, 8:09pm UTC](https://forum.codecrafters.io/t/test-qj0-fails-all-the-time/3388/9 "2024-12-21T20:09:54Z")

</div>

Closed on December 21, 2024, 8:09pm UTC

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.
