Commit Graph

736 Commits

Author SHA1 Message Date
Qi Xiao
19bd75db57 pkg/eval: Make the peach test cases print $best-run on failure. 2023-05-08 23:34:04 +01:00
Qi Xiao
0557e2a3be pkg/eval/evaltests: Make APIs of special matchers functions. 2023-05-08 23:27:53 +01:00
Qi Xiao
75ee4d0179 pkg/eval: Increase the base sleep time in peach's unit test to 2ms.
The previous value of 1ms caused some false positive on Cirrus's Linux ARM64 runner.
2023-05-07 22:38:22 +01:00
Qi Xiao
ae087dc1e4 pkg/eval: Don't use the new context.Cause API.
Elvish should still be buildable with Go 1.19.
2023-05-07 22:37:08 +01:00
Qi Xiao
f54fe608e8 Clean up some code from adding Context to Frame. 2023-05-07 21:49:27 +01:00
Qi Xiao
da576e221c pkg/eval: Use a Context inside Frame to pass interrupts. 2023-05-07 21:44:28 +01:00
Qi Xiao
6ecc2b306c Fixup for #1691. 2023-05-06 23:55:34 +01:00
Kurtis Rader
91c819d5d8 Add a &num-workers option to peach
Resolves #648
2023-04-16 20:34:55 -07:00
Qi Xiao
89bf04a802 pkg/eval: Construct ui.Text using the functions from the ui package.
This fixes #1668, because the crashing listbox rendering code uses "len(line) >
0" (where line is a ui.Text) to test whether it is non-empty. This test doesn't
work with the ui.Text constructed using "styled ''", which creates a ui.Text
with one empty segment.

The functions from the ui package are guaranteed to never return such ui.Text
instances, so switching the implementation of the styled builtin to functions
from the ui package fixes this.
2023-03-14 21:47:38 +00:00
Qi Xiao
0adf0ec147 Use the unix build tag.
The unix build tag is supported by Go 1.19.
2023-03-03 00:01:26 +00:00
Qi Xiao
67db2194c8 pkg/eval: Support slashes in relative command paths on Windows.
This fixes #1660.
2023-02-27 22:57:02 +00:00
Qi Xiao
34b115d7af Bump prog.DeprecationLevel to 19.
Remove use of float64 in tests, except for one that tests that it is deprecated.
2023-02-27 00:00:12 +00:00
Qi Xiao
5e1d0b6d3d Remove support for the "except" keyword.
It has been superseded by "catch" since the 0.18.0 release.
2023-02-26 23:55:48 +00:00
Qi Xiao
3845a2cf7f Expose stack traces in exceptions as opaque values.
Also document the correct way to compare the causes of exceptions.

This fixes #1632.
2023-02-26 23:52:26 +00:00
dunsany
9a26d6c645
Various has-key fixes (#1647)
* Correct slice indexing convention in code comment

A colon is not supported.

* Add more key slices tests

* Unify `has-key` tests with those from `pkg/eval/vals/has_key_test.go`

* Fix key slice format in documentation

Fixes #1646.

* Fix missing bracket

* Fix indexing

* Add more key slices `has-key` tests

* Fix `has-key` test expected value
2023-02-26 20:49:31 +00:00
dunsany
4172348398 Fix exception capture example 2023-02-04 14:37:10 +00:00
Qi Xiao
97a73e2d95 evaltest.capturePort -> eval.CapturePort.
Also rename the original eval.CapturePort to ValueCapturePort.
2023-01-15 16:44:25 +00:00
Qi Xiao
c7ed16d3cb pkg/eval/evaltest: Print byte output diff with go-cmp. 2023-01-15 16:44:25 +00:00
Qi Xiao
6166c13409 Remove superfluous content from example for the deprecate builtin. 2023-01-13 00:21:33 +00:00
Qi Xiao
0b0f5ba867 Add a new "conj" command for appending values to a list. 2023-01-04 18:57:08 +00:00
Qi Xiao
24640d3241 pkg/eval: Move tests of builtin commands to match implementation files. 2023-01-04 18:37:47 +00:00
Qi Xiao
de3a7fd1b3 Standardize spelling: UNIX -> Unix.
https://en.wikipedia.org/wiki/Unix#Branding contains a history of the spelling.
Follow Wikipedia in using Unix instead of UNIX.
2023-01-04 18:09:11 +00:00
Qi Xiao
7cbbd84b55 pkg/parse/cmpd: Handle nil in Primary.
This fixes a panic caused by "try { } catch".
2023-01-02 18:49:58 +00:00
Qi Xiao
08007a52ce website/cmd/md2html: Support implicit link targets to elvdoc sections.
For example, [`put`]() links to the elvdoc for "put".

Also remove the @cf macro now that implicit targets make it easier to link to
other elvdoc sections.
2023-01-02 02:36:58 +00:00
Qi Xiao
fcc6d23f14 pkg/mods/doc: Convert links to language.html to absolute links.
For example, a link to language.html#number is converted to point to
https://elv.sh/ref/language.html#number instead. Such links are quite common in
elvdocs.

Also convert all link destinations that use ./language.html to use language.html
instead, and add a check in tools/check-disallowed.sh to ensure that remains the
case.
2023-01-02 01:35:41 +00:00
Qi Xiao
629be7e297 Use path:is-dir in the example for $pwd. 2022-12-30 18:36:31 +00:00
Qi Xiao
7c52dd9545 Fix the example for $pwd to use new temporary assignment syntax. 2022-12-30 18:30:47 +00:00
Qi Xiao
833569303c Fixups for #1629. 2022-12-28 12:42:31 +00:00
Manuel Mendez
9fae00d125 eval: Add DeleteGlobal
Will be use by edit module soon.
2022-12-28 12:27:17 +00:00
Manuel Mendez
b178367ca7 eval: Fix godocs with wrong function name 2022-12-28 12:27:17 +00:00
Manuel Mendez
1ada9a5e22 ns: Add Ns.clone method
Does what it says on the tin.
2022-12-28 12:27:17 +00:00
Qi Xiao
5e6954dbf3 Add a doc: module for accessing documentation of Elvish modules.
This fixes #1432.
2022-12-26 21:36:07 +00:00
Qi Xiao
5a237d7888 pkg/eval: When compiling, emit autofixes for using unimported builtin modules. 2022-12-11 14:21:09 +00:00
Qi Xiao
78862465a4 pkg/diag: Include line:col of start position in Error and Show methods.
The Error methods used to show the start and end indices, while the Show methods
used to show line ranges.

Showing line:col of the start position seems to be pretty standard; both Go and
Rust do that.

I tried including the line:col of the end position too, but can't find a good
enough format.
2022-12-08 19:07:18 +00:00
Qi Xiao
7e6bd950b1 pkg/diag: Increase test coverage. 2022-11-30 12:57:02 +00:00
Qi Xiao
121509d8d2 pkg/eval: Preserve all compilation errors.
Multiple compilation errors are packed using diag.PackCognateErrors, like parse errors.
2022-11-30 01:40:03 +00:00
Qi Xiao
94ab1b5390 Generalize parse.Errors and move it to diag.
This generalized type will be used to pack multiple compilation errors.
2022-11-30 01:05:16 +00:00
Qi Xiao
3847235a14 pkg/diag: Split Errors into another package.
The Errors function is not related to diag.Error, so keeping it in the same
package is confusing.

Also unexport the MultiError type. This allows its Error method to be
simplified, as it can assume that it always contains at least 2 errors.
2022-11-29 22:13:02 +00:00
Qi Xiao
69715b05fe pkg/eval: Don't use panics for propagating compilation errors.
This also enables saving multiple compilation errors.
2022-11-29 21:17:13 +00:00
Qi Xiao
ff0feb4311 pkg/eval: Refactor index tracking out of argsWalker.
Also redesign the internal API a bit, and rename to argsGetter.
2022-11-29 21:17:07 +00:00
Qi Xiao
d3eda3dc88 pkg/eval: Remove leftover registration of time commands. 2022-11-26 15:22:18 +00:00
Qi Xiao
4520fc7fd4 pkg/eval: Move time-related builtins to separate file. 2022-11-26 10:41:58 +00:00
Qi Xiao
d44428f4c6 pkg/ui: Add more tests against Text and TextSegment. 2022-11-23 00:40:38 +00:00
Qi Xiao
dc523d45be website: Preserve $ in the HTML ID of docs for variables.
We are no longer using Pandoc, so this limitation can be lifted.

Also make @cf generate internal links where applicable in non-builtin modules:
"@cf mod:fn" in the doc of "mod" now links to just "#mod:fn" instead of
"mod.html#mod:fn".
2022-11-22 23:42:19 +00:00
Qi Xiao
980cf009ca Parse comment blocks preceding var and fn declarations as doc comments.
Convert all .elv files (including .d.elv files) to use this new format.
2022-11-22 22:59:31 +00:00
Qi Xiao
eed2f7dabc pkg/mods/file: file:is-tty interprets numbers as port numbers instead of FDs. 2022-11-21 11:30:14 +00:00
Qi Xiao
a3f4384495 Move all elvdocs into .d.elv files.
The elvdocs still use the old format (#elvdoc:fn or #elvdoc:var) for now, but
will be changed to "fn" and "var" forms soon.

Also remove the accidentally committed cmd/mvelvdoc. It has been used to perform
the conversion automatically but is not supposed to be committed.
2022-11-20 21:59:45 +00:00
Qi Xiao
08b7c91402 Fixup for #1616.
- Allow using &key and &less-than together.

- Simplify the implementation with a custom implementation of sort.Interface.
2022-11-20 21:48:23 +00:00
Qi Xiao
973e8e76e2 pkg/eval/vals: Avoid the .Name hack for allowing using $nil for callable.
Also add a test.
2022-11-20 19:31:07 +00:00
Kurtis Rader
306e2d7b8d
Issue 1570 order key option (#1616)
* Allow $nil for Callable options

Related #1570

* Add a `&key` option to the `order` command.

Resolves #1570

Co-authored-by: Qi Xiao <xiaq@users.noreply.github.com>
2022-11-20 19:10:19 +00:00
Qi Xiao
93e28d846b Fixup for #1618.
- Simplify the matcher for compilation errors.

- Various stylistic fixes.
2022-11-20 16:39:01 +00:00
Kurtis Rader
358e52a7f5 Make testing compilation errors more deterministic
A year ago I submitted a change to replace AnyError with tests for specific
errors (see https://github.com/elves/elvish/commit/87656c99).  This does
something similar for DoesNotCompile. This ensures the test does what
is implied and makes correlating specific unit tests with compilation
errors easier.

This includes a couple of changes to compilation error messages to improve
readability (IMHO) but those are not the primary purpose of this change.

Related #1560
2022-11-20 16:33:29 +00:00
Qi Xiao
a18aec1ac8 Fixup for #1598.
- Let file:is-tty always take one argument.

- Revert change to eval.ByteOutput.

- Make sys.IsATTY take a FD instead, to avoid the need to use os.NewFile. Using
  os.NewFile can cause the Go runtime to start polling the file, which
  interferes with Elvish's terminal reader.
2022-11-20 16:21:10 +00:00
Kurtis Rader
23c83323b6 Implement file:is-tty
Resolves #1263
2022-11-20 16:03:34 +00:00
Qi Xiao
6c6797b4c1 Remove use of "e.g.," and "i.e.,".
Some of the uses are replaced by plain English phrases like "such as", and the
remaining have the trailing commas removed.
2022-11-20 15:44:29 +00:00
Qi Xiao
3a0b1242ac Fixup for #1591.
- Keep more metrics than just the minimal duration.

- Change default &min-time to 1s.

- Don't allow unitless value as &min-time.

- Rename &on-run to &on-run-end, and &min-iters to &min-runs.
2022-11-20 15:13:25 +00:00
Qi Xiao
27f6ab2aa1 pkg/eval/errs: Fix misleading message in OutOfRange.Error.
The method returns a message saying that there is no valid value if ValidHigh <
ValidLow. This was useful when these fields were numbers, but since they are now
strings this no longer works.
2022-11-20 15:11:57 +00:00
Kurtis Rader
eb1770f2b9 Add a benchmark command
Resolves #1586
2022-10-23 23:37:07 +01:00
Qi Xiao
3ff0e4bcd9 pkg/eval: Check whether variable name is empty when parsing lvalue.
This fixes #1560.
2022-10-03 04:34:05 +01:00
Kurtis Rader
e896ac3c0e
Improve some compilation errors (#1617)
Quote variable names appearing in some compilation errors to improve
the clarity of those errors.
2022-10-03 04:22:46 +01:00
Qi Xiao
f8f0f3e889 Fixup for #1588 2022-08-29 12:29:24 +01:00
Kurtis Rader
eed6a995dd
Support comparing booleans (#1588)
Fixes #1585
2022-08-29 12:25:54 +01:00
Kurtis Rader
a549dba0ba Add missing "usage" text for three commands
I noticed this when testing my `help` command and noticed that
`help builtin:` produced three lines of "usage" text that did not
include a function or variable name.
2022-08-29 12:10:31 +01:00
Qi Xiao
8cb125c911 Improve documentation for %. 2022-08-29 12:09:43 +01:00
Kurtis Rader
c6e10f12a2 Some minor documentation fixes
Mostly elimination of duplicated words but also a few other fixes such
as the output of commands such as `%`.
2022-08-29 12:04:59 +01:00
Qi Xiao
629cc9c85e Fix elvdoc for compact. 2022-08-29 11:08:19 +01:00
Qi Xiao
acf470f104 New "compact" command.
This fixes #1453.
2022-08-28 22:58:37 +01:00
Qi Xiao
181c4dde55 pkg/eval: Create builtin_fn_stream_test.go.
Tests for functions defined in builtin_fn_stream.go are moved there.
2022-08-28 22:08:00 +01:00
Qi Xiao
3dcfa88c8d Remove go1.18 build tags as 1.18 is required. 2022-08-08 12:29:33 +01:00
Qi Xiao
1b8ccdbdbc pkg/eval: Deduplicate range implementations with generics. 2022-08-08 12:28:47 +01:00
Qi Xiao
551e246d96 webiste/cmd/macros: Strip leading $ from anchor targets of @cf.
Also add previously missing $'s in @cf arguments. This doesn't matter for the
anchor target, but matters for the link text.
2022-08-08 00:09:17 +01:00
Qi Xiao
9794eecd68 Add new runtime module.
This module provides $runtime:{lib-dirs rc-path effective-rc-path}. It will
likely grow in future.

This fixes #1385.
2022-08-08 00:09:02 +01:00
Qi Xiao
2e788c846d Run gofmt.
https://tip.golang.org/doc/go1.19#go-doc
2022-08-07 22:30:11 +01:00
Qi Xiao
bd569f8132 pkg/eval: Add a note about the use of echo in after-chdir's example. 2022-08-07 22:25:47 +01:00
Qi Xiao
46008d111b Add -randseed to set RNG seed.
This is used in ttyshots to get deterministic outputs.

This command is prefixed with - since I'd like to eventually move rand and
randint into their own module, so this command will be moved too.
2022-08-07 11:32:52 +01:00
Qi Xiao
41fc578002 Merge branch 'ttyshot' 2022-08-04 23:41:11 +01:00
Qi Xiao
40275b97f1 Rewrite elvdoc for styled and styled-segment.
Also document the behavior of ignoring SGR state in the 0.19.0 release notes.
2022-07-24 14:44:16 +01:00
Qi Xiao
42c6c3b1aa pkg/ui: Make styled text context-insensitive, and remove the "default" color.
Styled text is not supposed to "inherit" the current SGR styling context when
written to the terminal. This has always been the intention, but not correctly
implemented. This commit fixes that for both styled segments and styled texts.
Tests are amended to account for the difference in the output.

With context insensitivity correctly implemented, there is now no need for a
"default" color. It is functionally equivalent to a lack of color.

The parsing of SGR still needs to be aware of the codes 39 (default foreground)
and 49 (default background), but these codes are now translated into FgDefault
and BgDefault, which resets the foreground and background color fields.
2022-07-24 14:31:02 +01:00
Qi Xiao
ed97664695 pkg/eval: Test the exit command by faking os.Exit. 2022-06-23 20:25:01 +01:00
Qi Xiao
e0292dd298 Get coverage on IsStructMap methods with a hack. 2022-06-20 22:08:19 +01:00
Qi Xiao
4afbb71c07 Move pkg/testutil/must.go to a new pkg/must. 2022-06-20 20:29:14 +01:00
Qi Xiao
d2c005df45 pkg/eval: Test import of module with invalid UTF-8. 2022-06-20 00:14:25 +01:00
Qi Xiao
786b679509 pkg/eval: Cover more tilde expansion errors. 2022-06-20 00:08:33 +01:00
Qi Xiao
6723b9a226 Use consistent pattern for mutating variables in tests.
- Use testutil.Set.

- Only export such variables to tests.
2022-06-19 23:56:18 +01:00
Qi Xiao
94e43cd2fd pkg/eval: Add tests for errors in tilde expansion. 2022-06-19 23:34:36 +01:00
Qi Xiao
6a1e7b3996 pkg/shell: Add more daemon-related tests.
Also:

- Remove duplicate code for closing daemon client.

- Avoid using (*testing.T).TempDir - it uses test name in the path, which can
  exceed the limit of the address when calling bind(2):
  https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_un.h.html#tag_13_6
7_04
2022-06-19 21:45:36 +01:00
Qi Xiao
75ee261fcb pkg/eval: Remove access methods for exported fields.
The exported fields are intended to be mutated directly.
2022-06-18 19:01:59 +01:00
Qi Xiao
d48b6f1843 pkg/eval/vals: Replace MakeListFromStrings with a generic MakeListSlice. 2022-06-17 16:50:38 +01:00
Qi Xiao
ae9e6d1565 Fixup for #1531.
- Fix the handling of actual occurrences of U+FFFD.

- Fix an existing bug of QuoteVariableName("$\n").
2022-06-11 21:26:32 +01:00
Kurtis Rader
d0f6858b95 Correctly encode strings with invalid UTF-8
In addition to fixing the encoding bugs standardize on \xNN notation for
bytes rather than \uNNNN; e.g., \x00 rather than \u0000.

Also, update the documentation for double-quoted strings to include the
\e sequence.

Fixes #1528
2022-06-11 20:42:06 +01:00
Qi Xiao
68bce3b4a4 Clarify error message when writing values to port not supporting it.
This fixes #1516.
2022-06-07 20:29:34 +01:00
Qi Xiao
f42c2dda61 Make init value of $f~ actually identical to $nop~.
This fixes #1519.
2022-06-07 20:20:00 +01:00
Qi Xiao
8b0c7fdb36 Fix some lint warnings found on Windows. 2022-06-05 22:01:16 +01:00
Qi Xiao
d4dd11a981 pkg/eval/vars: Deexport EnvVariable, use Unset/IsSet via interface 2022-06-05 21:47:51 +01:00
Qi Xiao
26a66284a9 Fixup for #1551. 2022-06-05 16:01:10 +01:00
Tw
d27610b3e4 Fix undefined temporary environment restoring issue
Close #1536

Signed-off-by: Tw <tw19881113@gmail.com>
2022-06-05 15:41:19 +01:00
Kurtis Rader
71cd3835bc Don't dot import pkg/tt
Qualified imports of pkg/tt outnumber unqualified (27 to 24). Improve
consistency, and clarity, by changing the dot (unqualified) imports of
that package symbols to qualified.
2022-06-04 23:39:19 +01:00
Kurtis Rader
f681a73a1d Don't dot import pkg/testutil
Qualified imports of pkg/testutil outnumber unqualified (55 to 7). Improve
consistency, and clarity, by changing the dot (unqualified) imports of
that package symbols to qualified.
2022-06-04 23:39:19 +01:00
Kurtis Rader
14321f9e82 Make parse.Source naming more consistent
Fixes #1545
2022-05-29 17:36:29 +01:00
Kurtis Rader
7bae8f2df7 Correctly handle [..=-1] list indexing
Fixes #1518
2022-05-22 20:38:16 +01:00