Commit Graph

50 Commits

Author SHA1 Message Date
Qi Xiao
183927cffc Convert tests to transcript tests. 2024-01-30 20:21:39 +00:00
Qi Xiao
a1b30deb86 pkg/eval/evaltest: Rename TestWithFullSetup -> TestWithSetup.
The old TestWithSetup is now more accurately called TestWithEvalerSetup.
2023-07-22 23:04:18 +01:00
Qi Xiao
5a237d7888 pkg/eval: When compiling, emit autofixes for using unimported builtin modules. 2022-12-11 14:21:09 +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
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
Kurtis Rader
14321f9e82 Make parse.Source naming more consistent
Fixes #1545
2022-05-29 17:36:29 +01:00
Qi Xiao
dd3950cec0 Use the new testutil.Set in more places. 2022-04-11 21:55:59 +01:00
Qi Xiao
51e4d97568 interface{} -> any now that Elvish requires Go 1.18. 2022-03-20 16:17:19 +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
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
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
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
196eea21d4 Change module import path to src.elv.sh 2021-01-27 01:30:25 +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
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
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
9af4c83bf6 pkg/eval: Minor cleanups. 2021-01-05 16:05:34 +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
b44bbd9668 pkg/eval: Remove superfluous tests. 2021-01-04 14:36:53 +00:00
Qi Xiao
7932f58201 pkg/eval: Add a (*Evaler).Call method for calling a function.
Most of the places that need to directly call a function is in the edit package,
which need to call user-defined callbacks.

This change eliminates most call sites of NewTopFrame (including all call sites
outside the eval package). Remove the function and inline it in the remaining
few call sites.

Remove NewTopFrame means that the eval package no longer offers other packages
a way to construct Frame instances. This is intended: Frame is a relatively
low-level concept, and all code outside the eval package now uses the more
high-level Eval, Call, Check/CheckTree methods of *Evaler. The most notable
exception is packages that implement modules; they may still use Frame to access
the information kept in it, but they never construct Frame instances.

In future, the Frame type can be changed to an interface.
2021-01-03 18:57:11 +00:00
Qi Xiao
7663d9a0ce pkg/eval: Replace the NoExecute option of (*Evaler).Eval with a new Check method.
This method has the property that it always tries to compile the code even if
there is a parse failure. This is the more desirable behavior when checking
code: if there is a parse failure near the end of a chunk of code, the user may
like to learn about compile errors earlier in the code.
2021-01-03 16:01:24 +00:00
Qi Xiao
5642dc3756 pkg/eval: Test compile-time deprecations using (*Evaler).Eval. 2021-01-02 02:39:38 +00:00
Qi Xiao
dc59cbfeb4 pkg/eval: Make (*Evaler).Eval accept a Source instead of an Op.
Most callers can now call it with the source to evaluate, without having to call
ParseAndCompile first themselves.
2021-01-02 00:10:26 +00:00
Qi Xiao
6419f4524a Implement namespaces using slices instead of maps.
More related improvements and cleanups will be done in followup commits.

This fixes #1139.
2020-12-25 17:46:46 +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
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
Qi Xiao
4a130be641 pkg/eval: Move benchmarks to separte file. 2020-08-23 16:07:11 +01:00
Qi Xiao
bb24b63356 Remove builtin commands deprecated in v0.14.0. 2020-08-16 16:10:58 +01:00
Qi Xiao
e2f08af91b Change slice syntax to use .. instead of :.
Also support ..= for closed-range slices, a la Rust.

The old syntax is still supported, but deprecated.

This fixes #669.
2020-08-15 22:52:50 +01:00
Qi Xiao
663b10d8e2 Suppress deprecations by default.
The behavior is controlled by a global flag that will be flipped for the release
branch. A flag is available to force deprecations to be shown or hidden.
2020-04-26 21:26:53 +01:00
Qi Xiao
c767f92d01 Support compile-time deprecation.
This fixes #898.
2020-04-26 13:14:51 +01:00
Qi Xiao
20979b44a2 pkg/parse: Use Source values, not pointers.
The Source type is small enough that using values is likely more efficient.
2020-04-25 19:22:38 +01:00
Qi Xiao
b8505c7065 pkg/eval/source.go -> pkg/parse/source.go. 2020-04-25 18:26:17 +01:00
Qi Xiao
53a1eca9af pkg/eval: Remove New*Source functions.
All call sites of such functions are replaced with simple &Source{...}
expressions.
2020-04-25 13:22:07 +01:00
Qi Xiao
0c50e93ebd pkg/eval: Remove (*Evaler).EvalInTTY.
This is so that pkg/program/shell can get rid of the dependency on the standard
streams and can dependency-inject the files.
2020-04-16 00:11:23 +01:00
Qi Xiao
8292a5b166 pkg/eval: Remove Evaler.EvalSourceInTTY. 2020-04-15 00:04:23 +01:00
Qi Xiao
096ee354d6 pkg/eval: Simplify API for output capture. 2020-04-10 01:12:25 +01:00
Qi Xiao
11919e83ec [cleanup] pkg/eval: use diag.Ranging in op types. 2020-03-28 21:33:55 +00:00
Qi Xiao
06f9a2fdbe pkg/eval: Add test to reveal data races in Evaler. 2020-01-12 16:52:12 -05:00
Qi Xiao
ca945dcb7f pkg/eval: TestCase.Errors{With,} -> Throws{,Any}.
This is in preparation for supporting compilation errors. Also did some
cleanups.
2020-01-08 23:09:19 +00:00
Qi Xiao
10b4baf89c pkg/eval: NewInternalSource -> NewInternalGoSource. 2020-01-05 14:07:03 +00:00
Qi Xiao
e45fdf7228 Move all libraries to new pkg/. 2019-12-23 20:00:59 +00:00