Commit Graph

736 Commits

Author SHA1 Message Date
Qi Xiao
a57275564b Document relationship between *-env commands and E: namespace. 2022-05-22 20:13:17 +01:00
Qi Xiao
aa6d5a6257 Re-enable staticcheck, and fix issues it found. 2022-05-22 11:57:38 +01:00
Qi Xiao
dd3950cec0 Use the new testutil.Set in more places. 2022-04-11 21:55:59 +01:00
Qi Xiao
3a3b8f5700 pkg/edit/complete: Change Complete to take an Evaler.
The PureEvaler abstraction made things unnecessarily complex; it's better to
just create a real Evaler for tests is pretty.

The Evaler has a new ReplaceBuiltin method to make it easier to construct the
expected test result.
2022-04-11 21:39:29 +01:00
Qi Xiao
f8f60953ad Properly deprecate float64.
- Replace its use with "num" in documentation and test code.

- Add a new "inexact-num" for explicitly converting a number to inexact.

This fixes #1513.
2022-04-09 11:45:15 +01:00
Qi Xiao
6ec410753b evaltest: Fix diff output. 2022-04-07 20:46:30 +01:00
Qi Xiao
51e4d97568 interface{} -> any now that Elvish requires Go 1.18. 2022-03-20 16:17:19 +00:00
Qi Xiao
f7cb556d9b Require Go 1.18.
- Run "go fix" to remove legacy build tags

- Use staticcheck@master until it has a release that supports Go 1.18

- Turn off autocrlf for Windows tasks
2022-03-20 15:28:23 +00:00
Qi Xiao
957c8a7521 evaltest: Check that stderr is empty if PrintsStderrWith is not called.
Among other things, this will check for deprecation warnings. Also fix test code
that uses deprecated features.
2022-03-20 09:50:05 +00:00
Qi Xiao
5f1673c6c4 Use go-cmp to report unexpected test results.
cmp.Diff panics when comparing a struct that has unexported fields and no String
or Equal method, so change some structs to either export all their fields or
have an Equal method.

This fixes #1136.
2022-03-11 22:49:32 +00:00
Qi Xiao
e894ae5f82 Improve the syntax of "try".
* Require at least one of "except" or "finally" to be present. This fixes #1424.

* Rename "except" to "catch". The former will be deprecated from 0.18.0. This
  addresses #1497.
2022-03-01 13:57:00 +00:00
Qi Xiao
d7a9d38731 pkg/eval: Remove reference to the now-gone local: scope. 2022-02-20 23:30:47 +00:00
Qi Xiao
59459793e3 pkg/persistent: Cons -> Conj.
Cons was a misnomer for the operation of adding an element at the end of a
vector. Follow Clojure's naming here and call this operation Conj.
2022-01-05 22:34:55 +00:00
Qi Xiao
8ed351e386 Add a new "defer" command. 2022-01-05 00:12:35 +00:00
Qi Xiao
38d4553833 Update assignment syntax in docs.
- Also remove the section for the legacy assignment syntax.

- Also add a paragraph to "eval" about upvalues.
2022-01-03 19:45:39 +00:00
Qi Xiao
003557c22a Remove support for the legacy lambda syntax.
This fixes #664.
2022-01-03 00:47:41 +00:00
Qi Xiao
be1e144b45 Remove support for the "local:", "up:" and ":" special namespaces.
This fixes #1409.
2022-01-03 00:47:41 +00:00
Qi Xiao
3dd3b780b9 Remove legacy assignment syntax.
This fixes #645.
2022-01-03 00:47:41 +00:00
Qi Xiao
4fcffc5671 Remove most uses of the legacy assignment syntax.
The remaining few uses are in some of the tests, which will be removed later.

This addresses #645.
2022-01-03 00:47:41 +00:00
Qi Xiao
653c9f9d0f Remove dir-history, deprecated since 0.17.0. 2022-01-03 00:47:41 +00:00
Qi Xiao
3abf7f5510 Deprecate the legacy temporary assignment syntax from 0.18.0.
This addresses #1114.
2022-01-03 00:47:24 +00:00
Qi Xiao
11de899040 Add fuzz test for (*eval.Evaler).Check. 2022-01-01 23:52:08 +00:00
Qi Xiao
ae91cf7b1c Fix build on Go 1.16. 2021-12-31 21:13:41 +00:00
Qi Xiao
097e32b375 pkg/eval/vals: Add ReprPlain, Repr without pretty-printing.
Also de-export NoPretty now that it is no longer needed.
2021-12-31 21:05:07 +00:00
Qi Xiao
de3ac3166d Add a new conversion utility vals.ScanMapToGo. 2021-12-31 18:00:36 +00:00
Qi Xiao
e134ef51e3 Handle all-cap abbreviations in strutil.CamelToDashed.
Also remove support for the "name" field tag from eval.scanOptions - it's not
used anywhere and the use case it was intended for is handled by CamelToDashed.
2021-12-31 16:54:32 +00:00
Qi Xiao
d9e14da0db Export eval.Closure and (*eval.Frame).Fork. 2021-12-31 14:28:30 +00:00
Qi Xiao
4906c4aa28 Fix doc for the call builtin. 2021-12-31 12:46:47 +00:00
Qi Xiao
a8844a34f8 Check that blocks in control flows don't have arguments or options.
It is now a compile-time error if they do. This fixes #1456.
2021-12-30 13:49:48 +00:00
Qi Xiao
de5f0e0d32 Add new util vals.MakeListFromStrings. 2021-12-30 13:09:18 +00:00
Qi Xiao
7da15f48fb pkg/eval/vals: Add more conversion helpers.
Also update the comment in conversion.go.
2021-12-29 22:32:25 +00:00
Qi Xiao
f7b5df5de5 Add a new "call" command. 2021-12-29 01:16:44 +00:00
Qi Xiao
7da4b58f2f Revise doc for the builtin module.
- Revise the introduction section.

- Link to the notes on commands taking value inputs from all such commands.

- Revise the doc on the "all" command.

- Revise references to the builtin module from the language reference.
2021-12-28 12:01:35 +00:00
Qi Xiao
560bd17c17 pkg/eval: Break up builtin_fn_container.go.
- range -> builtin_fn_num.go

- all, one, take, drop, count, order -> new builtin_fn_stream.go

- repeat -> builtin_fn_io.go

- compare -> builtin_fn_pred.go
2021-12-26 12:22:14 +00:00
Christopher Loessl
bd76b46b8e
Doc update (#1457)
* docs(effective-elvish): follow same style as other docs

e.g., https://elv.sh/ref/language.html

* docs(builtin): ref from take to drop

* docs(language): remove mention of :up and :down ns

* docs(fundamentals): update to new lambda format

* docs(tour): update to new lambda syntax

* docs(builtin): update to new lambda syntax

* docs(language): update to new lambda syntax

* docs(unique-semantics): update to new lambda syntax

* docs(tour): fix typo

* Revert "docs(effective-elvish): follow same style as other docs"

This reverts commit db4306a400c61f5f7b6acec7a1e1f39feb9b1ba0.

https://github.com/elves/elvish/pull/1457#discussion_r775102178
2021-12-26 12:02:00 +00:00
Qi Xiao
c71f46642b Update eawk's doc.
* Remove a superfluous line break in the equivalent Elvish code.

* Keep code in transcripts on the same line to be correctly highlited.

* Add another example using digit-only argument names.
2021-12-17 19:53:30 +00:00
Qi Xiao
046e02869d pkg/eval/vals: Document the use of 0 in UnifyNums. 2021-12-17 10:52:44 +00:00
Qi Xiao
71e5bff8da Replace direct reference to persistent types with their aliases in eval/vals. 2021-12-17 00:21:20 +00:00
Qi Xiao
82d92ad467 pkg/eval/vals: De-export the Eq util and move into a _test file. 2021-12-16 23:55:24 +00:00
Qi Xiao
089752147a Fixup for #1447. 2021-12-13 01:23:14 +00:00
Kurtis Rader
87656c99fa Replace AnyError in tests with a specific error
The `AnyError` placeholder error can cause tests to succeed for errors
other than what was expected. That is, the use of `AnyError` can mask
bugs in a unit test. So replace it with the specific error, or error type,
the test expects to be raised.

This does not remove the anyError structure because it is used in
the TestCase.DoesNotCompile() method. To keep the size of this change
as small as possible I want to defer updating that use to a separate
change. However, remove the public AnyError var so future test writers
don't attempt to use it.
2021-12-13 01:08:24 +00:00
Qi Xiao
973fe39798 Implement the tmp special command.
This addresses #1114.
2021-12-09 22:12:38 +00:00
Qi Xiao
c1adf58b6d Document using "range n | each" to execute something n times.
This addresses #1433.
2021-12-08 00:32:32 +00:00
Qi Xiao
14a81d12f8 pkg/eval: Initialize ns variables to an empty ns, rather than nil.
This fixes #1257.
2021-12-06 00:18:09 +00:00
Qi Xiao
ab88de7c15 Fix ScanToGo's error message when ptr points to an interface.
When the destination to scan into is an interface, its zero value is simply a
nil interface, losing the information of the original type and resulting in
error messages like "need nil, got $actual-type".

ScanToGo now handles this case specifically, and uses the string representation
of the interface type in the error message.

Before:

~> ns []
Exception: wrong type of argument 0: wrong type: need nil, got list
~> var x~ = x
Exception: wrong type: need nil, got string

After:

~> ns []
Exception: wrong type of argument 0: wrong type: need !!hashmap.Map, got list
~> var x~ = x
Exception: wrong type: need !!eval.Callable, got string

This is still not ideal, since the "need" type is not given as an Elvish "kind",
but it's much less confusing than than old "need nil" messages.

This fixes #715.
2021-12-05 23:49:49 +00:00
Qi Xiao
82dda13def Fixup for #1435. 2021-12-05 20:51:17 +00:00
Qi Xiao
713a16bc6e
Merge branch 'master' into add-compare-builtin 2021-12-05 20:37:13 +00:00
Qi Xiao
b1154a95dc Fixup for #1439.
* Fix the case when start is near the overflow point and add regression tests.

* Rewrite the implementation in a less abstract way.

* Rewrite the elvdoc.
2021-12-05 20:22:44 +00:00
Kurtis Rader
2ba69c32dd Augment builtin:range to support counting down
Resolves #1436
2021-12-05 18:44:59 +00:00
Qi Xiao
64661d6b33 pkg/eval: Execute the last form in a pipeline on the current goroutine.
This simple optimization improves the performance of pipelines containing only
one form drastically. Pipelines containing more than one form also execute a
little bit faster.

A subset of the benchmark results, on MacBook Air M1 2020:

| Benchmark | Before      | After       | Speedup |
| --------- | ----------- | ----------- | ------- |
| nop       |  3398 ns/op | 934.1 ns/op | 3.6x    |
| nop-nop   | 13596 ns/op | 11423 ns/op | 1.2x    |
| put-x     |  4163 ns/op |  1611 ns/op | 2.6x    |
2021-12-02 00:34:36 +00:00
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