-
Notifications
You must be signed in to change notification settings - Fork 144
Add a few basic tests for unboxing and RULES working #714
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
clyring
wants to merge
4
commits into
haskell:master
Choose a base branch
from
clyring:plugin-tests
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,14 @@ | ||
# small script to hackily work around the dependency cycle | ||
# 'bytestring -> [plugin] -> ghc -> bytestring' that prevents | ||
# the testsuite from using plugins, by renaming the library | ||
# to 'bytestring-plugins-hack' | ||
|
||
sed -E ' | ||
/Name:|build-depends:/s/bytestring/bytestring-plugins-hack/ ; | ||
s/if false && impl\(pluginTestsHack\)/if true/' \ | ||
bytestring.cabal > bytestring-plugins-hack.cabal | ||
|
||
mv bytestring.cabal bytestring.cabal.__MOVED_DURING_PLUGIN_TESTS__ | ||
cabal test --test-show-details=direct "$@" | ||
mv bytestring.cabal.__MOVED_DURING_PLUGIN_TESTS__ bytestring.cabal | ||
rm bytestring-plugins-hack.cabal |
This file contains hidden or 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 hidden or 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,98 @@ | ||
{-# LANGUAGE TemplateHaskell #-} | ||
|
||
{-# OPTIONS_GHC -O -dsuppress-all -dno-suppress-type-signatures -fplugin=Test.Tasty.Inspection.Plugin #-} | ||
|
||
module PluginTests (testSuite) where | ||
|
||
import qualified Data.ByteString as S | ||
import qualified Data.ByteString.Char8 as S8 | ||
import qualified Data.ByteString.Lazy as BL | ||
import qualified Data.ByteString.Lazy.Char8 as BL8 | ||
import Data.ByteString.Builder | ||
import Data.Word | ||
|
||
import Test.Tasty | ||
import Test.Tasty.ExpectedFailure | ||
import Test.Tasty.Inspection | ||
|
||
import PluginTests.Splices | ||
|
||
testSuite :: TestTree | ||
testSuite = testGroup "Inspection plugin tests" | ||
[ testGroup "Literals" $ | ||
[ testGroup "StrictByteString" | ||
[ $(hasNoStringyStuff 'pack_strict_foo) | ||
, $(inspectTest $ 'len_pack_strict_foo === 'literal_three) | ||
, $(hasNoStringyStuff 'pack_strict_literal) | ||
, $(inspectTest $ 'len_pack_strict_literal === 'literal_thirtyOne) | ||
, expectFail $ $(hasNoStringyStuff 'pack_strict_nonAscii) | ||
, expectFail $ $(hasNoStringyStuff 'pack_strict_literal_nonAscii) | ||
] | ||
|
||
, testGroup "Builder" | ||
[ $(hasNoStringyStuff 'builder_string8_foo) | ||
, $(hasNoStringyStuff 'builder_string8_literal) | ||
, $(hasNoStringyStuff 'builder_stringUtf8_foo) | ||
, $(hasNoStringyStuff 'builder_stringUtf8_literal) | ||
, $(hasNoStringyStuff 'builder_stringUtf8_nonAscii) | ||
, $(hasNoStringyStuff 'builder_stringUtf8_literal_nonAscii) | ||
] | ||
] | ||
|
||
, $(inspectTest $ 'append_pack_replicate_unboxing `hasNoType` ''S.ByteString) | ||
] | ||
|
||
foo_string_literal :: [Char] | ||
foo_string_literal = "foo" | ||
|
||
unicode_string_literal :: [Char] | ||
unicode_string_literal = "\0example\0 ... \xff \x1f530" | ||
|
||
pack_strict_foo :: S.ByteString | ||
pack_strict_foo = S8.pack foo_string_literal | ||
|
||
len_pack_strict_foo :: Int | ||
len_pack_strict_foo = S.length pack_strict_foo | ||
|
||
pack_strict_literal :: S.ByteString | ||
pack_strict_literal = S8.pack "some ascii literal of length 31" | ||
|
||
len_pack_strict_literal :: Int | ||
len_pack_strict_literal = S.length pack_strict_literal | ||
|
||
pack_strict_nonAscii :: S.ByteString | ||
pack_strict_nonAscii = S8.pack unicode_string_literal | ||
|
||
pack_strict_literal_nonAscii :: S.ByteString | ||
pack_strict_literal_nonAscii | ||
= S8.pack "this\0literal contains\x80\xf0\xff non-ascii characters" | ||
|
||
literal_three :: Int | ||
literal_three = 3 | ||
|
||
literal_thirtyOne :: Int | ||
literal_thirtyOne = 31 | ||
|
||
builder_string8_foo :: Builder | ||
builder_string8_foo = string8 foo_string_literal | ||
|
||
builder_string8_literal :: Builder | ||
builder_string8_literal = string8 "some ascii string literal" | ||
|
||
builder_stringUtf8_foo :: Builder | ||
builder_stringUtf8_foo = stringUtf8 foo_string_literal | ||
|
||
builder_stringUtf8_literal :: Builder | ||
builder_stringUtf8_literal = stringUtf8 "some other ascii string literal" | ||
|
||
builder_stringUtf8_nonAscii :: Builder | ||
builder_stringUtf8_nonAscii = stringUtf8 unicode_string_literal | ||
|
||
builder_stringUtf8_literal_nonAscii :: Builder | ||
builder_stringUtf8_literal_nonAscii | ||
= stringUtf8 "inline literal string containing \0special\0 and non-ASCII characters like \x2139" | ||
|
||
append_pack_replicate_unboxing :: Int -> Word8 -> Int | ||
append_pack_replicate_unboxing n c | ||
= S.count c $ S.append (S.pack [0..c]) (S.replicate n c) | ||
|
This file contains hidden or 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,45 @@ | ||
{-# LANGUAGE TemplateHaskellQuotes #-} | ||
|
||
module PluginTests.Splices where | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you please add an explicit export list? |
||
|
||
import Test.Tasty | ||
import Test.Tasty.Inspection | ||
import Language.Haskell.TH | ||
|
||
import GHC.Base | ||
( unpackCString# | ||
, unpackAppendCString# | ||
, unpackCStringUtf8# | ||
, unpackAppendCStringUtf8# | ||
, unpackNBytes# | ||
, unpackFoldrCString# | ||
, unpackFoldrCStringUtf8# | ||
) | ||
import Language.Haskell.TH (Name) | ||
|
||
unpackCString_functions_without_foldr :: [Name] | ||
unpackCString_functions_without_foldr = | ||
[ 'unpackCString# | ||
, 'unpackAppendCString# | ||
, 'unpackCStringUtf8# | ||
, 'unpackAppendCStringUtf8# | ||
, 'unpackNBytes# | ||
] | ||
|
||
unpackCString_functions_all :: [Name] | ||
unpackCString_functions_all = | ||
[ 'unpackFoldrCString# | ||
, 'unpackFoldrCStringUtf8# | ||
] ++ unpackCString_functions_without_foldr | ||
|
||
hasNoStringyStuff :: Name -> Q Exp | ||
hasNoStringyStuff n = flip inspectObligations n | ||
[ (`hasNoTypes` [''Char, ''[]]) | ||
, (`doesNotUseAnyOf` unpackCString_functions_all) | ||
] | ||
|
||
hasNoStringyStuffExceptFolds :: Name -> Q Exp | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This one seems unused anywhere? |
||
hasNoStringyStuffExceptFolds n = flip inspectObligations n | ||
[ (`hasNoTypes` [''Char, ''[]]) | ||
, (`doesNotUseAnyOf` unpackCString_functions_without_foldr) | ||
] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do you feel about
chmod +x
on this file?