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.
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.
* 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.
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.
- 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.
* 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
* 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.
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.
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.
* 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.
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 |
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
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
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.
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.
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.
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".
- 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
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`.
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
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)
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.
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.
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
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.
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.
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.
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
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.
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.
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)
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.
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 #1053Fixes#568
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