# Test fail in last stage related to ls command handling logic

**URL:** <https://forum.codecrafters.io/t/test-fail-in-last-stage-related-to-ls-command-handling-logic/4448>\
**Category:** Challenges\
**Tags:** challenge:shell\
**Created:** [January 24, 2025, 5:26pm UTC](https://forum.codecrafters.io/t/test-fail-in-last-stage-related-to-ls-command-handling-logic/4448 "2025-01-24T17:26:04Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![mohamed-khalaf9](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/mohamed-khalaf9/32/4536_2.png) [@mohamed-khalaf9](https://forum.codecrafters.io/u/mohamed-khalaf9)\
**Post date:** [January 24, 2025, 5:02pm UTC](https://forum.codecrafters.io/t/test-fail-in-last-stage-related-to-ls-command-handling-logic/4448/1 "2025-01-24T17:02:26Z")

</div>

how can I handle ls to pass this test case:

I assume if ls with no arguments I will list everything inside current working directory if there is an argument , I will check if it is a directory then list its content ,if it is a regular file I just printing the name , so what is the wrong here

 ![codecrafters](https://canada1.discourse-cdn.com/flex003/uploads/codecrafters/original/2X/3/37b577ed9750886c529bb83068e1a428d56595f1.png)

---

<div class="post-metadata">

**Author:** ![mohamed-khalaf9](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/mohamed-khalaf9/32/4536_2.png) [@mohamed-khalaf9](https://forum.codecrafters.io/u/mohamed-khalaf9)\
**Post date:** [January 24, 2025, 5:26pm UTC](https://forum.codecrafters.io/t/test-fail-in-last-stage-related-to-ls-command-handling-logic/4448/2 "2025-01-24T17:26:04Z")

</div>

![codecrafters](https://canada1.discourse-cdn.com/flex003/uploads/codecrafters/original/2X/3/37b577ed9750886c529bb83068e1a428d56595f1.png)  
I have build a function that takes the argument of ls command , if no argument , I am listing the file in current directory which is the current path , if there an argument I check if it is a directory and list its files content , if regular file I am just writing the name of the file, now I can not understand what happen in this test case , is this a directory : /tmp/quz ? I need someone to explain the test case setup for me to help me pass this stage

---

<div class="post-metadata">

**Author:** ![mohamed-khalaf9](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/mohamed-khalaf9/32/4536_2.png) [@mohamed-khalaf9](https://forum.codecrafters.io/u/mohamed-khalaf9)\
**Post date:** [January 24, 2025, 5:30pm UTC](https://forum.codecrafters.io/t/test-fail-in-last-stage-related-to-ls-command-handling-logic/4448/3 "2025-01-24T17:30:01Z")

</div>

here is my last try output:

 ![code2](https://canada1.discourse-cdn.com/flex003/uploads/codecrafters/original/2X/e/ee92c2205096b7b110e74ca68d0b665fc1fa8d13.png)

---

<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:** [January 24, 2025, 5:47pm UTC](https://forum.codecrafters.io/t/test-fail-in-last-stage-related-to-ls-command-handling-logic/4448/4 "2025-01-24T17:47:25Z")

</div>

Hi @mohamed-khalaf9, it seems you’ve implemented a custom version of `ls`? If that’s the case, there’s no need to do so.

The `ls` command is already available as an executable on our tester, likely as `/bin/ls`. You can simply run it as you did in stage **#IP1 (Run a Program)**.

Here’s a successful run for your reference:

 ![image](https://canada1.discourse-cdn.com/flex003/uploads/codecrafters/original/2X/8/8dd1ff9dc19c4250d2a73802f03d326c9273296d.png)

---

<div class="post-metadata">

**Author:** ![mohamed-khalaf9](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/mohamed-khalaf9/32/4536_2.png) [@mohamed-khalaf9](https://forum.codecrafters.io/u/mohamed-khalaf9)\
**Post date:** [January 24, 2025, 9:45pm UTC](https://forum.codecrafters.io/t/test-fail-in-last-stage-related-to-ls-command-handling-logic/4448/5 "2025-01-24T21:45:09Z")

</div>

but why the tester display expected: “mango” one file just not all ?

---

<div class="post-metadata">

**Author:** ![mohamed-khalaf9](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/mohamed-khalaf9/32/4536_2.png) [@mohamed-khalaf9](https://forum.codecrafters.io/u/mohamed-khalaf9)\
**Post date:** [January 24, 2025, 10:00pm UTC](https://forum.codecrafters.io/t/test-fail-in-last-stage-related-to-ls-command-handling-logic/4448/6 "2025-01-24T22:00:42Z")

</div>

I think that the problem from the tester it expects just one file name , I don’t understand why, you can check screenshots provided by me not like your provided one

---

<div class="post-metadata">

**Author:** ![rohitpaulk](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/rohitpaulk/32/6_2.png) [@rohitpaulk](https://forum.codecrafters.io/u/rohitpaulk)\
**Post date:** [January 24, 2025, 10:03pm UTC](https://forum.codecrafters.io/t/test-fail-in-last-stage-related-to-ls-command-handling-logic/4448/7 "2025-01-24T22:03:02Z")

</div>

I think our expectations run line-by-line, which is why the error looks confusing. It’s only printing the expected/received log for the first line.

Once you implement printing each item on one line (by just using the default ls), things should work.

---

<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:** [March 10, 2025, 9:46am UTC](https://forum.codecrafters.io/t/test-fail-in-last-stage-related-to-ls-command-handling-logic/4448/8 "2025-03-10T09:46:17Z")

</div>

Closing this thread due to inactivity. If you still need assistance, feel free to reopen or start a new discussion!

---

<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:** [March 15, 2025, 9:47am UTC](https://forum.codecrafters.io/t/test-fail-in-last-stage-related-to-ls-command-handling-logic/4448/9 "2025-03-15T09:47:19Z")

</div>

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