Commit Graph

736 Commits

Author SHA1 Message Date
Qi Xiao
9e6555a4fb pkg/eval: Reorganize benchmarks.
Use b.Run to run benchmarks. Also remove the dedicated tests for output capture.
2021-12-02 00:30:01 +00:00
Qi Xiao
a0b93968a3 Fix broken relative links. 2021-11-29 20:03:09 +00:00
Qi Xiao
b05fc3250c Fixup for #1440.
- Fix whitespace inconsistency

- Fix comment in parse/parse.go
2021-11-28 21:32:41 +00:00
Kurtis Rader
d4b4edbbbe Replace legacy lambda with new lambda examples
I was surprised to see so many legacy lambda syntax examples in the
documentation. This replaces all of them with the new syntax -- excluding
the handful of cases meant to explicitly verify the legacy form is still
valid. This also adds a link to the issue in the release notes which
documents the change in syntax.

Related #664
2021-11-28 21:30:59 +00:00
Kurtis Rader
3068edaa5f Add a builtin:compare command
Expose the default comparison function used by the `builtin:order`
command as a command in its own right. This command is useful when
writing, in Elvish, something like `builtin:order`. Such as a semantic
version comparison command.

Resolves #1347
2021-11-21 19:32:25 -08:00
Qi Xiao
4df04d7cd4 Support omitting $low in randint.
Like range, it defaults to 0 when omitted.
2021-11-20 15:07:26 +00:00
Qi Xiao
6a5619b01e Simplify the doc for randint. 2021-11-20 14:57:03 +00:00
Qi Xiao
2463a9ad10 pkg/eval: Link to Wikipedia for the interval notation in the doc for randint. 2021-11-19 16:32:29 +00:00
Kurtis Rader
c59e01abfc Document the use of slurp with printf
A recent IM question, and subsequent discussion, resulted in @hhanche
commenting that if you need to explicitly move the output of `printf`
from the byte to the value stream you should use `slurp` rather than
`put` or `from-lines`. Include that insight in the `printf`
documentation.
2021-11-14 16:19:46 +00:00
Kurtis Rader
8faf8930b3 Add use unit tests and tweak documentation
This explicitly tests a common error case not currently verified by the
existing unit tests. Thus improving test coverage by one line.  :-)
2021-11-14 16:17:51 +00:00
Qi Xiao
5198e38f28 Advice against "useless use of put". 2021-11-07 23:36:56 +00:00
Qi Xiao
c1dce661b7 Fix use of the builtin module via explicit "builtin".
Some of the variables are added after the Evaler is created, but that change was
not synchronized back to the copy of the builtin module that is imported with
"use builtin".

This fixes #1414.
2021-10-28 22:28:13 +01:00
Qi Xiao
d71e52cbd7 Refactor the API of eval.NsBuilder to be completely based on methods. 2021-10-23 21:44:11 +01:00
Qi Xiao
b570b2f0b5 pkg/eval: Clean up the Ns type a bit. 2021-10-23 18:18:31 +01:00
Qi Xiao
a91852b0a7 Fix tests broken by last commit. 2021-10-22 17:44:57 +01:00
Qi Xiao
fc66ad1d10 pkg/eval/vals: Remove support for the legacy a:b slice syntax.
This syntax was deprecated in 0.15.0 and no longer documented since then.
2021-10-22 17:41:09 +01:00
Qi Xiao
b12c29fb53 pkg/eval: Remove unnecessary methods of *Ns and *staticNs. 2021-10-16 12:50:45 +01:00
Qi Xiao
6822e2ca7b Deprecate the local: and up: special namespaces in 0.17.
Also deprecate the use of a leading empty namespace.

This addresses #1409.
2021-10-15 22:45:02 +01:00
Qi Xiao
4b218d9859 Deprecate the legacy lambda syntax from 0.17.x.
This addresses #664.
2021-10-14 23:10:29 +01:00
Qi Xiao
6a92571a23 Check assignments to read-only variable during compilation. 2021-10-13 23:57:14 +01:00
Qi Xiao
20e98c7479 Support new lambda syntax { |arg &opt=default| body }.
This addresses #664.
2021-10-13 22:47:16 +01:00
Qi Xiao
569d73c270 Deprecate the legacy assignment form from 0.17.0.
This addresses #645.
2021-10-12 23:25:45 +01:00
Qi Xiao
6a7d99041d pkg/eval: Require the variable used in "set" to already exist.
This has always been the documented behavior, but up until this point, "set"
actually behaved like the legacy assignment form, which creates the variable if
it doesn't exist yet.

This fixes the discrepancy. Addresses #645.
2021-10-10 14:31:09 +01:00
Qi Xiao
862cf5619d Support turning off implicit external command resolution.
See documentation in website/ref/language.html.

This fixes #978.
2021-10-07 01:21:28 +01:00
Qi Xiao
5b490475e7 pkg/testutil: ScaledMs -> Scaled, takes a time.Duration instead. 2021-10-05 01:02:54 +01:00
Qi Xiao
e299010be8 pkg/eval: Export the config fields and remove access methods. 2021-10-05 00:53:38 +01:00
Qi Xiao
fc754f6822 pkg/eval: Deliver message for finished bg job using editor notification.
This fixes #1067.
2021-10-05 00:08:14 +01:00
Qi Xiao
e70216421f pkg/eval: Remove more unnecessary mutex guards. 2021-10-04 23:27:06 +01:00
Qi Xiao
6eae543ecf pkg/eval: Remove unnecessary mutex guards. 2021-10-03 23:57:26 +01:00
Qi Xiao
1f362db665 pkg/eval: Add before-exit hook for daemon cleanup.
The daemon client in the Evaler is now only used by the dir-history builtin
command and can be removed when it is removed.
2021-10-03 23:16:20 +01:00
Qi Xiao
56038311da pkg/eval: Remove elvdoc for the removed path-* commands. 2021-10-03 23:03:52 +01:00
Qi Xiao
7e526534cd pkg/eval: Remove Eval.libInstallDir; it's not used anywhere. 2021-10-03 23:01:26 +01:00
Qi Xiao
c6d9ebc389 Add special command "coalesce".
This fixes #1404.
2021-10-03 19:14:44 +01:00
Qi Xiao
0571db69e2 Remove commands deprecated in 0.16.0, and deprecate dir-history. 2021-10-03 16:47:51 +01:00
Qi Xiao
68168da9fc pkg/eval: Convert elements of slice return value from a GoFn to individual outputs. 2021-10-03 16:34:52 +01:00
Qi Xiao
cd62d565ab pkg/eval: Small test coverage improvements. 2021-10-03 01:54:07 +01:00
Qi Xiao
3526f0284e pkg/eval: Increase coverage of builtin_fn_flow_test.go. 2021-10-03 01:09:08 +01:00
Qi Xiao
7a72b6346a Reorganize pkg/sys into portable and non-portable system utilities.
Non-portable ones are moved into new packages pkg/sys/e{unix windows}. The "e"
prefix is needed to avoid conflict with packages under golang.org/x/sys/ and can
mean "extra".
2021-10-02 13:14:00 +01:00
Qi Xiao
418ae40ea9 pkg/eval/evaltest: Update godoc (TestCase -> Case). 2021-09-15 20:19:25 +01:00
Qi Xiao
90d5d01cc5 pkg/eval/evaltest: Fix package godoc.
There was an empty line between the godoc and the package line by mistake.
2021-09-12 18:04:24 +01:00
Qi Xiao
7ef7cb9f1b pkg/eval/evaltest: Clean up godoc and some minor API details. 2021-09-12 14:13:18 +01:00
Qi Xiao
b6d69d0b30 pkg/prog/progtest: Rewrite the progtest API.
The progtest package now provides a declarative framework, modelled after
pkg/eval/evaltest. Tests that use progtest are now much more concise.
2021-09-12 14:06:05 +01:00
Qi Xiao
315a8b77e1 pkg/eval: Improve coverage of builtin_fn_container.go. 2021-09-11 14:51:26 +01:00
Qi Xiao
c07c26b4c7 pkg/eval/vals: Remove a duplicate test. 2021-09-11 13:57:53 +01:00
Qi Xiao
8c8a80ff52 Fix staticcheck error. 2021-09-11 02:58:54 +01:00
Qi Xiao
b36c9bf513 pkg/eval/vals: Improve coverage. 2021-09-11 02:54:34 +01:00
Qi Xiao
492ff19077 pkg/eval: Improve coverage of compile_lvalue.go. 2021-09-10 20:09:04 +01:00
Qi Xiao
276fe85bc3 pkg/eval: Improve coverage for builtin_fn_styled.go. 2021-09-10 19:39:20 +01:00
Qi Xiao
8713cb5b1c pkg/eval: Slightly improve coverage of glob.go. 2021-09-10 19:08:22 +01:00
Qi Xiao
6b6d3d5a95 pkg/eval: Improve coverage of glob.go. 2021-09-10 18:57:11 +01:00
Qi Xiao
47de83c7d1 Reorganize standard library modules.
- Move from pkg/eval/mods to pkg/mods

- Introduce mods.AddTo that adds all standard library modules

- Move epm and readline-binding into their own packages
2021-08-24 15:56:04 +01:00
Qi Xiao
e83640bce1 Fix mods/path test on Windows. 2021-08-23 00:46:43 +01:00
Qi Xiao
9076934395 Remove most uses of the ioutil package.
https://golang.org/doc/go1.16#ioutil
2021-08-23 00:36:26 +01:00
Qi Xiao
7fa09ac1d3 Use buffered channels with signal.Notify.
Both places act on the first signal received, so a buffer size of 1 is
sufficient.
2021-08-23 00:22:11 +01:00
Qi Xiao
d0be34c227 Run gofmt with Go 1.17.
This has created a lot of //go:build lines.
2021-08-23 00:19:49 +01:00
Qi Xiao
4d62732ebc Fix "indicies" -> indices. 2021-08-22 23:31:26 +01:00
Shengjing Zhu
5724ec4c47 Fix typos and add codespell to CI 2021-08-22 23:07:34 +01:00
Qi Xiao
92cb68fb32 Fix mods/path test on Go 1.17.
The TempDir and TempFile functions now return filenames starting with "./" when
the directory is ".".
2021-08-19 11:21:23 +01:00
Qi Xiao
437da2894e Fix epm lib path on Windows, and document the install paths. 2021-08-16 21:14:11 +01:00
Kolby Crouch
ba156db4d6 epm: fix for xdg-dir 2021-08-16 20:58:45 +01:00
Qi Xiao
1cc3faa15a Make use of (*testing.T).Cleanup in more places. 2021-08-06 23:49:11 +01:00
Qi Xiao
e9d328aa16 Make use of (*testing.T).Cleanup for test cleanups.
This allows turning the following pattern in tests:

  value, cleanup := setupSomething()
  defer cleanup()

into the following:

  value := setupSomething(t)
2021-08-06 23:21:23 +01:00
Qi Xiao
adf8066819 pkg/testutil: Make MustWriteFile easier to use.
The function now take a string for the file content, and always uses 0600 for
file permission.
2021-08-06 21:38:37 +01:00
Qi Xiao
e035930e49 Merge branch 'master' into xdg-dir 2021-08-05 22:36:53 +01:00
Qi Xiao
d8ff3e743e pkg/eval: Fill in default dummy ports in Evaler.prepareFrame.
Also fix the value of Frame.port in a benchmark.

This fixes #1355.
2021-08-01 21:38:30 +01:00
Kurtis Rader
57cf018e06 Update unit tests that use p[rw]close
Replaces uses of the deprecated builtin `prclose` and `pwclose` commands
with `file close` in unit tests.

This also fixes one test that was not verifying what it intended due to
it's use of `.Throws(AnyError)` which was matching an Elvish error caused
by invalid command `file:prclose $p`.
2021-08-01 21:17:02 +01:00
Kurtis Rader
2e94e3bf87 Update run-parallel example
Courtesy of @zzamboni this updates the example of how to use the
`run-parallel` command to capture the stdout and stderr byte streams
independent of each other.

Resolves #1357
2021-08-01 21:12:17 +01:00
Kurtis Rader
659bd5fa68 unix:umask should accept int number type
Fixes #1356
2021-07-12 20:38:22 +01:00
Qi Xiao
2d09e1a500 Implement XDG directory support.
Tests will be added in a followup commit before this branch is merged.

This addresses #383.
2021-07-10 02:20:59 +01:00
Qi Xiao
d15218f11e Fixup for #1354. 2021-07-07 23:25:01 +01:00
Kurtis Rader
85c499f110 Lint cleanups
This change addresses issues reported by the `staticcheck` tool and a
couple reported by the `golint` tool. It also adds missing issue links
to a couple of entries in the release notes. This change deliberately
does not address these warnings since it is unclear whether the project
owner would prefer to suppress or address them:

    pkg/store/cmd.go:8:2: should not use dot imports (ST1001)
    pkg/store/db_store.go:10:2: should not use dot imports (ST1001)
    pkg/store/dir.go:8:2: should not use dot imports (ST1001)
2021-07-07 23:21:02 +01:00
Qi Xiao
00c7205e81 Fixup for #1348. 2021-07-03 20:34:56 +01:00
Kurtis Rader
3ba0397c34 Add buildinfo and version vars
Introduce `builtin:buildinfo` and `builtin:version` vars. This also
changes the `-buildinfo -json` implementation to use the standard
encoding/json package rather than handcrafting the JSON string.

This also fixes three incorrect spellings of "overridden". Normally I would
do those in a separate change but since there are only three instances,
one of which one was legitimately part of this change, I decided to bundle
the other two.
2021-07-03 20:21:40 +01:00
Kurtis Rader
de9ae18fa8 Fix go vet error about unreachable code 2021-07-03 20:00:59 +01:00
Qi Xiao
9981b2a777 Reduce the flakiness of TestPeach with some random jitter.
There was a recent failure of the test that checks peach is
nondeterministic: https://github.com/elves/elvish/runs/2926941131

The failure can be reproduced reliably when setting GOMAXPROCS=1.
However, GitHub Action's Windows runner has two CPU cores, which means
GOMAXPROCS should be 2. Presumably, during that particular one, one of
the cores is occupied by another process, so Go had to run the
goroutines in order on one CPU core.

Go's time.Sleep yields the current goroutine and allow other scheduled
goroutines to run on the same thread. As a result, adding a random
jitter guarantees nondeterminism in execution order, even if only one
CPU core is available to execute threads.

Also run the nondeterminism check in an infinite loop.
2021-06-28 00:46:27 +01:00
Qi Xiao
a12e1be189 Implement Hash for *big.Int and *big.Rat. 2021-06-27 17:01:12 +01:00
Qi Xiao
4afab8804b Fixup for #1342. 2021-06-27 16:41:07 +01:00
Kurtis Rader
3da541c719 Other float64 cases that should be generalized
While pondering issue #1340 I looked at the other `case float64:`
blocks. This change generalizes the few places that need it.

Fixes #1340
2021-06-27 16:32:38 +01:00
Kurtis Rader
d303c37987 Test more combinations of Text/Segment+num
This fixes the *Segment.Concat and RConcat methods to handle the new
number types. It also adds more tests of concatenation with the "Text"
and "Segment" types with number types.

Related #1340
2021-06-27 16:32:38 +01:00
Qi Xiao
3d49f02593 Document that "eq" requires values to have the same type to be considered equal.
This fixes #1288.
2021-06-27 01:54:31 +01:00
Qi Xiao
5fa39e1155 Fix the sequencing between closing pipes and setting readerGone.
For some reason this wrong sequencing was only discovered on FreeBSD, and the
test reliably pass on macOS (likely differences in scheduling algorithms).

Also make the bug a bit easier to reproduce on FreeBSD by using an external
command on the reader side. Builtin commands are too quick to execute.
2021-06-25 13:51:52 +01:00
Qi Xiao
78852916a0 Change new tests in str_test.go to use backquote for consistency. 2021-06-24 23:28:10 +01:00
Qi Xiao
82b9bddb15 Test almost all commands correctly bubble output errors.
Also make the helper thatOutputErrorIsBubbled more precise by matching for the
exact error that is thrown.
2021-06-24 23:24:43 +01:00
Qi Xiao
a3fe485b22 pkg/eval: Test that all value-outputting commands throw on write error. 2021-06-22 00:40:45 +01:00
Qi Xiao
ce08c4a7d5 Throw exception when writing values to a port without a value component.
This is done by generalizing the mechanism used to detect that the reader of
value output has terminated.
2021-06-22 00:35:30 +01:00
Qi Xiao
f4cb00e618 pkg/eval: Test that all byte-outputting commands throw on write error. 2021-06-21 23:39:24 +01:00
Qi Xiao
70cb56b568 Merge branch 'master' into reader-gone 2021-06-20 22:22:37 +01:00
Qi Xiao
75fc7eb839 Don't panic when plugin's Ns variable has wrong type. 2021-06-20 22:13:49 +01:00
Kolby Crouch
917b6eeefc Add plugin support 2021-06-20 21:11:32 +01:00
Qi Xiao
a7c4bbb00f pkg/eval: Improve coverage for compile_value.go.
Most of the remaining untested lines have a dependency on fsutil.GetHome.
2021-06-20 19:14:12 +01:00
Qi Xiao
4776c16b2f Add more test for special forms.
Plus some minor test-related changes.
2021-06-20 18:18:45 +01:00
Qi Xiao
6e75f3468c Move API of pkg/store into pkg/storedefs.
This makes the nodaemon entrypoint not depend on boltdb at all, reducing its
size by 100KB (on darwin-arm64).
2021-06-19 01:54:00 +01:00
Qi Xiao
cfb6134236 Remove daemon:spawn.
The daemon module has never been documented and is not used by any code on GitHub:
https://github.com/search?q=%22use+daemon%22+extension%3Aelv&type=Code&ref=advsearch&l=&l=
arch&l=&l=
2021-06-19 01:07:29 +01:00
Qi Xiao
27eec7c8ee Reorganize the daemon module.
* Move client, spawning and activation code into pkg/daemon/client.

* Move API types into pkg/daemon/daemondefs.
2021-06-19 01:06:11 +01:00
Qi Xiao
6ced40733c pkg/eval: Fix EPIPE on Windows.
The syscall package exposes an EPIPE on Windows, but it's not what Windows APIs
return. The error number 232 is what is semantically EPIPE.
2021-06-18 00:45:25 +01:00
Qi Xiao
53dbece608 Fix style. 2021-06-18 00:16:20 +01:00
Qi Xiao
657b73122f Change all builtin commands writing value output to surface ReaderGone.
Also replace (*Frame).OutputChan with (*Frame).ValueOutput, which returns a
small interface for writing to the value output that is also aware when the
reader is gone.
2021-06-18 00:14:59 +01:00
Qi Xiao
321a4e78eb Merge branch 'master' into reader-gone 2021-06-15 22:09:40 +01:00
Qi Xiao
1fe1497c66 Add appropriate build tag on test for Unix-only exec command. 2021-06-15 20:28:49 +01:00
Qi Xiao
a70059aeb6 Test the exec builtin command. 2021-06-15 20:21:47 +01:00
Qi Xiao
3b7c18c6c5 pkg/eval/vals: Improve test coverage of index.go and iterate_keys.go.
This addresses #1234.
2021-06-15 19:22:58 +01:00
Qi Xiao
2e9e0289cc Make the kind of int, *big.Int and *big.Rat "number". 2021-06-15 19:22:38 +01:00
Qi Xiao
3f0e89d223 pkg/eval/vals: Test expected panics in num.go. 2021-06-15 19:11:57 +01:00
Qi Xiao
2093ac680f Increase coverage of pkg/eval/vals/index_list.go to 100%.
This addresses #1234.
2021-06-15 18:53:31 +01:00
Qi Xiao
83c81cc5b2 Fix unused symbols found by staticcheck.
Also consolidate pkg/sys/testutil_test.go into pkg/sys/select_test.go.
2021-06-15 17:46:31 +01:00
Qi Xiao
5cbb218dad Merge branch 'docset' 2021-06-14 22:50:00 +01:00
Qi Xiao
7d435154f5 Move doc for the epm module into its source. 2021-06-14 22:48:10 +01:00
Qi Xiao
56ce36f1aa Fix the file module's elvdoc.
- Fix broken anchors.

- Fix broken comment block of the pipe command.
2021-06-14 22:18:32 +01:00
Qi Xiao
162ae65b92 Fix elvdoc for file:close and platform:hostname. 2021-06-14 21:57:57 +01:00
Qi Xiao
3204e700ac Fixup for #1329 2021-06-13 22:54:47 +01:00
Kurtis Rader
9a576529a3 Replace ErrArgs with more specific errors
This also replaces the slightly awkward "arguments here" reason with
"argument count" as the "what" for a typical errs.ArityMismatch
exception. It also reformats most of the constructors so that the "what"
is on the same line. This makes `grep errs.ArityMismatch **.go` more
useful as a result.
2021-06-13 22:42:04 +01:00
Qi Xiao
a823eb8fbb Fix a broken link. 2021-06-13 16:27:36 +01:00
Qi Xiao
067c809fc5 Change all builtin commands that write to byte output to surface write errors.
Also replace (*Frame).OutputFile with (*Frame).ByteOutput, which returns a
small interface for writing bytes and converts EPIPE to ReaderGone.
2021-06-11 22:20:27 +01:00
Qi Xiao
3e9e7ce5c8 In elvdoc for to-terminated, use slurp to show byte output that includes NUL. 2021-06-11 14:49:43 +01:00
Qi Xiao
46fa331dca Fixup for #1308. 2021-06-10 09:14:15 +01:00
Kurtis Rader
267e015bd6 Add from-terminated and to-terminated commands
This change makes feeding output to commands which handle NUL terminated
"lines" (e.g., `fzf -read0` or `xargs -0`) extremely fast compared to
using an explicit Elvish loop that does `print $val"\x00"`. Similarly for
handling input from commands that produce NUL terminated "lines" (e.g.,
`find . -print0`) compared to an Elvish loop using `read-upto "\x00"`.

Resolves #1070
Related #1053
2021-06-10 09:06:15 +01:00
Qi Xiao
af3292418f Change math:pow to produce exact results in certain cases; deprecate math:pow10. 2021-06-10 01:47:59 +01:00
Qi Xiao
59e4a7302a Remove outdated TODO on math:round. 2021-06-10 00:11:52 +01:00
Qi Xiao
b7f2457820 Make all rounding functions in math: exactness-preserving.
This fixes #1331.
2021-06-10 00:10:50 +01:00
Qi Xiao
cb15a1e28e Fixup for #1332 2021-06-06 22:46:27 +01:00
Kurtis Rader
b8bc076d07 Increase pkg/eval/vars/env_list.go coverage to 100%
Related #1234
2021-06-06 22:43:45 +01:00
Kurtis Rader
a55b83c6f2 Increase pkg/eval/vars/env.go coverage to 100%
Related #1234
2021-06-06 22:39:09 +01:00
Qi Xiao
59b96f27d8
Merge branch 'master' into testutil-test-coverage 2021-06-06 22:03:34 +01:00
Qi Xiao
675812c608 Fixup for #1321. 2021-06-06 22:01:41 +01:00
Qi Xiao
79b5435f8a
Merge pull request #1321 from krader1961/sleep-values
Fix `sleep` handling of the new `num` type
2021-06-06 22:00:47 +01:00
Qi Xiao
c3594f0670 Fixup for #1322. 2021-06-06 21:59:30 +01:00
Kurtis Rader
3a73babdee Increase eawk test coverage to 100%
Related #1234
2021-06-06 21:56:23 +01:00
Qi Xiao
16dc290775
Merge branch 'master' into sleep-values 2021-06-06 21:52:27 +01:00
Qi Xiao
3cf5ab996f pkg/eval/vals: Make Pipe a PseudoStructMap.
It is in theory better implemented as a StructMap because it is a transparent
data type. However, the reflection-based algorithm for StructMap will create a
"kind" field for it, and we don't want to remove the custom kind of Pipe yet, so
this has to be a PseudoStructMap now.
2021-06-06 21:48:39 +01:00
Qi Xiao
a69ce8461e
Merge branch 'master' into pipe-close 2021-06-06 21:40:35 +01:00
Kurtis Rader
ff9341eb91 More error deduplication 2021-06-06 14:54:47 +01:00
Kurtis Rader
f5d38ab3d7 Eliminate duplicate error definitions
In light of the preceding change to address staticcheck lint warnings I
ran this:

    grep 'errors\.New("' **.go |
        sed -e 's/^.*errors\.New("\([^"]*\)".*/\1/' |
        sort | uniq -c | sort -n

Which caused me to notice two errors associated with the builtin `sleep`
command have multiple definitions. It is questionable whether the negative
duration error is justified. I think it should be replaced by the invalid
duration error but decided not to do that in order to limit the scope of
this change.
2021-06-06 14:54:47 +01:00
Kurtis Rader
9345125bd2 staticcheck lint cleanups
Fix two issues found by `staticcheck -tests=false ./...`:

pkg/eval/go_fn.go:155:5: var errNoOptions is unused (U1000)
pkg/persistent/hashmap/hashmap.go:321:2: only the first constant in this group has an explicit type (SA9004)
2021-06-06 14:54:47 +01:00
Kurtis Rader
2b6b11c230 Exercise testutil.MustPipe
I noticed that testutil.MustPipe was not covered by any unit tests. This
converts the handful of places that should use it to do so. This changes
the coverage of pkg/testutil/must.go from 61.5% to 73.1%. There isn't
any way to increase that further without explicitly testing the panic
paths.
2021-06-02 20:29:34 -07:00
Qi Xiao
9361832251 Fixup for #1310 2021-05-31 22:13:24 +01:00
Qi Xiao
641690ed45
Merge branch 'master' into peach-unit-test 2021-05-31 21:33:10 +01:00
Qi Xiao
c39d03e973 Support all number types in the order command.
This fixes #1309.
2021-05-31 21:25:08 +01:00
Qi Xiao
8a2c9a24db pkg/eval/vals: Add an optimized version of UnifyNums for two numbers. 2021-05-31 21:02:12 +01:00
Kurtis Rader
20decc5976 Implement edit:command-history &dedup
This implements `&dedup` and `&newest-first` options for
`edit:command-history`. This makes it noticably cheaper to feed unique
command history into external commands like `fzf`.

Related #1053
Fixes #568
2021-05-30 23:49:46 +01:00
Kurtis Rader
f67c7ed387 A couple of TODO cleanups 2021-05-30 00:40:42 +01:00
Kurtis Rader
9b61cdc727 Be consistent about sync.WaitGroup var naming
Also, remove the unused dbStore.Waits() method. This came to my
attention while writing `peach` unit tests.
2021-05-30 00:40:42 +01:00
Qi Xiao
cc1a07b28b Fixup for file:truncate. 2021-05-30 00:32:30 +01:00
Supreet
fc28dddb38 file:truncate added to file module, with requested changes 2021-05-30 00:15:43 +01:00
Kurtis Rader
956c4c9d8f Fix sleep handling of the new num type
Fixes #1317
2021-05-23 20:17:51 -07:00
Kurtis Rader
3ded2fb772 Replace prclose and pwclose with file:close
Rather than having specialized commands make a `file:pipe` object
indexable so we can use the generic `file:close` command. This does not
address existing problems; such as builtins not failing when writing to
a `file:pipe` object if the read-end is closed.

Related #1316
2021-05-22 20:55:53 -07:00
Qi Xiao
641f0ebf04 Detect and suppress SIGPIPE caused by the next command in a pipeline exiting early.
This addresses #952.
2021-05-20 00:10:17 +01:00
Qi Xiao
fd70a5a274 pkg/eval/errs: Add ReaderGone error type.
Also fix the error message of SetReadOnlyVar.
2021-05-18 20:34:44 +01:00
Kurtis Rader
8a92716bd9 Add test coverage of peach
This also documents the behavior of `break` and `continue` when used in
the function passed to `peach`.

Related #1234
2021-05-17 19:28:45 -07:00
Qi Xiao
f7a82908e2 Reimplement some math functions to be exactness-preserving.
This addresses #1300.
2021-05-09 20:03:21 +01:00
Qi Xiao
79fe6947cf Reorder test cases in math.go and math_test.go. 2021-05-09 14:40:34 +01:00
Qi Xiao
320b77ea1b pkg/eval/vals: Convert any number type to float64.
This addresses #1300.
2021-05-09 14:32:50 +01:00
Qi Xiao
3d078ec653 pkg/eval/mods/path: Skip symlink tests if unable to create symlinks.
Creating symlinks requires a special permission on Windows, which the
use may not have.

Also remove the support for symlinks in testutil.ApplyDir. Because of
this issue on Windows, any test that requires creating symlinks needs to
be broken out to an individual test case, meaning that symlinks can't be
created alongside other files, so there is less benefit of keeping it
inside the same Dir structure.
2021-05-08 13:22:21 +01:00
Qi Xiao
b80f9ed09e pkg/eval/mods/path: Fix test on Windows. 2021-05-08 02:32:42 +01:00
Qi Xiao
b1d50754e2 Remove the NEXT-RELEASE.md symlink.
GitHub displays symlinks simply as the path of the destination, meaning
that we can't just link to it for the notes of the next release.
2021-05-05 22:26:12 +01:00
Kurtis Rader
e2f810048e Add $edit:after-command and $edit:command-duration
The `edit:after-command` hooks are called with a single argument:
a pseudo-map with these keys:

    "command": the command line that was run
    "duration": the execution duration in seconds
    "error": any error that occurred ($nil if no error occurred)

The `edit:command-duration` variable is the elapsed seconds (as a
float64) of the most recently run interactive command.

Resolves #1029
2021-05-05 22:17:19 +01:00
Qi Xiao
91b6f6dd72 Use the integrated persistent package. 2021-05-03 22:17:46 +01:00
Qi Xiao
543b123661 Add some design notes in eval/vals/num.go. 2021-05-02 01:17:27 +01:00
Qi Xiao
2ac9d891ca Improve readability of argument mismatch error message.
* Use 0-based indexing.

* Use more natural-sounding English.

Inspired by #1290.
2021-05-02 00:27:38 +01:00
Qi Xiao
9cd90c49bb Minor fixup for #1274. 2021-05-02 00:22:28 +01:00
Qi Xiao
698d55ef07
Merge branch 'master' into issue-1248 2021-05-01 19:17:17 -04:00
Qi Xiao
7b66e9f104 Minor fixups for #1273.
Also fix a test broken by bad merge.
2021-05-02 00:13:22 +01:00
Qi Xiao
82f1912c5e
Merge branch 'master' into readonly-var-msg 2021-05-01 19:06:39 -04:00
Qi Xiao
90acb4a242 Minor fixup for path:temp-{dir file}.
* Remove `MatchesRegexp` from eval/vals since it is not part of the
  Elvish value protocol.

* Simplify implementation of value matching in `eval/evaltest`.

* Documentation wording tweaks.
2021-04-25 23:03:44 +01:00
Kurtis Rader
bc37099c92 Add equivalent of mktemp as builtin commands.
This implements `path:temp-dir` and `path:temp-file`.

Resolves #1255
2021-04-25 17:34:23 -04:00
Qi Xiao
a2ba33f6c5 Remove unneeded tests.
These tests exercise the arity checking logic, which is implemented
generically for every builtin function and does not need to be tested
individually.
2021-04-19 23:49:09 +01:00
Supreet
8f2accb0b9 File module with pipe function. Pipe command marked deprecated in compiler.go and builtin_fn_io.go
Prclose and pwclose with Deprecation marked in specific file. Give
feedback regarding the test cases.

File module now has prclose and pwclose

Wrote test cases for prclose and pwclose, need better test cases

Deprecation for prclose and pwclose marked in respective files.
2021-04-19 18:48:22 -04:00
Qi Xiao
2a1eda6bb0
Fix elvdoc of the src command 2021-04-11 01:17:39 +01:00
Qi Xiao
9b276a3431 Replace references to f{open close} in file module's elvdoc. 2021-04-09 13:03:47 +01:00
Qi Xiao
42d6e94dd7 Remove support for $-exports-. 2021-04-09 00:02:40 +01:00
Qi Xiao
c30a6a2fbe Remove support for using a lone "a=b" for assignment. 2021-04-08 23:57:40 +01:00
Qi Xiao
b53a92b964 Remove all builtin commands deprecated since 0.15.0. 2021-04-08 23:07:50 +01:00
Qi Xiao
318c4c14fd Clean up temporary files properly in the test for the file: module. 2021-04-08 23:07:11 +01:00
Qi Xiao
e1552ab4f5 Minor fixes for the file module:
* Add to release notes.

* Fix the deprecation level of fopen and fclose.

* Fix format of elvdoc and add ref doc.

* Minor style adjustments.
2021-04-08 22:55:33 +01:00
Supreet
77c40b9abb Links file module, marks fopen and fclose deprecation in compiler.go
aand builtin_fn_io.go
2021-04-08 22:45:16 +01:00
Qi Xiao
c2a232a156 Merge branch 'num'
This fixes #241.
2021-04-08 00:43:19 +01:00
Qi Xiao
5eec2c049d Remove special treatment of the builtin: namespace.
This fixes #1227.
2021-04-08 00:42:58 +01:00
Qi Xiao
fd212c1f75 More doc, and add exact-num. 2021-04-07 07:05:08 +01:00
Qi Xiao
a5baad65f8 pkg/eval/vals: Clean up FromGo. 2021-04-06 22:38:56 +01:00
Qi Xiao
6052a4dc4a Remove the "fix int" terminology; just call it "int". 2021-04-06 22:35:58 +01:00
Qi Xiao
e2c4030728 pkg/eval: Handle non-positive step and overflow in the range builtin. 2021-04-06 22:33:02 +01:00
Qi Xiao
5c643181a4 Cleanup, docs and tests. 2021-04-05 20:48:22 +01:00
Kurtis Rader
12980c2719 Some golint cleanups 2021-04-05 15:31:53 +01:00
Qi Xiao
da67ba8a4a Use machine word (int) instead of int64 for fixnum. 2021-04-04 13:37:38 +01:00
Qi Xiao
4612b58759 Support exact integer and rational numbers. 2021-04-04 00:58:53 +01:00
Kurtis Rader
e2759f777b Initialize a command var to $nop~
You cannot assign $nil to a command var so that should not be the initial
value of `var x~`. Instead, assign $builtin:nop~.

Fixes #1248
2021-03-28 22:51:30 -07:00
Kurtis Rader
ddf9bf040e Correctly highlight read-only except var
Using a read-only variable as the target of an `except` clause should
highlight just the var name rather than the entire `try...except...`
statement.

Resolves #1258
2021-03-28 22:01:31 +01:00
Kurtis Rader
1e0885310e Include name in error msg setting a readonly var
When attempting to update a read-only var return an error struct rather
than a simple string (i.e., a Go `error` type).  This makes it possible
to include the var name in the error message.  This builds on commit
a33ecb2d that highlights the offending var name in the stack trace but
does not include the var name in the error message. With this change the
error message includes the offending var name.

Related #255
2021-03-26 18:38:22 -07:00
Qi Xiao
959120162b pkg/eval: Use cmpd.StringLiteral in one more place.
Also remove an unused method that is now superseded by the cmpd package.
2021-03-19 23:18:42 +00:00
Kurtis Rader
69a8adb2e9 Allow quoted var names in an except... block
Related #1258
2021-03-19 22:59:25 +00:00
Qi Xiao
b2591e95a7 Add new edit:clear command.
This fixes #1238.
2021-02-26 00:36:09 +00:00
Qi Xiao
634d71dcba Extract utilities for compound nodes into pkg/parse/cmpd. 2021-02-24 00:02:47 +00:00
Qi Xiao
e3b0b27931 Do not append slash after expanding ~username.
This fixes #1246.
2021-02-23 23:25:48 +00:00
Qi Xiao
a33ecb2da4 When variable cannot set, point to the variable in the stack trace.
This fixes #255.
2021-02-21 11:53:05 +00:00
Qi Xiao
5327ba3521 Make tests compatible with "go test -count n" (n > 1).
The "-count" flag causes the test functions to be invoked multiple times. Since
some tests mutate their test data or some global state, they will fail when
invoked with a count larger than 1.

This commit changes *some* of such tests to either avoid mutating the test data,
or resetting the global state. Some such tests still remain and will be fixed later.
2021-02-17 22:46:32 +00:00
Qi Xiao
ed854fa667 Remove edit:histlist:toggle-case-sensitivity; do smart-case matching. 2021-02-14 15:52:38 +00:00
Qi Xiao
ba7a72631c Fix readline-binding, and add a test. 2021-02-14 14:41:38 +00:00
Qi Xiao
3c4db682e9 Change path:is-{dir regular} to use Lstat.
This matches their behavior with the documentation regarding symlinks; both
should return false for symlinks.
2021-02-10 23:33:31 +00:00
Qi Xiao
c96bfade21 pkg/parse: Small API tweak. 2021-02-01 14:20:56 +00:00
Qi Xiao
e4fa1cf452 Run gofmt -s on pkg/eval/closure.go. 2021-01-27 01:44:28 +00:00
Qi Xiao
196eea21d4 Change module import path to src.elv.sh 2021-01-27 01:30:25 +00:00
Qi Xiao
ae98cc5272 Add a new "deprecate" command. 2021-01-24 15:32:24 +00:00
Qi Xiao
b87cc7b5de Add back support for circular module dependency.
This fixes #1226.
2021-01-24 14:10:45 +00:00
Qi Xiao
3bf95ec088 Fix the panic when referencing a module that calls edit:add-var.
This fixes #1225.
2021-01-21 01:05:33 +00:00
Qi Xiao
37c3c0b0de Deprecate the use of "a=b" for non-temporary assignment in 0.15.
It is still the syntax for temporary assignment; only using it as a standalone
command is deprecated.
2021-01-19 23:28:34 +00:00
Qi Xiao
fbfbef8531 pkg/eval: Move implementation of compile-time deprecation to compiler.go. 2021-01-19 23:20:23 +00:00
Qi Xiao
47d9766f5c Control deprecation warnings with a number instead of a bool.
Previously, to avoid showing deprecation warnings for the next release when the
user is running on HEAD, a boolean CLI flag -show-deprecations is introduced,
and is set to false in the master branch. The idea is that release branches will
have this default to true, so people running released versions will see
deprecations.

However, this means that people running on HEAD will never see any deprecations
unless they use this CLI flag, which is not ideal. This commit replaces the flag
bool -show-deprecations with a numerical -deprecation-level flag, which requests
deprecations that are active as of release 0.X to be shown. The default value of
this flag will be the minor version number of the *last* release, so that people
running HEAD will see as many deprecation warnings as people running the last
release would. This number will be bumped just before releases.
2021-01-19 21:37:36 +00:00
Kurtis Rader
87519a9d9c Fix typo in description of path:is-regular 2021-01-17 04:56:59 +00:00
Qi Xiao
d97c989219 Introduce edit:add-var and edit:add-vars.
This addresses #1138.
2021-01-17 01:33:25 +00:00
Qi Xiao
a16cd8dfa6 pkg/eval: Allow "var a:". 2021-01-17 01:17:35 +00:00
Qi Xiao
629144195b pkg/eval: Fix handling of the global scope in (*Evaler).Eval.
- Do not mutate ev.global if cfg.Global is not nil. This fixes #1223.

- Handle concurrent mutations correctly. This addresses #1138.
2021-01-17 00:36:18 +00:00
Kurtis Rader
be712d5405
Introduce the path: module (#1203)
* Introduce the `path:` module

This is based on https://github.com/elves/elvish/pull/1084 by @kolbycrouch
submitted five months ago. It addresses all of the feedback on that
change and includes other documentation and unit test improvements. It
also includes a couple of extensions to the original P.R., such as a
`path:is-abs` command.

I decided to resurrect that change because I want better support for
filesystem path manipulation so that users can replace non-portable
external commands such as `realpath` and `find` with Elvish builtins. This
is a baby step towards that goal.

Related #849

* Add a `path:is-regular` command

This adds a `path:is-regular` command.  This is for symmetry with the
`path:is-dir` command and the glob `[type:regular]` modifier.

It also adds support for symlinks in the `testutil.Applydir` function
and change the path unit test to use it.

* Rename path:real to path:eval-symlinks
2021-01-16 23:21:33 +00:00
Qi Xiao
072677351b Introduce "var" and "set".
Assignment using "foo = bar" instead of "var foo = bar" or "set foo = bar" is
not yet deprecated, but will be soon.

This addresses #645.
2021-01-16 06:11:37 +00:00
Qi Xiao
22dc0e6a6b Move parsing of ordinary assignment form to the compile phase.
This will unblock the implementation of the "var" special command.

This addresses #645.
2021-01-16 01:48:51 +00:00
Qi Xiao
5f7bcb91e5 Make the syntax for the argument of "del" consistent with assignment LHS.
This fixes #1218.
2021-01-13 23:27:38 +00:00
Qi Xiao
e833b74aa4 Document %% in the elvdoc of printf. 2021-01-11 21:49:11 +00:00
Qi Xiao
ff69171c9d Fix typo: interprete -> interpret 2021-01-11 12:00:55 +00:00
Qi Xiao
75f10573d4 Address feedback of #1200. 2021-01-10 18:34:34 +00:00
Qi Xiao
f1d1107e33 Fix the elvdoc of -source. 2021-01-10 17:08:59 +00:00
Qi Xiao
50c971e5dd pkg/eval: Split test functions. 2021-01-10 16:43:21 +00:00
Kurtis Rader
c67677fd8f Implement a printf builtin
There is more work to be done but this should address 99.9999% of the
expected uses of a `printf` builtin. Some corner cases which don't have
a POSIX analog, such as support for Elvish bool types will be implemented
in future changes.

Resolves #1132
2021-01-10 16:39:50 +00:00
Qi Xiao
2defb9c53a pkg/eval: Correctly handle variable lookup error during runtime.
This fixes #1214.
2021-01-10 13:30:07 +00:00
Qi Xiao
56ceeedd21 pkg/eval: Store variable deletion information in *Ns.
This fixes #1213.
2021-01-10 00:54:02 +00:00
Qi Xiao
8d1a6b34db pkg/eval/evaltest: Support testing evaluation of multiple code pieces.
Also use this to simplify TestMultipleEval in pkg/eval.
2021-01-10 00:08:58 +00:00
Qi Xiao
402861fcfb eval/evaltest: Simplify EvalAndCollect. 2021-01-10 00:04:07 +00:00
Qi Xiao
d84e9801b5 Don't compile the arguments of special commands twice.
This fixes #1204.
2021-01-09 23:33:24 +00:00
Qi Xiao
28f86fefc6 Fix non-first uses of a module.
The implementation of useOp has not been updated correctly to accomodate the
fact that the namespaces are no longer modified in place.

This fixes #1212.
2021-01-09 23:17:26 +00:00
Qi Xiao
02d9252b5d pkg/eval: Return bool instead error from (*Evaler)'s PurelyEval* methods. 2021-01-09 16:05:04 +00:00
Qi Xiao
9991b08fe0 Fix panic in completion of non-existing namespace variable.
This fixes #1209.
2021-01-09 15:54:12 +00:00
Qi Xiao
363b712f66 pkg/eval: Eliminate in-place mutations of *Ns.
This commit replaces scopeOp, the only remaining place that mutates *Ns in
place, with nsOp, which performs copy-on-write for *Ns.

As a result, the "eval" command no longer mutates the passed namespace. The
default namespace it uses is also changed to match the default of "-source" (an
amalgamated namespace from the local and upvalue scopes), making "-source $file"
equivalent to "eval (slurp <$file)", and formally deprecated.

Another result is that (*Evaler).Eval can now guard the mutation of the global
namespace with the mutex, making it concurrency-safe to execute multiple sources
that touch the global namespace.

This fixes #1137.
2021-01-09 15:02:15 +00:00
Qi Xiao
066b48cfd2 Make all builtin functions and subnamespaces read-only.
This fixes #1211.
2021-01-09 00:41:42 +00:00
Qi Xiao
af906f1d76 pkg/eval: Change all the *Op types to return Exception instead of error.
Also change the variable name used to keep the Exception returned from "err" to
"exc".

This uncovers several error scenarios that were not returning Exception, and
would result in the absense of stack traces when such errors occur.
2021-01-09 00:25:32 +00:00
Qi Xiao
b77a052e7e pkg/eval: Make Exception an interface.
This change is a preparation step for refining all *Op types to return Exception
as the error.

Keeping Exception as a struct type will make such a change error-prone, since
a (*Exception)(nil) != error(nil), so if an *Op returns a nil *Exception, it
is not nil if the return value is stored in an error-typed variable.
2021-01-08 00:56:45 +00:00
Kurtis Rader
5564c8f754 Fix handling of unexpected errors
Doing something like the following is likely to result in too many open
files (assuming `ulimit -n` == 256) resulting in a panic:

    > fn fact [n]{ if (== $n 0) { put 1 } else { put (* $n (fact (- $n 1))) } }
    > fact 60
    panic: interface conversion: error is *os.SyscallError, not
    *eval.Exception

    goroutine 24161 [running]:
    github.com/elves/elvish/pkg/eval.(*pipelineOp).exec.func1(0x152a5a0,
    0xc000dca210, 0xc000a44e70, 0xc00057b540, 0xc001030590, 0x203000)
        github.com/elves/elvish/pkg/eval/compile_effect.go:153 +0x152
    created by github.com/elves/elvish/pkg/eval.(*pipelineOp).exec
        github.com/elves/elvish/pkg/eval/compile_effect.go:149 +0x225
    Exception: elvish exited with 2

Fixes #1208
2021-01-07 22:34:22 +00:00
Qi Xiao
9af4c83bf6 pkg/eval: Minor cleanups. 2021-01-05 16:05:34 +00:00
Qi Xiao
af0c22c47a Move pkg/eval/resolve.go to pkg/edit, and add more introspection methods on *Ns. 2021-01-05 15:43:26 +00:00
Qi Xiao
5c55e72e78 pkg/eval: Update comments about the Elvish-Go interface. 2021-01-05 05:23:28 +00:00
Qi Xiao
2033600881 pkg/eval: Clean up Port related code. 2021-01-05 05:23:17 +00:00
Qi Xiao
6e8ecc8bd5 pkg/eval: Cleanups for reducing the API surface area number of files.
- Move NewEnvListVar to pkg/eval/vars.

- De-export GlobPattern, GlobFlag and ExternalCmd.

- Merge editor.go and chdir.go into eval.go, value_helper.go into compile_value.go.

- Remove eval_internal_test.go and replace it with a new test for $pid.
2021-01-05 04:33:52 +00:00
Qi Xiao
75baa0b5a2 pkg/eval: Remove (*Ns).Append.
This change makes Ns immutable from the exposed API. Internally there is exactly
one place that still mutates Ns, in scopeOp; this will be addressed later.
2021-01-05 01:09:04 +00:00
Qi Xiao
a2790af67a pkg/eval: Clean up the structure and methods of Evaler and Frame.
- Make Evaler mostly thread-safe. The only remaining thread-unsafe part is the
  modules field, which is more tricky than other fields.

- Remove the state and evalerScopes type, and move their fields into Evaler.

- Expose valuePrefix via a get method, and change PortsFromFiles to take the
  prefix instead of a *Evaler. Also expose a PortsFromStdFiles.

- Make Evaler a normal field of Frame, instead of an embedded field. This makes
  access to global states more explicit.
2021-01-05 00:22:09 +00:00
Qi Xiao
0a3d7ac02e pkg/eval: Fix $args.
This fixes #1207.
2021-01-04 21:04:17 +00:00
Qi Xiao
6c764d31d5 pkg/eval: Add mutex to Evaler, and remove that of deprecationRegistry.
The Evaler keeps global states and needs to be accessed concurrently. Mutations
to global states have fairly low throughput, so it makes sense to use a single
mutex.

On the other hand, the compiler is always used on a single thread, so it does
not need any mutex protection, so there is no need to put the mutex inside
deprecationRegistry.
2021-01-04 15:55:26 +00:00
Qi Xiao
b44bbd9668 pkg/eval: Remove superfluous tests. 2021-01-04 14:36:53 +00:00
Qi Xiao
1be25a240c pkg/eval: Internal cleanups.
- Remove the Op type; it is no longer used by any code outside the eval package
  and its use within the package is limited.

- Replace (*Evaler).execOp with (*Evaler).prepareFrame.
2021-01-04 14:17:27 +00:00
Qi Xiao
01612e291b pkg/eval: Clean up closure call implementation.
- Remove reliance on scopeOp, concentrating all the scope for creating the local
  scope in (*closure).call.

- Check options at the very beginning, and include all unsupported options in the
  error.
2021-01-04 13:46:00 +00:00
Qi Xiao
685f0a2593 Fix the example in the elvdoc for -source. 2021-01-03 22:59:24 +00:00
Qi Xiao
d844d80ebb Fix format of elvdoc for -source. 2021-01-03 22:36:13 +00:00
Qi Xiao
09b8dcdf2f Handle the global namespace correctly in the -source command.
The -source command now runs with a temporary namespace that is amalgamated
from the local and up namespace of the caller -source; this means that it can
no longer mutate its caller's local scope, which is the only possible sensible
behavior anyway.

This fixes #1202.
2021-01-03 22:31:55 +00:00
Qi Xiao
086038fa0f pkg/eval: Remove (*Evaler).Close. 2021-01-03 20:55:04 +00:00
Qi Xiao
5fbeb781ff pkg/eval: Remove (*Frame).Eval. 2021-01-03 20:54:35 +00:00