AutoHotkey Community

It is currently May 27th, 2012, 11:31 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 27 posts ]  Go to page Previous  1, 2
Author Message
 Post subject:
PostPosted: December 8th, 2010, 11:28 am 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
I guess its up to LowLevel.ahk. If you find appropriate one for AHK_H then it should work.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 19th, 2010, 5:53 pm 
Offline

Joined: November 7th, 2006, 9:47 pm
Posts: 1934
Location: Germany
I have modified the UTest_Edit() function to work with SciTE.
Code:
/*
 Function: UTest_Edit
            Open editor with given file and go to line number.
            Required to be implemented by the user in order for double click in GUI to work.
            (modified 2010-12-19 by Tuncay)
 */
UTest_Edit( Path, LineNumber )
{
    ;?BEGIN-OUT-COMMENTED
    ;~ Run, "d:\Utils\Edit Plus\EditPlus.exe" "%Path%"
    ;~ WinWait, EditPlus   
    ;~ WinMenuSelectItem,,,Search, Go To, 1&
    ;~ Send %LineNumber%{Enter}
    ;?END-OUT-COMMENTED
   
    ;?START-NEW
    TitleMatchMode := A_TitleMatchMode
    SetTitleMatchMode 2
    Run, "C:\Program Files\AutoHotkey\SciTE_beta4\SciTE.exe" "%Path%"
    Sleep, 20
    WinWaitActive, SciTE4AutoHotkey
    SetTitleMatchMode %TitleMatchMode%
    Sleep, 20
    Send, ^g
    Sleep, 20
    Send, %LineNumber%{Enter}
    ;?END-NEW
}

For those who do not know: This function jumps to line, by clicking the tested function listed in the gui.

_________________
{1:"ahkstdlib", 2:"my libs", 3:"my apps", 4:"my license"}
--> Don't feed the troll! <--


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 27th, 2011, 7:14 am 
Offline

Joined: March 10th, 2011, 7:17 pm
Posts: 374
guest3456 wrote:
is it possible to add 'expected' and 'actual' columns to the listbox?


i made a few changes to UTest framework:
- Assert_Equal(param1, param2) - Assert() wraps this
- expected/actual results for Assert_Equal()
- full green/red bar on success/failure

i bumped version to v0.3a in the code

download:
http://www.autohotkey.net/~guest3456/myUTest.ahk

i use it in my test driven development example which shows UTest in action

:)


Report this post
Top
 Profile  
Reply with quote  
 Post subject: sweet!
PostPosted: May 30th, 2011, 12:38 am 
Offline

Joined: June 18th, 2006, 8:47 am
Posts: 346
Location: Phoenix, AZ
majkinetor,
Guest3456 turned me onto this very useful tool and I just want to say THANKS! This will make life so much easier when I get software updates at work and need to check that everything still works.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 2nd, 2011, 9:55 am 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
Thats great guest3456. When I find time I will post your changes into repo. Thx.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 5th, 2011, 8:19 am 
Offline

Joined: May 29th, 2011, 3:06 am
Posts: 85
Thanks for the library, it looks really useful!

However, when I tried using it with AHK_L 1.1.0.0, it threw an win32 exception on line 583 in the 2nd loop iteration (stepping through code)
Code:
__getFirstLine()
{
    static pFirstLine
    if (pFirstLine = "") {
        if pThisFunc := __getFuncUDF(A_ThisFunc) {
            if pFirstLine := NumGet(pThisFunc+4) ; mJumpToLine
            Loop {
                if !(pLine:=NumGet(pFirstLine+16)) ; mPrevLine
                    break
                pFirstLine := pLine
            }
        }
    }
    return pFirstLine
}
This low level stuff is a bit over my head and I don't understand what's wrong or how to fix it. I looked in the LowLevel thread, which said something about function structure changing in 1.1, but not what to change in the code to account for it, if this even has anything to do with the problem.

So, is there any change we could get a version which we can use with AHK_L 1.1.0.0?


Report this post
Top
 Profile  
Reply with quote  
PostPosted: August 27th, 2011, 9:36 am 
Offline

Joined: August 3rd, 2007, 8:01 am
Posts: 555
Location: Houston, TX
Iggy_ wrote:
Thanks for the library, it looks really useful!
However, when I tried using it with AHK_L 1.1.0.0, it threw an win32 exception...

Remove all the lowlevel code from utest.ahk
And replace the code for UTest_getFunctions() with
Code:
UTest_getFunctions() {
funcs := object()
fnames := ""
FileRead, script, %A_ScriptName%
pos := 1
while pos{
pos := regexmatch(script, "([\w_\d]+)\(", m, pos)
pos += strlen(m1)
f := func(m1)
name := f.name

if !f.name
  Continue

if !f.IsBuiltIn
  funcs[name] := f.name
}
for i, j in funcs
{
fnames .= j . "`n"
}
 ; msgbox % fnames
   return SubStr(fNames, 1, -1)
}

https://github.com/tinku99/utest


Last edited by tinku99 on October 16th, 2011, 3:38 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 1st, 2011, 5:31 pm 
Offline

Joined: May 29th, 2011, 3:06 am
Posts: 85
Thanks tinku99!

Actually, I gave up hope on using this some time ago and have since put together some similar functions & classes I've been using to test with, much like NUnit constraint model. I'll share it when it's 100% completed and tested a bit more. But thanks for the update :)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 2nd, 2011, 4:05 am 
Offline

Joined: March 10th, 2011, 7:17 pm
Posts: 374
i look forward to it Iggy


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 7th, 2011, 5:05 am 
Offline

Joined: March 10th, 2011, 7:17 pm
Posts: 374
Iggy_ wrote:

Actually, I gave up hope on using this some time ago and have since put together some similar functions & classes I've been using to test with, much like NUnit constraint model. I'll share it when it's 100% completed and tested a bit more.


in upcoming versions of AHK_L and v2, there will be try/catch/throw, which will give new possibilities for testing, if anyone cares to write new framework


Report this post
Top
 Profile  
Reply with quote  
 Post subject: using try catch
PostPosted: October 16th, 2011, 8:03 pm 
Offline

Joined: August 3rd, 2007, 8:01 am
Posts: 555
Location: Houston, TX
guest3456 wrote:
in upcoming versions of AHK_L and v2, there will be try/catch/throw, which will give new possibilities for testing, if anyone cares to write new framework
here you go: https://github.com/tinku99/utest


Report this post
Top
 Profile  
Reply with quote  
 Post subject: line numbers?
PostPosted: March 13th, 2012, 4:03 am 
Modified tinku99's version a bit -- there is some semblance of line number support and Notepad++ Portable support.

WARNING: In UTest.ahk, there are at least two instances of the value 0xA0 -- which doesn't show up very well in some editors here. Not sure they will survive pasting...They occur after instances of ~`a in the function definition for UTest.

UTest.ahk
Code:
/* Title: UTest
modified by Guest_AutoHotkey_L
changes: formatting
         preliminary line number support
         Notepad++ Portable support

modified by Naveen Garg
changes: removed dependency on lowlevel functions which were brittle.
         added stack trace information for failed tests

originally by majkinetor: http://www.autohotkey.com/forum/author-majkinetor.html
forum: http://www.autohotkey.com/forum/viewtopic.php?t=49262

    Unit testing framework.

    (see Utest.png)

 Usage:

   UTest will scan the script for functions which name starts with "Test_".
   Test functions have no parameter and use one of the Assert functions.
   If Assert function fails, test will fail and you will
   see that in the result output.txt with stack trace of failed tests.

   To test your script, use the following template :

  (start code)
   ahktest()
      Return
      #include UTest.ahk
   
      Test_MyTest1()
      {
        assert(1, expr2, expr3)
      }

      Test_MyTest2(expr1, expr2)
      {
      }
      ...
      ...
      #include FunctionsToTest.ahk
  (end code)

 
*/
ahktest()
{
  #SingleInstance, force
  ; XXX: used elsewhere too
  OutFile := "output.txt"
  UTest("Result", UTest_Start(UTest("NoGui"))) ;execute tests
  Run, % OutFile
  FileRead, Output, % OutFile
  Return Output
}

Assert(b1 = "", b2 = 1, b3 = 1, b4 = 1, b5 = 1, b6 = 1, b7 = 1, b8 = 1
     , b9 = 1, b10 = 1)
{
  e := {}
  Loop, 10
  {
    If (A_Index == 1)
    {
      Continue
    }
    If !b%A_Index%
    {
      e.insert("Test " . A_Index . " failed`n")
    }
  }
  If e[1]
  {
    stack := getStackTrace()
    stack := RemoveUTestFunctionsFromStackTrace(stack)
    te := exception("fail", -1)
    s := ToString(e)
       . "at " . getLineSource(te.line, te.file)
       . "`nin file " . te.file
       . "`nstacktrace: "
    stack[0] := s
    UTest_SetFail(Name, ",")
    Throw stack
  }
}

UTest_Edit(Path, LineNumber)
{
  OutputDebug, % "UTest_Edit entered"
  ; XXX
  Command := "x:\apps\Notepad++Portable\Notepad++Portable.exe "
           . "-multiInst "
  If (LineNumber != "")
  {
    Command .= "-n" . LineNumber . " "
  }
  Command .= """" . Path . """"
  OutputDebug, % Command
  ;
  Run, % Command
  /*
  If (LineNumber != "")
  {
    Mode := A_TitleMatchMode
    SetTitleMatchMode, RegEx
    WinWaitActive, % "^.* - Notepad\+\+$"
    OutputDebug, % "Found an instance of Notepad++"
    SetTitleMatchMode, % Mode
    OutputDebug, "Restored title match mode to: " . A_TitleMatchMode
    Send ^g
    WinWaitActive, % "Go To..."
    Send %LineNumber%{Enter}
  }
  */
}

;================================== PRIVATE ================================

UTest_RunTests()
{
  OutputDebug, % "UTest_RunTests entered"
  ; XXX: used elsewhere too
  OutFile := "output.txt"
  FileDelete, % OutFile
  tests := UTest_GetTests()
  bNoGui := UTest("NoGui")
  If (tests == "")
  {
    MsgBox, % "No tests found!"
    ExitApp
  }
  bTestsFail := 0
  OutputDebug, % tests
  Loop, Parse, tests, `n
  {
    StringSplit, f, A_LoopField, % A_Space
    Try
    {
      %f1%()
    }
    Catch e
    {
      If !UTest("Name")
      {
        FileAppend % "test " . A_Index . ":`n"
                   . ToString(e) . "`n"
                   . "******************************************`n"
                   , % OutFile
      }
    }
    bFail := UTest("F")
    OutputDebug, % "bFail: " . bFail
    Param := UTest("Param")
    Name := UTest("Name")
    fName := SubStr(f1, 6)
    IfEqual, bFail, 1, SetEnv, bTestsFail, 1
    s .= (bFail ? "FAIL" : "OK")
       . "," . fName
       . "," . f2
       . "," . Name
       . "," . Param . "`n"
    OutputDebug, % "s: " . s
    UTest("F", 0)
    UTest("Param", "")
    UTest("Name", "")
    If !bNoGui
    {
      LV_Add(bFail ? "Select" : ""
           , bFail ? "FAIL" : "OK"
           , fName, f2, Name, Param)
    }
  }
  If !bNoGui
  {
    LV_ModifyCol()
    LV_ModifyCol(1, 100)
    LV_ModifyCol(3, 50)
    LV_ModifyCol(4, 150)
  }
  UTest("TestsFail", bTestsFail)
  Return SubStr(s, 1, -1)
}

UTest_GetTests()
{
  s := UTest_GetFunctions()
  Loop, Parse, s, `n
  {
    If (SubStr(A_LoopField, 1, 5) == "Test_")
    {
      t .= A_LoopField . "`n"
    }
  }
  Return SubStr(t, 1, -1)
}

UTest_GetFunctions()
{
  fnames := ""
  FObj := FileOpen(A_ScriptName, "r")
  ; XXX: check success?
  LineNo := 1
  While (!FObj.AtEOF)
  {
    Line := FObj.ReadLine()
    LineNo += 1
    FoundPos := RegExMatch(Line, "^([\w_\d]+)\(", m)
    ; XXX: check for problems?
    FoundPos += StrLen(m1)
    f := Func(m1)
    name := f.name
    If !f.name
    {
      Continue
    }
    If !f.IsBuiltIn
    {
      fnames .= f.name . " " . LineNo . "`n"
    }
  }
  Return SubStr(fNames, 1, -1)
}

UTest_GetFreeGuiNum()
{
  Loop, 99
  {
    Gui %A_Index%:+LastFoundExist
    IfWinNotExist
    {
      Return A_Index
    }
  }
  Return 0
}

UTest_Start(bNoGui = false)
{
  If !bNoGui
  {
    hGui := UTest_CreateGui()
  }
  s := UTest_RunTests()
  If (hGui)
  {
    Result := UTest("TestsFail") ? "FAIL" : "OK"
    ControlSetText, Static1, % Result, % "ahk_id " . hGui
  }
  Return s
}

UTest_CreateGui()
{
  w := 500
  h := 400
  n := UTest_GetFreeGuiNum()
  Gui, %n%: +LastFound +LabelUTest_
  hGui := WinExist()
  Gui, %n%: Add, ListView, w%w% h%h% gUTest_OnList, Result|Test|Line|Name|Param
  Gui, %n%: Font, s20 bold cRED, Courier New
  Gui, %n%: Add, Text, w%w% h40
  Gui, %n%: Show, autosize, UTest - %A_ScriptName%
  UTest("GUINO", n)
  Hotkey, IfWinActive, % "ahk_id " . hGui
  Hotkey, ESC, UTest_Close
  Hotkey, IfWinActive
  Return hGui

UTest_Close:
  ExitApp
  ; XXX: what is the following line?
  Return
}

UTest_SetFail(Name = "", Param = "")
{
  UTest("Param", UTest("Param") . " " . Param)
  UTest("Name", UTest("Name") . " " . Name)
  UTest("F", 1)
  Return 1
}

UTest_OnList:
{
  OutputDebug,  "UText_OnLine entered"
  IfNotEqual, A_GuiEvent, DoubleClick, return
  LV_GetText(lineNumber, LV_GetNext(), 3)
  UTest_Edit(A_ScriptFullPath, lineNumber)
  Return
}

; XXX: careful of instances of ~`a... below, some editors don't appear to
; display appropriately...the hex value following ~`a appears to be A0
UTest(var = "", value = "~`a "
    , ByRef o1 = "", ByRef o2 = "", ByRef o3 = ""
    , ByRef o4 = "", ByRef o5 = "", ByRef o6 = "")
{
  static
  _ := %var%
  IfNotEqual, value, ~`a , SetEnv, %var%, %value%
  Return _
  ; XXX: what is the following line?
return
}

#include util.ahk


util.ahk
Code:
getFile(name)
{
  static files := {}
  If files[name]
  {
    Return files[name]
  }
  file := {}
  Loop, Read, % name
  {
    file[A_Index] := A_LoopReadLine
  }
  files[name] := file
  Return file
}

getLinesNear(lineNumber, filename)
{
  If lineNumber is not number
  {
    Throw exception("lineNumber not provided")
  }
  file := getFile(filename)
  lines := ""
  loop, 5
  {
    lines .= file[lineNumber - 3 + A_Index] . "`n"
  }
  Return lines
}

getLineSource(lineNumber, filename)
{
  If lineNumber is not number
  {
    Throw exception("lineNumber not provided")
  }
  file := getFile(filename)
  line := file[lineNumber]
  Return line
}

getStackTrace(max = 10)
{
  If (max > 50)
  {
    max := 50
  }
  stack := Object()
  Loop
  {
    If (A_Index < 2)  ; don't need stack for these utility functions
    {
      Continue
    }
    If (A_Index > max)  ; in case we are in a long running coroutine
    {
      Break
    }
    s := exception("level " . A_Index, 0 - A_Index)
    If (s.what < 0)
    {
      Break
    }
    s.extra := getLinesNear(s.line, s.file)
    stack[A_Index] := s
  }
  Return stack
}

RemoveUTestFunctionsFromStackTrace(stack)
{
  max := stack.maxindex()
  Loop, % max
  {
    s := stack[A_Index]
    If instr(s.What, "runTests")
    {
      stack[A_Index] := 0
      stack[A_Index - 1] := 0
      level := A_Index
    }
    If (level < max)
    {
      Loop, % (max - level)
      {
        stack[level + A_Index] := 0
      }
    }
  }
  Return stack
}


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 27 posts ]  Go to page Previous  1, 2

All times are UTC [ DST ]


Who is online

Users browsing this forum: Google [Bot], MSN [Bot], nomissenrojb and 65 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group