diff --git a/include/fluentexpr.ch b/include/fluentexpr.ch new file mode 100644 index 0000000..4b699e6 --- /dev/null +++ b/include/fluentexpr.ch @@ -0,0 +1,36 @@ +#xcommand Throw With ; + => ; + __MSG__ := Format( , ) ;; + aAdd( aTestReport, { .F., __MSG__ } ) ;; + UserException( __MSG__ ) ;; + Return Self + +#xcommand Passed With ; + => ; + __MSG__ := Format( , ) ;; + aAdd( aTestReport, { .T., __MSG__ } ) ;; + Return Self + +#xcommand Expect to [] be ; + =>; + ::Expect():[():]ToBe() + +#xcommand Expect to [] be a file ; + =>; + ::Expect():[():]ToBeAFile() + +#xcommand Expect to [] be a file with contents ; + =>; + ::Expect():[():]ToBeAFileWithContents() + +#xcommand Expect to [] be a folder; + =>; + ::Expect():[():]ToBeAFolder() + +#xcommand Expect to [] have type ; + =>; + ::Expect():[():]ToHaveType() + +#xcommand Expect to [] throw error; + =>; + ::Expect():[():]ToThrowError() \ No newline at end of file diff --git a/include/testsuite.ch b/include/testsuite.ch index 5ac373b..b7f9810 100644 --- a/include/testsuite.ch +++ b/include/testsuite.ch @@ -1,6 +1,13 @@ #ifndef _TESTSUITE_CH #define _TESTSUITE_CH +#include 'fluentexpr.ch' + +#xcommand Test Suite [VERBOSE] => TestSuite SUITEID Description VERBOSE +#xcommand End Test Suite => EndTestSuite ; CompileTestSuite SUITEID +#xcommand Define Feature => Feature Description ; Feature TestSuite SUITEID +#xcommand Define Before => Enable Before ; Before TestSuite SUITEID + #xcommand TestSuite ; [ ] ; [ ] ; @@ -25,7 +32,7 @@ #xcommand Enable Before ; => ; - _ObjClassMethod( Before, , ) + _ObjClassMethod( Before, , ) #xcommand Before TestSuite ; => ; diff --git a/src/fluentexpr.prw b/src/fluentexpr.prw index 7e35c17..481ca2e 100644 --- a/src/fluentexpr.prw +++ b/src/fluentexpr.prw @@ -1,19 +1,6 @@ #include 'protheus.ch' #include 'testsuite.ch' -#xcommand Throw With ; - => ; - __MSG__ := Format( , ) ;; - aAdd( aTestReport, { .F., __MSG__ } ) ;; - UserException( __MSG__ ) ;; - Return Self - -#xcommand Passed With ; - => ; - __MSG__ := Format( , ) ;; - aAdd( aTestReport, { .T., __MSG__ } ) ;; - Return Self - Static Function Format( cString, aValues ) Local cResult := cString Local nIndex @@ -33,7 +20,7 @@ Static Function ToString( xValue ) EndIf Return cValToChar( xValue ) -Class FluentExpr +Class FluentExpr From LongNameClass Data xValue Data lNot Method New( xValue ) Constructor diff --git a/tests/expect.prw b/tests/expect.prw index 0e8eed7..0d3399a 100644 --- a/tests/expect.prw +++ b/tests/expect.prw @@ -1,42 +1,40 @@ #include 'protheus.ch' #include 'testsuite.ch' -TestSuite Expect Description 'The test suite to test the test suite itself!' Verbose - Enable Environment 'T3' 'S SC 01' - Enable Before - Feature Files Description 'Tests with files should be working' - Feature Folders Description 'Tests with folders should be :top:' -EndTestSuite - -Before TestSuite Expect - If File( '\love.txt' ) - FErase( '\love.txt' ) - EndIf - If ExistDir( '\problems' ) - DirRemove( '\problems' ) - EndIf - Return - -Feature Files TestSuite Expect - Local nHandle - - nHandle := FCreate( '\love.txt' ) - FWrite( nHandle, 'I love you <3' ) - FClose( nHandle ) - - ::Expect( nHandle ):Not():ToHaveType( 'C' ) - ::Expect( nHandle ):ToHaveType( 'N' ) - ::Expect( nHandle ):Not():ToBe( 0 ) - ::Expect( '\hate.txt' ):Not():ToBeAfile() - ::Expect( '\love.txt' ):ToBeAFile() - ::Expect( '\love.txt' ):Not():ToBeAFileWithContents( 'I hate you :@' ) - ::Expect( '\love.txt' ):ToBeAFileWithContents( 'I love you <3+' ) - Return - -Feature Folders TestSuite Expect - MakeDir( '\problems' ) - ::Expect( '\problems' ):ToBeAFolder() - ::Expect( '\happiness' ):Not():ToBeAFolder() - Return - -CompileTestSuite Expect \ No newline at end of file +#define SUITEID Expect + +Test Suite 'The test suite to test the test suite itself!' Verbose + Define Before + If File( '\love.txt' ) + FErase( '\love.txt' ) + EndIf + If ExistDir( '\problems' ) + DirRemove( '\problems' ) + EndIf + Return + + Define Feature Files 'Tests with files should be working' + Local nHandle + + nHandle := FCreate( '\love.txt' ) + FWrite( nHandle, 'I love you <3' ) + FClose( nHandle ) + + Expect nHandle to not have type 'C' + Expect nHandle to have type 'N' + Expect nHandle to not be 0 + Expect '\hate.txt' to not be a file + Expect '\love.txt' to be a file + Expect '\love.txt' to not be a file with contents 'I hate you :@' + Expect '\love.txt' to be a file with contents 'I love you <3+' + Return + + Define Feature Folders 'Tests with folders should be :top:' + MakeDir( '\problems' ) + Expect '\problems' to be a folder + Expect '\happiness' to not be a folder + Return + +End Test Suite + +#undef SUITEID \ No newline at end of file