SlideShare ist ein Scribd-Unternehmen logo
1 von 52
Test-Driven
Language Development
Lennart Kats   Delft University of Technology
Rob Vermaas    LogicBlox
Eelco Visser   Delft University of Technology
Language Workbenches
Testing




“DOES THE TYPE CHECKER CATCH THIS?”
Testing




“DOES THIS HYPERLINK POINT TO THE RIGHT PLACE?”
Syntax




Semantics            IDE
parsing
                                 abstract syntax
                                 syntax error marking
                        Syntax




            Semantics               IDE

type checking                          errors/warnings
compilation                            reference resolving
interpretation                         content completion
execution                              refactoring
                                       views
How to test
language services?
IMPLEMENT
FEATURE, TRY WITH                   DOESN’T WORK
    EXAMPLE




                                       DISCARD
                    CLOSE ENOUGH.      EXAMPLE
How can we
systematically test
language definitions?
General-Purpose
 Testing Tools?
A Test Input
module Example

function foo() {
  bar();
}

function bar() {

}
Another Test Input
module Example

function foo() {
  foo();
}

function bar() {

}
A Negative Test Case
module Example

function foo() {
  notfoo();
}

function bar() {

}
Automated Testing
     Infrastructure
                  Parser

Test    Test     Compiler
input   script

                   IDE
Automated Testing
            Infrastructure
                                Parser

      Test            Test     Compiler
      input           script

                                 IDE
+ simple
– language-specific script
– limited expressiveness
– boilerplate in tests
– ...
Can we design a
    general, reusable
solution for language testing?
Yes We Can

Generic test specification language
                +
         Parametrization
Language-Parametric
Testing Language (LPTL)
module my-tests

language mobl

test Cannot assign an integer to a string [[
 module Example
  module Example

  <test input>
   function test() {
   var s s : String = 1;
     var : String = 1;
  }}
]] 1 error
LPTL Opportunities


     Expressiveness


     Tool support
LPTL Opportunities (1)


Module system
      +
GUI Test Runner
LPTL Opportunities (2)


 IDE support
   for test
specifications
LPTL Opportunities (3)


Immediate
   test
evaluation
LPTL Opportunities (4)


IDE support
  for test
   inputs
LPTL Opportunities (5)
              setup [[
               module Example

               imports stuff

 Reduced        function test() {
                  [[...]]
boilerplate     }
              ]]

              test Cannot assign ... [[
                var s : String = 1;
              ]] 1 error
LPTL Opportunities (6)
                  1 error

                  2 warnings

                  /expected here/

                  parse fails
  Wide set of
test conditions   complete ... to ...

                  resolve ... to ...

                  refactor ... to ...

                  build ...

                  run ...
Testing Syntax (1)

 test Proper declaration [[
   var s : String = "a";
 ]] parse

 test Java-like declaration [[
   String s = "a";
 ]] parse fails
Testing Syntax (2)

 test Proper declaration [[
   var s : String = "a";
 ]] parse to VarDecl("s", _)

 test Precedence [[
   3+1*2
 ]] parse to [[
   3 + (1 * 2)
 ]]
Testing Error Markers


   test Variable declaration [[
     var s : String = "a";
   ]] 0 errors

   test Bad variable declaration [[
     var s : String = 25;
   ]] 1 error /wrong type/
Testing References
test [[
 module Example

 function foo() {
   bar();
 }

 function bar() {

  }
]] resolve ... to ...
Testing References
test [[
 module Example

 function foo() {
   bar();
   [[bar]]();
 }

 function [[bar]]() {
          bar() {

  }
]] resolve ... to ...
           #1 to #2
Testing Code
Generation..?
Testing Code
      Generation..?
test [[
  function foo() {
    return 3;
  }
]] build generate-javascript to [[
  [[bar]]();

 function bar() {

  }
]]
Testing Code
     Generation..?
test [[
   function foo() {
     return 3;
   }
                    to [[
]] build generate-javascript to [[
  var foo = function() {
   [[bar]]();
     return 3;
  };
   function bar() {
]]
   }
]]
Testing Execution
setup [[
 application execution

  function main() : Num {
    // init
    [[...]]
  }
]]

test Arithmetic [[
  return 1 + 1;
]] run run-test to 2
Implementation


 Spoofax Testing Language

      (spoofax.org)
Implementation
       Techniques

Language embedding

Dynamic instantiation of language services
Language Embedding:
      Syntax
  module tests
  language mobl

  test Java-like declaration [[
    String s = "a";
  ]] parse fails
Language Embedding:
      Syntax
 1 module tests
    language mobl

    test Java-like declaration [[
      String s = "a";
    ]] parse fails
Language Embedding:
      Syntax
 1 module tests
 2 language mobl

    test Java-like declaration [[
      String s = "a";
    ]] parse fails
Language Embedding:
      Syntax
 1 module tests
 2 language mobl

   test Java-like declaration [[
 3 ]]String sfails
      parse
              = "a";
Language Embedding:
 Semantics & IDE (1)

  test A function call [[
   function foo() {

   }
    fo|
  ]]

          Content complete
Language Embedding:
 Semantics & IDE (1)

  test A function call [[
   function foo() {
                             Mobl
   }
    fo|
  ]]

          Content complete
Language Embedding:
 Semantics & IDE (2)

  test A function call [[
   function foo() {
                            Mobl
   }
    notfoo();
  ]]


       No condition;
       error not expected
Dynamic Language Service
     Instantiation


                      Mobl
Dynamic Language Service
     Instantiation


   Language consists of separate services

     Services have functional interfaces
Reflection

+ simple
+ no scripting required
+ IDE helps avoid errors
+ little boilerplate code
+ expressiveness
WRITE 1 TEST
                    IMPLEMENT FEATURE




       TESTS FAIL




                       TESTS SUCCEED!
ADDITIONAL
  SLIDES
Self-Application

language Spoofax-Testing

test Testing testing [[[

  language mobl
  test Testing [[
    module y
  ]]

]]]
Dynamic Language Service
     Instantiation
                           Test
  “mobl”                   input


  Language      Mobl
                           Parser
   registry   language


                         Completion
                           service
Related:
Automatic Test Generation

• Generate tests from grammar
• Requires oracle
• Complementary to our approach
The Spoofax Language
      Workbench [OOPSLA 2010]
• Integrated environment for language
  definition
• Define syntax, semantics, IDE
• Based on Eclipse
  www.spoofax.org

Weitere ähnliche Inhalte

Was ist angesagt?

Programming Language
Programming  LanguageProgramming  Language
Programming LanguageAdeel Hamid
 
Imperative programming
Imperative programmingImperative programming
Imperative programmingEdward Blurock
 
CS4200 2019 Lecture 1: Introduction
CS4200 2019 Lecture 1: IntroductionCS4200 2019 Lecture 1: Introduction
CS4200 2019 Lecture 1: IntroductionEelco Visser
 
A First Look at Google's Go Programming Language
A First Look at Google's Go Programming LanguageA First Look at Google's Go Programming Language
A First Look at Google's Go Programming LanguageGanesh Samarthyam
 
Log cat kotlindsl
Log cat kotlindslLog cat kotlindsl
Log cat kotlindslsanaebadi1
 
Programming paradigm
Programming paradigmProgramming paradigm
Programming paradigmbusyking03
 
Microservices for building an IDE – The innards of JetBrains Rider - TechDays...
Microservices for building an IDE – The innards of JetBrains Rider - TechDays...Microservices for building an IDE – The innards of JetBrains Rider - TechDays...
Microservices for building an IDE – The innards of JetBrains Rider - TechDays...Maarten Balliauw
 
difference between c c++ c#
difference between c c++ c#difference between c c++ c#
difference between c c++ c#Sireesh K
 
Break Free with Managed Functional Programming: An Introduction to F#
Break Free with Managed Functional Programming: An Introduction to F#Break Free with Managed Functional Programming: An Introduction to F#
Break Free with Managed Functional Programming: An Introduction to F#IndyMobileNetDev
 
Break Free with Managed Functional Programming: An Introduction to F#
Break Free with Managed Functional Programming: An Introduction to F#Break Free with Managed Functional Programming: An Introduction to F#
Break Free with Managed Functional Programming: An Introduction to F#Dave Fancher
 

Was ist angesagt? (20)

Programming Language
Programming  LanguageProgramming  Language
Programming Language
 
Imperative programming
Imperative programmingImperative programming
Imperative programming
 
C-Sharp 6.0 ver2
C-Sharp 6.0 ver2C-Sharp 6.0 ver2
C-Sharp 6.0 ver2
 
CS4200 2019 Lecture 1: Introduction
CS4200 2019 Lecture 1: IntroductionCS4200 2019 Lecture 1: Introduction
CS4200 2019 Lecture 1: Introduction
 
Intro dotnet
Intro dotnetIntro dotnet
Intro dotnet
 
Go programing language
Go programing languageGo programing language
Go programing language
 
C++vs java
C++vs javaC++vs java
C++vs java
 
A First Look at Google's Go Programming Language
A First Look at Google's Go Programming LanguageA First Look at Google's Go Programming Language
A First Look at Google's Go Programming Language
 
Log cat kotlindsl
Log cat kotlindslLog cat kotlindsl
Log cat kotlindsl
 
C# language
C# languageC# language
C# language
 
Create Your Own Language
Create Your Own LanguageCreate Your Own Language
Create Your Own Language
 
LIL Presentation
LIL PresentationLIL Presentation
LIL Presentation
 
Xtext Webinar
Xtext WebinarXtext Webinar
Xtext Webinar
 
Programming paradigm
Programming paradigmProgramming paradigm
Programming paradigm
 
Microservices for building an IDE – The innards of JetBrains Rider - TechDays...
Microservices for building an IDE – The innards of JetBrains Rider - TechDays...Microservices for building an IDE – The innards of JetBrains Rider - TechDays...
Microservices for building an IDE – The innards of JetBrains Rider - TechDays...
 
Difference between c, c++ and java
Difference between c, c++ and javaDifference between c, c++ and java
Difference between c, c++ and java
 
difference between c c++ c#
difference between c c++ c#difference between c c++ c#
difference between c c++ c#
 
Break Free with Managed Functional Programming: An Introduction to F#
Break Free with Managed Functional Programming: An Introduction to F#Break Free with Managed Functional Programming: An Introduction to F#
Break Free with Managed Functional Programming: An Introduction to F#
 
Break Free with Managed Functional Programming: An Introduction to F#
Break Free with Managed Functional Programming: An Introduction to F#Break Free with Managed Functional Programming: An Introduction to F#
Break Free with Managed Functional Programming: An Introduction to F#
 
Python for Swift
Python for SwiftPython for Swift
Python for Swift
 

Ähnlich wie Test-Driven Language Development: A Generic Approach

Code Review In Testing View
Code Review In Testing ViewCode Review In Testing View
Code Review In Testing ViewSQABD
 
What's coming to c# (Tel-Aviv, 2018)
What's coming to c# (Tel-Aviv, 2018)What's coming to c# (Tel-Aviv, 2018)
What's coming to c# (Tel-Aviv, 2018)Moaid Hathot
 
Kotlin: Challenges in JVM language design
Kotlin: Challenges in JVM language designKotlin: Challenges in JVM language design
Kotlin: Challenges in JVM language designAndrey Breslav
 
Testes? Mas isso não aumenta o tempo de projecto? Não quero...
Testes? Mas isso não aumenta o tempo de projecto? Não quero...Testes? Mas isso não aumenta o tempo de projecto? Não quero...
Testes? Mas isso não aumenta o tempo de projecto? Não quero...Comunidade NetPonto
 
Pragmatic Parallels: Java and JavaScript
Pragmatic Parallels: Java and JavaScriptPragmatic Parallels: Java and JavaScript
Pragmatic Parallels: Java and JavaScriptdavejohnson
 
Introduction to Kotlin for Android developers
Introduction to Kotlin for Android developersIntroduction to Kotlin for Android developers
Introduction to Kotlin for Android developersMohamed Wael
 
Groovy Update - JavaPolis 2007
Groovy Update - JavaPolis 2007Groovy Update - JavaPolis 2007
Groovy Update - JavaPolis 2007Guillaume Laforge
 
Become Jythonic in FDMEE (KSCOPE15)
Become Jythonic in FDMEE (KSCOPE15)Become Jythonic in FDMEE (KSCOPE15)
Become Jythonic in FDMEE (KSCOPE15)Francisco Amores
 
Reusando componentes Zope fuera de Zope
Reusando componentes Zope fuera de ZopeReusando componentes Zope fuera de Zope
Reusando componentes Zope fuera de Zopementtes
 
Language processor implementation using python
Language processor implementation using pythonLanguage processor implementation using python
Language processor implementation using pythonViktor Pyskunov
 
PIL - A Platform Independent Language
PIL - A Platform Independent LanguagePIL - A Platform Independent Language
PIL - A Platform Independent Languagezefhemel
 
Iron Languages - NYC CodeCamp 2/19/2011
Iron Languages - NYC CodeCamp 2/19/2011Iron Languages - NYC CodeCamp 2/19/2011
Iron Languages - NYC CodeCamp 2/19/2011Jimmy Schementi
 
Mohammed Kharma-A flexible framework for quality assurance and testing of sof...
Mohammed Kharma-A flexible framework for quality assurance and testing of sof...Mohammed Kharma-A flexible framework for quality assurance and testing of sof...
Mohammed Kharma-A flexible framework for quality assurance and testing of sof...Mohammed Kharma
 
Functional Testing Swing Applications with Frankenstein
Functional Testing Swing Applications with FrankensteinFunctional Testing Swing Applications with Frankenstein
Functional Testing Swing Applications with Frankensteinvivek_prahlad
 
"Formal Verification in Java" by Shura Iline, Vladimir Ivanov @ JEEConf 2013,...
"Formal Verification in Java" by Shura Iline, Vladimir Ivanov @ JEEConf 2013,..."Formal Verification in Java" by Shura Iline, Vladimir Ivanov @ JEEConf 2013,...
"Formal Verification in Java" by Shura Iline, Vladimir Ivanov @ JEEConf 2013,...Vladimir Ivanov
 
Concepts of JetBrains MPS
Concepts of JetBrains MPSConcepts of JetBrains MPS
Concepts of JetBrains MPSVaclav Pech
 

Ähnlich wie Test-Driven Language Development: A Generic Approach (20)

Code Review In Testing View
Code Review In Testing ViewCode Review In Testing View
Code Review In Testing View
 
Os Welton
Os WeltonOs Welton
Os Welton
 
What's coming to c# (Tel-Aviv, 2018)
What's coming to c# (Tel-Aviv, 2018)What's coming to c# (Tel-Aviv, 2018)
What's coming to c# (Tel-Aviv, 2018)
 
PL/SQL unit testing with Ruby
PL/SQL unit testing with RubyPL/SQL unit testing with Ruby
PL/SQL unit testing with Ruby
 
Kotlin: Challenges in JVM language design
Kotlin: Challenges in JVM language designKotlin: Challenges in JVM language design
Kotlin: Challenges in JVM language design
 
Testes? Mas isso não aumenta o tempo de projecto? Não quero...
Testes? Mas isso não aumenta o tempo de projecto? Não quero...Testes? Mas isso não aumenta o tempo de projecto? Não quero...
Testes? Mas isso não aumenta o tempo de projecto? Não quero...
 
Pragmatic Parallels: Java and JavaScript
Pragmatic Parallels: Java and JavaScriptPragmatic Parallels: Java and JavaScript
Pragmatic Parallels: Java and JavaScript
 
Introduction to Kotlin for Android developers
Introduction to Kotlin for Android developersIntroduction to Kotlin for Android developers
Introduction to Kotlin for Android developers
 
Groovy Update - JavaPolis 2007
Groovy Update - JavaPolis 2007Groovy Update - JavaPolis 2007
Groovy Update - JavaPolis 2007
 
F# 101
F# 101F# 101
F# 101
 
Become Jythonic in FDMEE (KSCOPE15)
Become Jythonic in FDMEE (KSCOPE15)Become Jythonic in FDMEE (KSCOPE15)
Become Jythonic in FDMEE (KSCOPE15)
 
Reusando componentes Zope fuera de Zope
Reusando componentes Zope fuera de ZopeReusando componentes Zope fuera de Zope
Reusando componentes Zope fuera de Zope
 
Language processor implementation using python
Language processor implementation using pythonLanguage processor implementation using python
Language processor implementation using python
 
PIL - A Platform Independent Language
PIL - A Platform Independent LanguagePIL - A Platform Independent Language
PIL - A Platform Independent Language
 
Iron Languages - NYC CodeCamp 2/19/2011
Iron Languages - NYC CodeCamp 2/19/2011Iron Languages - NYC CodeCamp 2/19/2011
Iron Languages - NYC CodeCamp 2/19/2011
 
Mohammed Kharma-A flexible framework for quality assurance and testing of sof...
Mohammed Kharma-A flexible framework for quality assurance and testing of sof...Mohammed Kharma-A flexible framework for quality assurance and testing of sof...
Mohammed Kharma-A flexible framework for quality assurance and testing of sof...
 
Functional Testing Swing Applications with Frankenstein
Functional Testing Swing Applications with FrankensteinFunctional Testing Swing Applications with Frankenstein
Functional Testing Swing Applications with Frankenstein
 
"Formal Verification in Java" by Shura Iline, Vladimir Ivanov @ JEEConf 2013,...
"Formal Verification in Java" by Shura Iline, Vladimir Ivanov @ JEEConf 2013,..."Formal Verification in Java" by Shura Iline, Vladimir Ivanov @ JEEConf 2013,...
"Formal Verification in Java" by Shura Iline, Vladimir Ivanov @ JEEConf 2013,...
 
Concepts of JetBrains MPS
Concepts of JetBrains MPSConcepts of JetBrains MPS
Concepts of JetBrains MPS
 
Java introduction
Java introductionJava introduction
Java introduction
 

Test-Driven Language Development: A Generic Approach

Hinweis der Redaktion

  1. \n
  2. Language workbenches combine interactive definition and use of DSLs\n
  3. Scenario: scoping rules!\n
  4. Scenario: scoping rules!\n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. not recording intentions, not avoiding regressions\n
  11. \n
  12. \n
  13. \n
  14. Other variations: nested functions, closures, methods, inheritance\n
  15. Other variations: nested functions, closures, methods, inheritance\n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n
  38. \n
  39. Module system\n GUI Test Runner\n Avoids boilerplate\n Testing conditions for syntax, semantics, IDE\n
  40. \n
  41. \n
  42. Generic language and infrastructure\nspecialized with embedding\n
  43. Generic language and infrastructure\nspecialized with embedding\n- module system\n- parametrization\n- general format for specifying tests\n- and conditions\n
  44. \n
  45. \n
  46. \n
  47. \n
  48. \n
  49. \n
  50. \n
  51. \n
  52. Test will use parser and compare to expectation\n
  53. Test will use parser and compare to expectation\n
  54. Test will use parser and compare to expectation\n
  55. Test will simulate reference resolve and compare to expectation\n
  56. Test will simulate reference resolve and compare to expectation\n
  57. Test will simulate reference resolve and compare to expectation\n
  58. Test will simulate reference resolve and compare to expectation\n
  59. Test will simulate reference resolve and compare to expectation\n
  60. \n
  61. \n
  62. Next:\n\n
  63. Next:\n\n
  64. \n
  65. 1. Parse testing language\n 2. Determine tested language\n 3. Parse tested language\n(might be syntax incorrect!)\n
  66. 1. Parse testing language\n 2. Determine tested language\n 3. Parse tested language\n(might be syntax incorrect!)\n
  67. 1. Parse testing language\n 2. Determine tested language\n 3. Parse tested language\n(might be syntax incorrect!)\n
  68. 1. Parse testing language\n 2. Determine tested language\n 3. Parse tested language\n(might be syntax incorrect!)\n
  69. 1. Parse testing language\n 2. Determine tested language\n 3. Parse tested language\n(might be syntax incorrect!)\n
  70. 1. Parse testing language\n 2. Determine tested language\n 3. Parse tested language\n(might be syntax incorrect!)\n
  71. \n
  72. \n
  73. \n
  74. \n
  75. \n
  76. \n
  77. \n
  78. \n
  79. expressiveness + tool support\n
  80. \n
  81. does not \n
  82. \n
  83. \n
  84. \n
  85. \n
  86. \n
  87. Oracle: baseline compiler, specification, execution\n\n
  88. \n