Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 43afc03

Browse files
authored
Merge pull request #193 from ruby-syntax-tree/silent-tests
Make the test suite silent
2 parents 09c816c + a1981d7 commit 43afc03

File tree

3 files changed

+59
-14
lines changed

3 files changed

+59
-14
lines changed

README.md

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ It is built with only standard library dependencies. It additionally ships with
4646
- [textDocument/formatting](#textdocumentformatting)
4747
- [textDocument/inlayHint](#textdocumentinlayhint)
4848
- [syntaxTree/visualizing](#syntaxtreevisualizing)
49-
- [Plugins](#plugins)
50-
- [Customization](#customization)
49+
- [Customization](#customization)
50+
- [Plugins](#plugins)
5151
- [Languages](#languages)
5252
- [Integration](#integration)
5353
- [Rake](#rake)
@@ -320,6 +320,10 @@ Baked into this syntax is the ability to provide exceptions to file name pattern
320320
stree write "**/{[!schema]*,*}.rb"
321321
```
322322

323+
## Formatting
324+
325+
326+
323327
## Library
324328

325329
Syntax Tree can be used as a library to access the syntax tree underlying Ruby source code.
@@ -619,18 +623,45 @@ Implicity, the `2 * 3` is going to be executed first because the `*` operator ha
619623

620624
The language server additionally includes this custom request to return a textual representation of the syntax tree underlying the source code of a file. Language server clients can use this to (for example) open an additional tab with this information displayed.
621625

622-
## Plugins
626+
## Customization
627+
628+
There are multiple ways to customize Syntax Tree's behavior when parsing and formatting code. You can ignore certain sections of the source code, you can register plugins to provide custom formatting behavior, and you can register additional languages to be parsed and formatted.
629+
630+
### Ignoring code
631+
632+
To ignore a section of source code, you can a special `# stree-ignore` comment. This comment should be placed immediately above the code that you want to ignore. For example:
633+
634+
```ruby
635+
numbers = [
636+
10000,
637+
20000,
638+
30000
639+
]
640+
```
641+
642+
Normally the snippet above would be formatted as `numbers = [10_000, 20_000, 30_000]`. However, sometimes you want to keep the original formatting to improve readability or maintainability. In that case, you can put the ignore comment before it, as in:
643+
644+
```ruby
645+
# stree-ignore
646+
numbers = [
647+
10000,
648+
20000,
649+
30000
650+
]
651+
```
652+
653+
Now when Syntax Tree goes to format that code, it will copy the source code exactly as it is, including the newlines and indentation.
623654

624-
You can register additional customization and additional languages that can flow through the same CLI with Syntax Tree's plugin system. When invoking the CLI, you pass through the list of plugins with the `--plugins` options to the commands that accept them. They should be a comma-delimited list. When the CLI first starts, it will require the files corresponding to those names.
655+
### Plugins
625656

626-
### Customization
657+
You can register additional customization that can flow through the same CLI with Syntax Tree's plugin system. When invoking the CLI, you pass through the list of plugins with the `--plugins` options to the commands that accept them. They should be a comma-delimited list. When the CLI first starts, it will require the files corresponding to those names.
627658

628-
To register additional customization, define a file somewhere in your load path named `syntax_tree/my_plugin`. Then when invoking the CLI, you will pass `--plugins=my_plugin`. To require multiple, separate them by a comma. In this way, you can modify Syntax Tree however you would like. Some plugins ship with Syntax Tree itself. They are:
659+
To register plugins, define a file somewhere in your load path named `syntax_tree/my_plugin`. Then when invoking the CLI, you will pass `--plugins=my_plugin`. To require multiple, separate them by a comma. In this way, you can modify Syntax Tree however you would like. Some plugins ship with Syntax Tree itself. They are:
629660

630661
* `plugin/single_quotes` - This will change all of your string literals to use single quotes instead of the default double quotes.
631662
* `plugin/trailing_comma` - This will put trailing commas into multiline array literals, hash literals, and method calls that can support trailing commas.
632663

633-
If you're using Syntax Tree as a library, you should require those files directly.
664+
If you're using Syntax Tree as a library, you can require those files directly or manually pass those options to the formatter initializer through the `SyntaxTree::Formatter::Options` class.
634665

635666
### Languages
636667

test/ractor_test.rb

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,33 @@ def test_formatting
2020
source = SyntaxTree.read(filepath)
2121
program = SyntaxTree.parse(source)
2222

23-
Ractor.new(source, program, name: filepath) do |source, program|
24-
SyntaxTree::Formatter.format(source, program)
23+
with_silenced_warnings do
24+
Ractor.new(source, program, name: filepath) do |source, program|
25+
SyntaxTree::Formatter.format(source, program)
26+
end
2527
end
2628
end
2729

28-
ractors.each(&:take)
30+
ractors.each { |ractor| assert_kind_of String, ractor.take }
2931
end
3032

3133
private
3234

3335
def filepaths
3436
Dir.glob(File.expand_path("../lib/syntax_tree/{node,parser}.rb", __dir__))
3537
end
38+
39+
# Ractors still warn about usage, so I'm disabling that warning here just to
40+
# have clean test output.
41+
def with_silenced_warnings
42+
previous = $VERBOSE
43+
44+
begin
45+
$VERBOSE = nil
46+
yield
47+
ensure
48+
$VERBOSE = previous
49+
end
50+
end
3651
end
3752
end

test/rake_test.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,11 @@ def invoke(task_name)
4646
invocation = nil
4747
stub = ->(args) { invocation = Invocation.new(args) }
4848

49-
begin
49+
assert_raises SystemExit do
5050
SyntaxTree::CLI.stub(:run, stub) { ::Rake::Task[task_name].invoke }
51-
flunk
52-
rescue SystemExit
53-
invocation
5451
end
52+
53+
invocation
5554
end
5655
end
5756
end

0 commit comments

Comments
 (0)