Commit Graph

42 Commits

Author SHA1 Message Date
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
4520fc7fd4 pkg/eval: Move time-related builtins to separate file. 2022-11-26 10:41:58 +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
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
Kurtis Rader
eb1770f2b9 Add a benchmark command
Resolves #1586
2022-10-23 23:37:07 +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
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
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
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
f7b5df5de5 Add a new "call" command. 2021-12-29 01:16:44 +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
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
Qi Xiao
e299010be8 pkg/eval: Export the config fields and remove access methods. 2021-10-05 00:53:38 +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
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
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
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
675812c608 Fixup for #1321. 2021-06-06 22:01:41 +01:00
Qi Xiao
16dc290775
Merge branch 'master' into sleep-values 2021-06-06 21:52:27 +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
956c4c9d8f Fix sleep handling of the new num type
Fixes #1317
2021-05-23 20:17:51 -07:00
Qi Xiao
b53a92b964 Remove all builtin commands deprecated since 0.15.0. 2021-04-08 23:07:50 +01: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
50c971e5dd pkg/eval: Split test functions. 2021-01-10 16:43:21 +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
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
e4cebea152 pkg/eval: Simplify the tests for -source by running them in a temp dir. 2020-12-29 13:46:03 +00:00
Qi Xiao
f3c2185dae pkg/eval/evaltest: Move Must* functions to the testutil package.
Also exclude those functions from test coverage calculation.
2020-09-04 21:57:20 +01:00
Qi Xiao
90a99c1792 pkg/eval/evaltest: Consolidate all the Throws* methods into one. 2020-09-04 20:31:47 +01:00
Qi Xiao
bb122024dd pkg/eval: Move test framework into new evaltest package. 2020-09-03 06:51:21 +01:00
Qi Xiao
48919bcb24 pkg/: Move test utilities from util/ to testutil/. 2020-09-03 04:55:16 +01:00
Kurtis Rader
fd64782e2c Improve test coverage of pkg/eval/external_cmd.go
Improve coverage of pkg/eval/external_cmd.go from 58.3% to 86.1% as
measured by `make test` on macOS.

This would have been a smaller change but I felt it was important to
actually validate the exception raised when an external command fails
rather than simply using `.ThrowsAny()`. That necessitated augmenting
the pkg/eval/testutils.go module.

Related #1062
2020-09-03 04:14:26 +01:00
Kurtis Rader
19e158d08a Document builtin sleep and add tests
I was reviewing test coverage and noticed that the `esleep`
implementation was undocumented and had no tests. This

a) implements `sleep` and deprecates `esleep`,

b) uses the Go time.ParseDuration function rather than assuming a
simple number of seconds,

c) documents the command,

d) adds tests of the function.

Related #1062
2020-08-31 20:22:47 +01:00
Qi Xiao
4659d9bcc6 Introduce a use-mod command.
This fixes #1113.
2020-08-17 00:11:25 +01:00
Qi Xiao
735d30c0ff Introduce a new eval command.
This fixes #230.
2020-08-16 23:04:10 +01:00
Qi Xiao
270c7f230e pkg/eval: Support passing any value to "fail". 2020-05-31 13:56:59 +01:00
Qi Xiao
90a34f2d19 pkg/eval: Support specifying a callback for the "time" builtin.
This fixes #295.
2020-04-26 21:11:01 +01:00
Qi Xiao
33da89f34f pkg/eval: Clean up API.
Unexport some of the test utilities, and remove unused AddDirer.
2020-04-10 18:10:42 +01:00
Qi Xiao
e45fdf7228 Move all libraries to new pkg/. 2019-12-23 20:00:59 +00:00