Skip to content

Commit 05034cc

Browse files
committed
WIP
1 parent 4232c70 commit 05034cc

6 files changed

Lines changed: 134 additions & 12 deletions

File tree

assets/coverage-badge.svg

Lines changed: 1 addition & 1 deletion
Loading

coverage.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,32 @@ var (
2222
func StartCoverage() {
2323
Provenance = true
2424
coverage = true
25-
// Just in case the function is called again the function info is reset.
26-
coverageFuncs = coverageFuncs[:0]
2725
}
2826

2927
// StopCoverage stops collecting coverage data. Existing data is not changed.
3028
func StopCoverage() {
3129
coverage = false
3230
}
3331

32+
// Coverage returns the current state of coverage.
33+
func Coverage() bool {
34+
return coverage
35+
}
36+
37+
// ResetCoverage resets all the function use counts to zero. If a hard reset
38+
// then the coverage function list is also zeroed out.
39+
func ResetCoverage(hard bool) {
40+
if hard {
41+
coverageFuncs = coverageFuncs[:0]
42+
} else {
43+
for _, f := range coverageFuncs {
44+
if p := f.Provenance(); p != nil {
45+
p.count = 0
46+
}
47+
}
48+
}
49+
}
50+
3451
// WriteCoverage writes a coverage file. The file is a Lisp file containing
3552
// one list. The list starts with a property list of filenames and file
3653
// checksums. Each provenance element in the list contains filepath,

docs/notes.md

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,37 @@
55
---------------------
66

77
- add provenance
8+
- documentation function should replace _ and __ as needed and wrap lines
9+
- lisp functions
10+
- reset-coverage (hard)
11+
- write-coverage (filename &optional destination)
12+
- nil should return string mostly for testing or for progress analysis
13+
- test with defun
14+
- what to do with repl defined functions?
15+
- maybe keep counter of editor.evalForm() calls then REPL-<counter> as filename
16+
817

918
- use for stack trace
1019
- for tracing, maybe just add filename:line:col as a prefix and keep current the same otherwise
1120
- for non-file loaded skip that part (just use a few spaces for indent)
1221
- maybe just filepath base without .lisp then firstLine and firstColumn
13-
- options for tracing as globals?
14-
- just provenance
15-
- just functions (current)
16-
- both
22+
- options for error stack as globals?
23+
- *stack-trace-format*
24+
- :provenance (default)
25+
- provenance if available and function otherwise
26+
- :provenance-long (full file path)
27+
- :function
28+
- :both
29+
- :both-long
1730
- in AppendFull
31+
-
32+
1833
- coverage app
34+
- start with writing colorized file(s)
35+
- lisp code
36+
- where to put the code?
37+
- lisp dir in slip?
38+
- later could be interactive
1939
- lisp app for processing and coverage
2040
- add file checksum function to support lisp coverage
2141
- functions for terminal support?

pkg/gi/pkg.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,22 @@ func init() {
276276
Export: true,
277277
Doc: "are the command line arguments.",
278278
},
279+
"*provenance*": {
280+
Get: getProvenance,
281+
Set: setProvenance,
282+
Export: true,
283+
Doc: `If *provenance* is true function provenance information is collected.
284+
Function provenance is used in stack trace output as we as in coverage reports. If used it
285+
should be set to true at before loading files.`,
286+
},
287+
"*coverage*": {
288+
Get: getCoverage,
289+
Set: setCoverage,
290+
Export: true,
291+
Doc: `If *coverage* is true counts of the number of calls to functions with
292+
provenance information are collected for use when a call to write-coverage is made. If used
293+
it should be set to true at before loading files.`,
294+
},
279295
})
280296
for _, f := range []*flavors.Flavor{
281297
defLogger(),
@@ -443,3 +459,29 @@ func getAppArgs() slip.Object {
443459
}
444460
return args
445461
}
462+
463+
func getProvenance() (state slip.Object) {
464+
if slip.Provenance {
465+
state = slip.True
466+
}
467+
return
468+
}
469+
470+
func setProvenance(value slip.Object) {
471+
slip.Provenance = value != nil
472+
}
473+
474+
func getCoverage() (state slip.Object) {
475+
if slip.Coverage() {
476+
state = slip.True
477+
}
478+
return
479+
}
480+
481+
func setCoverage(value slip.Object) {
482+
if value == nil {
483+
slip.StopCoverage()
484+
} else {
485+
slip.StartCoverage()
486+
}
487+
}

pkg/repl/repl.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,13 @@ func SetConfigDir(dir string) {
125125
if Trace {
126126
fmt.Printf("Loading %q.\n", cfgPath)
127127
}
128-
pathname := slip.String(filepath.Join(slip.WorkingDir, cfgPath))
129-
code, listProvs := slip.ReadProv(buf, &scope, string(pathname), nil)
130-
_ = slip.CurrentPackage.Set("*load-pathname*", pathname)
131-
_ = slip.CurrentPackage.Set("*load-truename*", pathname)
128+
pathname := cfgPath
129+
if cfgPath[0] != '/' {
130+
pathname = filepath.Join(slip.WorkingDir, cfgPath)
131+
}
132+
code, listProvs := slip.ReadProv(buf, &scope, pathname, nil)
133+
_ = slip.CurrentPackage.Set("*load-pathname*", slip.String(pathname))
134+
_ = slip.CurrentPackage.Set("*load-truename*", slip.String(pathname))
132135
code.CompileWithProvenance(listProvs)
133136
code.Eval(&scope, nil) // TBD consider load-verbose and load-print
134137
} else {
@@ -141,7 +144,10 @@ func SetConfigDir(dir string) {
141144
}
142145
}
143146
if buf, err = os.ReadFile(customPath); err == nil {
144-
pathname := slip.String(filepath.Join(slip.WorkingDir, customPath))
147+
if customPath[0] != '/' {
148+
customPath = filepath.Join(slip.WorkingDir, customPath)
149+
}
150+
pathname := slip.String(customPath)
145151
_ = slip.CurrentPackage.Set("*load-pathname*", pathname)
146152
_ = slip.CurrentPackage.Set("*load-truename*", pathname)
147153
if Trace {

test/gi/pkg_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright (c) 2026, Peter Ohler, All rights reserved.
2+
3+
package gi_test
4+
5+
import (
6+
"testing"
7+
8+
"github.com/ohler55/slip/sliptest"
9+
)
10+
11+
func TestGlobalProvenance(t *testing.T) {
12+
(&sliptest.Function{
13+
Source: `(let ((orig *provenance*)
14+
result)
15+
(setq *provenance* nil)
16+
(addf result *provenance*)
17+
(setq *provenance* t)
18+
(addf result *provenance*)
19+
(setq *provenance* orig)
20+
result)`,
21+
Expect: "(nil t)",
22+
}).Test(t)
23+
}
24+
25+
func TestGlobalCoverage(t *testing.T) {
26+
(&sliptest.Function{
27+
Source: `(let ((orig *coverage*)
28+
result)
29+
(setq *coverage* nil)
30+
(addf result *coverage*)
31+
(setq *coverage* t)
32+
(addf result *coverage*)
33+
(setq *coverage* orig)
34+
result)`,
35+
Expect: "(nil t)",
36+
}).Test(t)
37+
}

0 commit comments

Comments
 (0)