Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement standard library glob function #477

Closed

Conversation

hdwalters
Copy link
Contributor

Fixes #463.

src/std/fs.ab Outdated Show resolved Hide resolved
Copy link
Member

@b1ek b1ek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

two things:

  1. that function should be rewritten to be failful, since it can hit a permission error or something stupid like that
  2. all std functions must be covered by a test

@hdwalters
Copy link
Contributor Author

hdwalters commented Sep 15, 2024

@b1ek wrote:

  1. that function should be rewritten to be failful, since it can hit a permission error or something stupid like that

Made function failing. Note, this now fails if the glob matches nothing, and due to a quirk of the Amber compiler, if you assign the results of an unsafe glob("...") call to a local variable, that variable contains [""] not [] as one might expect. This does not prevent the unit tests from passing.

  1. all std functions must be covered by a test

Added unit tests for "missing file", "no spaces" and "with spaces".

Copy link
Member

@Ph0enixKM Ph0enixKM left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hdwalters These two tests failed on my end. I'm running this on MacBook

Screenshot 2024-09-15 at 22 32 18

@hdwalters
Copy link
Contributor Author

hdwalters commented Sep 15, 2024

@hdwalters These two tests failed on my end. I'm running this on MacBook

That's weird. I had to replace the temporary directory with a hard-coded placeholder for the assertion:

echo replace_regex(file, "^.+\/", "[tmpdir]\/", true)

Note that the slashes are escaped because we're calling sed 's/.../.../' under the hood. This is addressed in a new issue #481.

I would have thought that sed would perform this replacement, as the directories under /var/folders should be matched by regex ^.+/.

@Ph0enixKM
Copy link
Member

@hdwalters great! So we're waiting for #481. Right?

@hdwalters
Copy link
Contributor Author

hdwalters commented Sep 16, 2024

@hdwalters great! So we're waiting for #481. Right?

This PR does not depend on #481, though my fix for that issue modifies these unit tests. To be clear, these unit tests will pass or fail on your machine, whether or not we escape slash characters in the stdlib replace_regex function.

@Mte90 Mte90 self-requested a review September 17, 2024 10:35
Copy link
Member

@Mte90 Mte90 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I shared my opinion on #463 (comment) and I am against this solution because use eval

@hdwalters hdwalters closed this Sep 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature] Loop files/directories (glob)
4 participants