25
25
import java .util .HashMap ;
26
26
import java .util .List ;
27
27
import java .util .Map ;
28
+ import org .graalvm .options .OptionCategory ;
28
29
import org .graalvm .options .OptionDescriptors ;
30
+ import org .graalvm .options .OptionKey ;
31
+ import org .graalvm .options .OptionStability ;
29
32
import org .graalvm .options .OptionValues ;
30
33
31
34
/**
47
50
@ Registration (id = SimpleCodeCoverageInstrument .ID , name = "Simple Code Coverage" , version = "0.1" , services = SimpleCodeCoverageInstrument .class )
48
51
public final class SimpleCodeCoverageInstrument extends TruffleInstrument {
49
52
53
+ @ Option (name = "" , help = "Enable Simple Coverage (default: false)." , category = OptionCategory .USER , stability = OptionStability .STABLE )
54
+ static final OptionKey <Boolean > ENABLED = new OptionKey <>(false );
55
+
56
+ @ Option (name = "PrintCoverage" , help = "Print coverage to stdout on process exit (default: true)." , category = OptionCategory .USER , stability = OptionStability .STABLE )
57
+ static final OptionKey <Boolean > PRINT_COVERAGE = new OptionKey <>(true );
58
+
50
59
public static final String ID = "simple-code-coverage" ;
51
60
52
61
/**
@@ -67,10 +76,11 @@ public Map<Source, Set<SourceSection>> getSourceToNotYetCoveredSections() {
67
76
*
68
77
* This method is used to properly initialize the instrument. A common
69
78
* practice is to use the {@link Option} system to enable and configure the
70
- * instrument, as is done in this method. Defining {@link Option}s Sis shown
71
- * in the {@link CLI} class, and their usage can be seen in the
72
- * {@link SimpleCodeCoverageInstrumentTest} when the context is being
73
- * created.
79
+ * instrument, as is done in this method. Defining {@link Option}s as is
80
+ * shown in {@link #ENABLED} and {@link #PRINT_COVERAGE}, and their usage
81
+ * can be seen in the {@link SimpleCodeCoverageInstrumentTest} when the
82
+ * context is being created. Using them from the command line is shown in
83
+ * the runJsWithCoverage.sh script.
74
84
*
75
85
* @param env the environment for the instrument. Allows us to read the
76
86
* {@link Option}s, input and output streams to be used for reading and
@@ -82,9 +92,9 @@ public Map<Source, Set<SourceSection>> getSourceToNotYetCoveredSections() {
82
92
@ Override
83
93
protected void onCreate (final Env env ) {
84
94
final OptionValues options = env .getOptions ();
85
- if (CLI . ENABLED .getValue (options )) {
95
+ if (ENABLED .getValue (options )) {
86
96
enable (env );
87
- if (CLI . PRINT_COVERAGE .getValue (options )) {
97
+ if (PRINT_COVERAGE .getValue (options )) {
88
98
ensurePrintCoverage (env );
89
99
}
90
100
env .registerService (this );
@@ -202,15 +212,15 @@ public List<Integer> notYetCoveredLineNumbers(final Source source) {
202
212
*
203
213
* If the {@link TruffleInstrument} uses {@link Option}s, it is nesesery to
204
214
* specify which {@link Option}s. The {@link OptionDescriptors} is
205
- * automatically generated from the {@link CLI} class due to the
206
- * {@link Option.Group} annotation. In our case, this is the
207
- * {@code CLIOptionDescriptors } class.
215
+ * automatically generated from this class due to the {@link Option}
216
+ * annotation. In our case, this is the
217
+ * {@code SimpleCodeCoverageInstrumentOptionDescriptors } class.
208
218
*
209
219
* @return The class generated by the {@link Option.Group} annotation
210
220
*/
211
221
@ Override
212
222
protected OptionDescriptors getOptionDescriptors () {
213
- return new CLIOptionDescriptors ();
223
+ return new SimpleCodeCoverageInstrumentOptionDescriptors ();
214
224
}
215
225
216
226
/**
0 commit comments