Giter Site home page Giter Site logo

spectre's Introduction

Spectre

Build Status

Special Executive for Command-line Test Running and Execution.

A behavior-driven development (BDD) framework and test runner for Swift projects and playgrounds. It's compatible with both OS X and Linux.

Usage

describe("a person") {
  let person = Person(name: "Kyle")

  $0.it("has a name") {
    try expect(person.name) == "Kyle"
  }

  $0.it("returns the name as description") {
    try expect(person.description) == "Kyle"
  }
}

Reporters

Spectre currently has two built-in reporters, Standard and the Dot reporter. Custom reporters are supported, make a type that conforms to Reporter.

The default reporter can be configured via an environment variable. For example:

$ env SPECTRE_REPORTER=dot swift test
$ env SPECTRE_REPORTER=tap swift test

Standard

The standard reporter produces output as follows:

Passing Tests

Standard Reporter Success

Failing Tests

Standard Reporter Failure

Dot

Using the -t argument, you can use the dot reporter.

Passing Tests

Dot Reporter Success

Failing Tests

Dot Reporter Failure

Expectation

Equivalence

try expect(name) == "Kyle"
try expect(name) != "Kyle"

Truthiness

try expect(alive).to.beTrue()
try expect(alive).to.beFalse()
try expect(alive).to.beNil()

Error handling

try expect(try write()).toThrow()
try expect(try write()).toThrow(FileError.NoPermission)

Comparable

try expect(5) > 2
try expect(5) >= 2
try expect(5) < 10
try expect(5) <= 10

Types

try expect("kyle").to.beOfType(String.self)

Causing a failure

throw failure("Everything is broken.")

Custom assertions

You can easily provide your own assertions, you just need to throw a failure when the assertion does not meet expectaions.

Examples

The following projects use Spectre:

Installation / Running

Swift Package Manager

Check out Commander as an example.

Playground

You can use Spectre in an Xcode Playground, open Spectre.playground in this repository, failures are printed in the console.

Spectre in an Xcode Playground

spectre's People

Contributors

christopherweems avatar elliottwilliams avatar hemet avatar iresslercmm avatar kattrali avatar keith avatar kerrmarin-lvmh avatar kylef avatar nrebhun avatar rbukovansky avatar readmecritic avatar stephencelis avatar stupergenius avatar tanner0101 avatar xavi-matos avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

spectre's Issues

Support for Xcode 12 beta

Can't install xcodegen I have a issue with Spectre

==> make install PREFIX=/usr/local/Cellar/xcodegen/2.16.0
Last 15 lines from /Users/amine/Library/Logs/Homebrew/xcodegen/01.make:
[13/18] Compiling PathKit PathKit.swift
[14/19] Compiling Spectre Case.swift
/private/tmp/xcodegen-20200717-5913-n8cz13/XcodeGen-2.16.0/.build/checkouts/Spectre/Sources/Spectre/XCTest.swift:35:14: error: 'recordFailure(withDescription:inFile:atLine:expected:)' is only available in macOS 10.13 or newer
    testCase.recordFailure(withDescription: "\(name): \(failure.reason)", inFile: failure.file, atLine: failure.line, expected: false)
             ^
/private/tmp/xcodegen-20200717-5913-n8cz13/XcodeGen-2.16.0/.build/checkouts/Spectre/Sources/Spectre/XCTest.swift:35:14: note: add 'if #available' version check
    testCase.recordFailure(withDescription: "\(name): \(failure.reason)", inFile: failure.file, atLine: failure.line, expected: false)
             ^
/private/tmp/xcodegen-20200717-5913-n8cz13/XcodeGen-2.16.0/.build/checkouts/Spectre/Sources/Spectre/XCTest.swift:34:8: note: add @available attribute to enclosing instance method
  func addFailure(_ name: String, failure: FailureType) {
       ^
/private/tmp/xcodegen-20200717-5913-n8cz13/XcodeGen-2.16.0/.build/checkouts/Spectre/Sources/Spectre/XCTest.swift:19:7: note: add @available attribute to enclosing class
class XcodeReporter: ContextReporter {
      ^
make: *** [build] Error 1

Do not report this issue to Homebrew/brew or Homebrew/core!


Error: You are using macOS 11.0.

Ability to start tests from Xcode

All of Spectre tests added to global contexts start in atexit. XCode always says that they are passed. As really Spectre tests has not started yet.

If we start them manually with run. XCode also fails, as inside run exit is called.

Is there any plan to add ability testing with XCode?

Spectres should time how long each test case takes and provide user with total time.

Similiar to mocha and other testing frameworks which allow you to see how long a test case takes. There should also be options to cause test failure when any test goes over some threshold. Mocha default reporter colours the time yellow/red to show slower tests.

Unfortunately this likely means we have to change the design of the reporters themselves.

Testing async methods

Hi, @kylef

I want to test some async methods. Is it now supported in Spectre?

I just had a brief look at Spectre but didn't find this feature. Maybe something like this in other BDD testing framework:

$0.it("should do something asynchronously") {
    waitUntil { done in
        //.. async work
        done()
    }
}

If this is not yet in Spectre, I'd like to try to implement (although I have no experience on creating a test framework). Before I could get into it, I think it's better to confirm it. What do you think about it?

Support type comparison

First of all, thank you for working on this, very neat tool.

I just tried to compare the object type with my expectation. I got it to work with

https://github.com/ryuichis/swift-ast/blob/66bb167818d4ecc5b009f4f19085826e861d37f5/Tests/declaration/ParsingTypeAliasDeclarationSpec.swift#L119

However, if I change the line to

try expect(Mirror(reflecting: node.type).subjectType) == testType

then I got the following error:

Tests/declaration/ParsingTypeAliasDeclarationSpec.swift:119:71: error: binary operator '==' cannot be applied to operands of type 'Expectation<Any.Type>' (aka 'Expectation<protocol<>.Type>') and 'Type.Type'
                try expect(Mirror(reflecting: node.type).subjectType) == testType
                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^  ~~~~~~~~
Tests/declaration/ParsingTypeAliasDeclarationSpec.swift:119:71: note: overloads for '==' exist with these partially matching parameter lists: (FloatingPointClassification, FloatingPointClassification), (_MirrorDisposition, _MirrorDisposition), (Mirror.DisplayStyle, Mirror.DisplayStyle), (Bool, Bool), (Any.Type?, Any.Type?), (COpaquePointer, COpaquePointer), (Character, Character), (UInt8, UInt8), (Int8, Int8), (UInt16, UInt16), (Int16, Int16), (UInt32, UInt32), (Int32, Int32), (UInt64, UInt64), (Int64, Int64), (UInt, UInt), (Int, Int), (Float, Float), (Double, Double), (Float80, Float80), (ObjectIdentifier, ObjectIdentifier), (String, String), (Index, Index), (String.UnicodeScalarView.Index, String.UnicodeScalarView.Index), (String.UTF16View.Index, String.UTF16View.Index), (String.UTF8View.Index, String.UTF8View.Index), (UnicodeScalar, UnicodeScalar), (_SwiftNSOperatingSystemVersion, _SwiftNSOperatingSystemVersion), (Bit, Bit), (AnyForwardIndex, AnyForwardIndex), (AnyBidirectionalIndex, AnyBidirectionalIndex), (AnyRandomAccessIndex, AnyRandomAccessIndex), (AccessLevel, AccessLevel), (ContextualKeywordType, ContextualKeywordType), (KeywordType, KeywordType), (PunctuatorType, PunctuatorType), (Token, Token), (ContiguousArray<Element>, ContiguousArray<Element>), (ArraySlice<Element>, ArraySlice<Element>), (Array<Element>, Array<Element>), (AutoreleasingUnsafeMutablePointer<Memory>, AutoreleasingUnsafeMutablePointer<Memory>), (T, T), (LazyFilterIndex<Base>, LazyFilterIndex<Base>), (FlattenCollectionIndex<BaseElements>, FlattenCollectionIndex<BaseElements>), (FlattenBidirectionalCollectionIndex<BaseElements>, FlattenBidirectionalCollectionIndex<BaseElements>), (Set<Element>, Set<Element>), ([Key : Value], [Key : Value]), (SetIndex<Element>, SetIndex<Element>), (DictionaryIndex<Key, Value>, DictionaryIndex<Key, Value>), (_HeapBuffer<Value, Element>, _HeapBuffer<Value, Element>), (HalfOpenInterval<Bound>, HalfOpenInterval<Bound>), (ClosedInterval<Bound>, ClosedInterval<Bound>), (ManagedBufferPointer<Value, Element>, ManagedBufferPointer<Value, Element>), (T?, T?), (T?, _OptionalNilComparisonType), (_OptionalNilComparisonType, T?), (Range<Element>, Range<Element>), (ReverseIndex<Base>, ReverseIndex<Base>), (UnsafeMutablePointer<Memory>, UnsafeMutablePointer<Memory>), (UnsafePointer<Memory>, UnsafePointer<Memory>), ((A, B), (A, B)), ((A, B, C), (A, B, C)), ((A, B, C, D), (A, B, C, D)), ((A, B, C, D, E), (A, B, C, D, E)), ((A, B, C, D, E, F), (A, B, C, D, E, F)), (Self, Self), (E, E.ValueType)
                try expect(Mirror(reflecting: node.type).subjectType) == testType
                                                                      ^
make: *** [.build/debug/test_runner] Error 1

Tests could be even more readable if we could write something like try expect(anObject).to.beTypeOf(AClass) and try expect(anObject).to.beProtocolOf(AProtocol).

Travis CI

Hi, @kylef, are you planning to setup Travis CI check and build for Spectre? Best would be for both platforms (Mac and Linux/Ubuntu). Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.