forked from github-linguist/linguist
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request github-linguist#2173 from github/moar-instrumentation
Instrument all calls and pass the blob, strategy and language candidates in the payload.
- Loading branch information
Showing
4 changed files
with
72 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
require_relative "./helper" | ||
|
||
class TestInstrumentation < Minitest::Test | ||
include Linguist | ||
|
||
class LocalInstrumenter | ||
Event = Struct.new(:name, :args) | ||
|
||
attr_reader :events | ||
|
||
def initialize | ||
@events = [] | ||
end | ||
|
||
def instrument(name, *args) | ||
@events << Event.new(name, args) | ||
yield if block_given? | ||
end | ||
end | ||
|
||
def setup | ||
Linguist.instrumenter = LocalInstrumenter.new | ||
end | ||
|
||
def teardown | ||
Linguist.instrumenter = nil | ||
end | ||
|
||
def test_detection_instrumentation_with_binary_blob | ||
binary_blob = fixture_blob("Binary/octocat.ai") | ||
Language.detect(binary_blob) | ||
|
||
# Shouldn't instrument this (as it's binary) | ||
assert_equal 0, Linguist.instrumenter.events.size | ||
end | ||
|
||
def test_modeline_instrumentation | ||
blob = fixture_blob("Data/Modelines/ruby") | ||
Language.detect(blob) | ||
|
||
detect_event = Linguist.instrumenter.events.last | ||
detect_event_payload = detect_event[:args].first | ||
|
||
assert_equal 3, Linguist.instrumenter.events.size | ||
assert_equal "linguist.detected", detect_event.name | ||
assert_equal Language['Ruby'], detect_event_payload[:language] | ||
assert_equal blob, detect_event_payload[:blob] | ||
assert_equal Linguist::Strategy::Modeline, detect_event_payload[:strategy] | ||
end | ||
end |