Skip to content

FEATURE: add the first draft of the standard library#8150

Merged
fdncred merged 4 commits intonushell:mainfrom
amtoine:feature/first-draft-of-the-standard-library
Feb 27, 2023
Merged

FEATURE: add the first draft of the standard library#8150
fdncred merged 4 commits intonushell:mainfrom
amtoine:feature/first-draft-of-the-standard-library

Conversation

@amtoine
Copy link
Copy Markdown
Member

@amtoine amtoine commented Feb 21, 2023

hello there 👋 😋

as discussed over on the discord server, in #standard-library, there is this new project of putting together a bunch of "standard" scripts and functions and propose a nushell "standard library".
this PR is the first one in that direction 🎉

Note
this PR is still a draft to have some feedback 😌
this PR is now READY FOR REVIEW 🎉

Description

this PR implements the following few commands:

  • the assert familly with a private helper _assert
  • a version of the match statement

i've also added some examples in the docstrings of the functions 👍

User-Facing Changes

the standard library can now be used with

use crates/nu-utils/src/sample_config/std.nu

from the root of the nushell source

Tests + Formatting

i've written a first draft of a tests.nu module which

  • tests the assert familly of function in test_assert
  • tests the rest of the standard library in tests

the tests are run with

nu crates/nu-utils/src/sample_config/tests.nu

through the main function and should give no error 👍

Note
if you change one of the test line, there should be an error popping when running the tests 😉

After Submitting

Warning
to be coming

This commit implements the few commands we talked about in the
dedicated discord channel, #standard-library:
- the `assert` familly with a private helper `_assert`
- a version of the `match` statement
@amtoine amtoine changed the title FIRST: add the first draft of the standard library FEATURE: add the first draft of the standard library Feb 21, 2023
Usage:
```bash
nu crates/nu-utils/src/sample_config/tests.nu
```
@amtoine
Copy link
Copy Markdown
Member Author

amtoine commented Feb 23, 2023

📄 TODO:

  • add a first draft of std.nu => e730176
  • add a first draft of tests.nu => 48ccb8b
  • make sure the tests have a correct form
  • make sure the tests cover the few first functions
  • make sure the calling method, both for useing the library and running the tests, are easy to use
  • add documentation to the std.nu functions
  • add better error messages (maybe for later?)
  • probably some other things here 😋

@fdncred
Copy link
Copy Markdown
Contributor

fdncred commented Feb 23, 2023

Seems like a good start. It doesn't have to be perfect the first time. We'll continue to iterate.

@jmoore34
Copy link
Copy Markdown
Contributor

Perhaps assert_eq and such could be subcommands, eg assert eq with a space, for better discoverability

This change has been proposed by @jmoore34 and validated by @fdncred,
advocating better discoverability.

Commands used:
```bash
sd 'def assert_eq' 'def "assert eq"' crates/nu-utils/src/sample_config/std.nu
sd '`assert_eq`' '`assert eq`' crates/nu-utils/src/sample_config/std.nu
sd 'assert_eq' 'assert eq' crates/nu-utils/src/sample_config/tests.nu

sd 'def assert_ne' 'def "assert ne"' crates/nu-utils/src/sample_config/std.nu
sd '`assert_ne`' '`assert ne`' crates/nu-utils/src/sample_config/std.nu
sd 'assert_ne' 'assert ne' crates/nu-utils/src/sample_config/tests.nu
```
@amtoine
Copy link
Copy Markdown
Member Author

amtoine commented Feb 24, 2023

@fdncred @jmoore34

Perhaps assert_eq and such could be subcommands, eg assert eq with a space, for better discoverability

no problem, i've changed that in 839d7bf 👍

Seems like a good start. It doesn't have to be perfect the first time. We'll continue to iterate.

gotcha 👌
then we can mark that as "ready for review" and merge it if you want.
the TODO can be moved to some other place 😋

@amtoine amtoine marked this pull request as ready for review February 24, 2023 08:40
@amtoine
Copy link
Copy Markdown
Member Author

amtoine commented Feb 24, 2023

@sholderbach
Copy link
Copy Markdown
Member

mm how can i fix nushell/nushell/actions/runs/4260734684/jobs/7414370252? 😕

We removed the Windows coverage run for now as our setup was currently incompatible with the limited disk allocation on those workers. Should resolve by merging main.

@amtoine
Copy link
Copy Markdown
Member Author

amtoine commented Feb 26, 2023

We removed the Windows coverage run for now as our setup was currently incompatible with the limited disk allocation on those workers. Should resolve by merging main.

got it 👌
i'll merge this branch into main and we'll see if that fixes the CI!

@amtoine
Copy link
Copy Markdown
Member Author

amtoine commented Feb 26, 2023

there it is, merged on very latest main 🤞

@codecov
Copy link
Copy Markdown

codecov bot commented Feb 26, 2023

Codecov Report

Merging #8150 (446e661) into main (b27c770) will increase coverage by 0.00%.
The diff coverage is n/a.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #8150   +/-   ##
=======================================
  Coverage   68.87%   68.88%           
=======================================
  Files         617      617           
  Lines       99259    99259           
=======================================
+ Hits        68362    68371    +9     
+ Misses      30897    30888    -9     
Impacted Files Coverage Δ
crates/nu-parser/src/parser.rs 83.82% <0.00%> (+0.18%) ⬆️

@amtoine
Copy link
Copy Markdown
Member Author

amtoine commented Feb 26, 2023

@sholderbach
cool it worked 🤩

@sholderbach
Copy link
Copy Markdown
Member

What is the general status? I would favour landing as soon as possible so potential bikeshedding can happen in their respective topical PRs.

@amtoine
Copy link
Copy Markdown
Member Author

amtoine commented Feb 27, 2023

What is the general status? I would favour landing as soon as possible so potential bikeshedding can happen in their respective topical PRs.

as been already said, that might be a good start, at least i've done what i had in mind for this very first PR 👍

@fdncred
Copy link
Copy Markdown
Contributor

fdncred commented Feb 27, 2023

Let's land this and keep building.

@fdncred fdncred merged commit 9e589a9 into nushell:main Feb 27, 2023
@amtoine amtoine deleted the feature/first-draft-of-the-standard-library branch February 28, 2023 17:19
amtoine added a commit to goatfiles/nu_scripts that referenced this pull request Mar 4, 2023
@fdncred fdncred added the A:std-library Defining and improving the standard library written in Nu label Mar 14, 2023
fdncred pushed a commit that referenced this pull request Mar 28, 2023
Related to #8150, #8635 and #8632.

# Description
i've introduced a bad set of tests for the `assert equal` command in
#8150...

they should not compare `1 + 2` and `4)` or `3)` but the ints.

in this PR, i remove this spurious parentheses that were not planned at
all 😬 👀


# User-Facing Changes
```
$nothing
```

# Tests + Formatting
```
>_ nu crates/nu-utils/standard_library/tests.nu
INF|2023-03-28T20:18:13.022|Running tests in test_asserts
INF|2023-03-28T20:18:13.173|Running tests in test_dirs
INF|2023-03-28T20:18:13.247|Running tests in test_logger
INF|2023-03-28T20:18:13.473|Running tests in test_std
```

# After Submitting
```
$nothing
```
WindSoilder pushed a commit to WindSoilder/nushell that referenced this pull request Mar 29, 2023
Related to nushell#8150, nushell#8635 and nushell#8632.

# Description
i've introduced a bad set of tests for the `assert equal` command in
nushell#8150...

they should not compare `1 + 2` and `4)` or `3)` but the ints.

in this PR, i remove this spurious parentheses that were not planned at
all 😬 👀


# User-Facing Changes
```
$nothing
```

# Tests + Formatting
```
>_ nu crates/nu-utils/standard_library/tests.nu
INF|2023-03-28T20:18:13.022|Running tests in test_asserts
INF|2023-03-28T20:18:13.173|Running tests in test_dirs
INF|2023-03-28T20:18:13.247|Running tests in test_logger
INF|2023-03-28T20:18:13.473|Running tests in test_std
```

# After Submitting
```
$nothing
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A:std-library Defining and improving the standard library written in Nu

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants