// ĠCopyright Ġ 2 0 0 0 - 2 0 1 9 ĠJetBrains Ġs . r . o . ĠUse Ġof Ġthis Ġsource Ġcode Ġis Ġgoverned Ġby Ġthe ĠApache Ġ 2 . 0 Ġlicense Ġthat Ġcan Ġbe Ġfound Ġin Ġthe ĠLICENSE Ġfile . Ċ package Ġorg . jetbrains . plugins . gradle . execution . test . runner Ċ Ċ import Ġcom . intellij . openapi . external System . service . execution . External System Run Configuration Ċ import Ġcom . intellij . psi . Psi Class Ċ import Ġcom . intellij . psi . Psi Directory Ċ import Ġcom . intellij . psi . Psi Method Ċ import Ġorg . jetbrains . plugins . gradle . util . run Read Action And Wait Ċ import Ġorg . junit . Test Ċ Ċ class ĠGradle Test Run Configuration Producer Test Ġ: ĠGradle Test Run Configuration Producer TestCase () Ġ{ ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` test Ġsimple Ġconfiguration `() Ġ{ ĊĠĠĠ Ġval Ġproject Data Ġ= Ġgenerate And Import Template Project () ĊĠĠĠ Ġassert Configuration From Context < TestMethod Gradle Configuration Producer >( ĊĠĠĠĠĠ Ġ"" ": clean Test Ġ: test Ġ-- tests Ġ" TestCase . test 1 """ ", ĊĠĠĠĠĠ Ġproject Data [" project "][" TestCase "][" test 1 "]. element ĊĠĠĠ Ġ) ĊĠĠĠ Ġassert Configuration From Context < TestClass Gradle Configuration Producer >( ĊĠĠĠĠĠ Ġ"" ": clean Test Ġ: test Ġ-- tests Ġ" TestCase """ ", ĊĠĠĠĠĠ Ġproject Data [" project "][" TestCase "]. element ĊĠĠĠ Ġ) ĊĠĠĠ Ġassert Configuration From Context < All In Package Gradle Configuration Producer >( ĊĠĠĠĠĠ Ġ"" ": clean Test Ġ: test Ġ-- tests Ġ" pkg .* """ ", ĊĠĠĠĠĠ Ġrun Read Action And Wait Ġ{ Ġproject Data [" project "][" pkg . TestCase "]. element . containing File . containing Directory Ġ} ĊĠĠĠ Ġ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` test Ġpattern Ġconfiguration `() Ġ{ ĊĠĠĠ Ġval Ġproject Data Ġ= Ġgenerate And Import Template Project () ĊĠĠĠ Ġassert Configuration From Context < Pattern Gradle Configuration Producer >( ĊĠĠĠĠĠ Ġ"" ": clean Test Ġ: test Ġ-- tests Ġ" TestCase . test 1 " Ġ-- tests Ġ" pkg . TestCase . test 1 " Ġ""" Ġ+ ĊĠĠĠĠĠ Ġ"" ": module : clean Test Ġ: module : test Ġ-- tests Ġ" Module TestCase . test 1 " Ġ-- continue """, ĊĠĠĠĠĠ Ġproject Data [" project "][" TestCase "][" test 1 "]. element , ĊĠĠĠĠĠ Ġproject Data [" project "][" pkg . TestCase "][" test 1 "]. element , ĊĠĠĠĠĠ Ġproject Data [" module "][" Module TestCase "][" test 1 "]. element ĊĠĠĠ Ġ) ĊĠĠĠ Ġassert Configuration From Context < Pattern Gradle Configuration Producer >( ĊĠĠĠĠĠ Ġ"" ": clean Test Ġ: test Ġ-- tests Ġ" TestCase " Ġ-- tests Ġ" pkg . TestCase " Ġ""" Ġ+ ĊĠĠĠĠĠ Ġ"" ": module : clean Test Ġ: module : test Ġ-- tests Ġ" Module TestCase " Ġ-- continue """, ĊĠĠĠĠĠ Ġproject Data [" project "][" TestCase "]. element , ĊĠĠĠĠĠ Ġproject Data [" project "][" pkg . TestCase "]. element , ĊĠĠĠĠĠ Ġproject Data [" module "][" Module TestCase "]. element ĊĠĠĠ Ġ) ĊĠĠĠ Ġassert Configuration From Context < Pattern Gradle Configuration Producer >( ĊĠĠĠĠĠ Ġ"" ": clean Test Ġ: test Ġ-- tests Ġ" TestCase . test 1 " Ġ-- tests Ġ" pkg . TestCase . test 1 " Ġ""" Ġ+ ĊĠĠĠĠĠ Ġ"" ": module : clean Test Ġ: module : test Ġ-- tests Ġ" Module TestCase " Ġ-- continue """, ĊĠĠĠĠĠ Ġproject Data [" project "][" TestCase "][" test 1 "]. element , ĊĠĠĠĠĠ Ġproject Data [" project "][" pkg . TestCase "][" test 1 "]. element , ĊĠĠĠĠĠ Ġproject Data [" module "][" Module TestCase "]. element ĊĠĠĠ Ġ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` test Ġconfiguration Ġproducer Ġproperly Ġmatches Ġconfiguration Ġwith Ġcontext `() Ġ{ ĊĠĠĠ Ġval Ġproject Data Ġ= Ġgenerate And Import Template Project () ĊĠĠĠ Ġrun Read Action And Wait Ġ{ ĊĠĠĠĠĠ Ġval Ġlocations Ġ= ĠlistOf ( project Data [" project "][" TestCase "][" test 1 "]. element , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġproject Data [" project "][" TestCase "]. element , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġproject Data [" project "][" pkg . TestCase "]. element . containing File . containing Directory , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġproject Data [" project "][" TestCase "][" test 2 "]. element ) ĊĊĠĠĠĠĠ Ġval Ġcontexts Ġ= Ġ( locations Ġ+ Ġlocations ). map Ġ{ ĠgetContext By Location ( it ) Ġ} Ġ// Ġwith Ġduplicate Ġlocations ĊĠĠĠĠĠ Ġval Ġcfg From Ctx Ġ= Ġcontexts . map Ġ{ Ġget Configuration From Context ( it ) Ġ} ĊĠĠĠĠĠ Ġval Ġconfigurations Ġ= Ġcfg From Ctx . map Ġ{ Ġit . configuration Ġas ĠExternal System Run Configuration Ġ} ĊĠĠĠĠĠ Ġval Ġmethod Prod Ġ= Ġget Configuration Producer < TestMethod Gradle Configuration Producer >() ĊĠĠĠĠĠ Ġval Ġclass Prod Ġ= Ġget Configuration Producer < TestClass Gradle Configuration Producer >() ĊĠĠĠĠĠ Ġval Ġpackage Prod Ġ= Ġget Configuration Producer < All In Package Gradle Configuration Producer >() ĊĊĠĠĠĠĠ Ġfor Ġ(( j , Ġconfiguration ) Ġin Ġconfigurations . with Index ()) Ġ{ ĊĠĠĠĠĠĠĠ Ġfor Ġ(( k , Ġcontext ) Ġin Ġcontexts . with Index ()) Ġ{ ĊĠĠĠĠĠĠĠĠĠ Ġval Ġcfg Matches Context Ġ= Ġj Ġ% Ġlocations . size Ġ== Ġk Ġ% Ġlocations . size ĊĊĠĠĠĠĠĠĠĠĠ Ġval Ġis Psi Method Ġ= Ġcontext . psi Location Ġis ĠPsi Method ĊĠĠĠĠĠĠĠĠĠ ĠassertEquals ( is Psi Method Ġ&& Ġcfg Matches Context , Ġmethod Prod . is Configuration From Context ( configuration , Ġcontext )) ĊĊĠĠĠĠĠĠĠĠĠ Ġval Ġis Psi Class Ġ= Ġcontext . psi Location Ġis ĠPsi Class ĊĠĠĠĠĠĠĠĠĠ ĠassertEquals ( is Psi Class Ġ&& Ġcfg Matches Context , Ġclass Prod . is Configuration From Context ( configuration , Ġcontext )) ĊĊĠĠĠĠĠĠĠĠĠ Ġval Ġis Psi Dir Ġ= Ġcontext . psi Location Ġis ĠPsi Directory ĊĠĠĠĠĠĠĠĠĠ ĠassertEquals ( is Psi Dir Ġ&& Ġcfg Matches Context , Ġpackage Prod . is Configuration From Context ( configuration , Ġcontext )) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠ Ġval Ġcontext Ġ= ĠgetContext By Location (* locations . to Typed Array ()) ĊĊĠĠĠĠĠ ĠassertFalse ( method Prod . is Configuration From Context ( configurations [ 0 ], Ġcontext )) ĊĠĠĠĠĠ ĠassertFalse ( class Prod . is Configuration From Context ( configurations [ 1 ], Ġcontext )) ĊĠĠĠĠĠ ĠassertFalse ( package Prod . is Configuration From Context ( configurations [ 2 ], Ġcontext )) ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` test Ġconfiguration Ġescap ing `() Ġ{ ĊĠĠĠ Ġval Ġproject Data Ġ= Ġgenerate And Import Template Project () ĊĠĠĠ Ġassert Configuration From Context < TestMethod Gradle Configuration Producer >( ĊĠĠĠĠĠ Ġ""" ': my Ġmodule : clean Test ' Ġ': my Ġmodule : test ' Ġ-- tests Ġ" My Module TestCase . test 1 """ ", ĊĠĠĠĠĠ Ġproject Data [" my Ġmodule "][" My Module TestCase "][" test 1 "]. element ĊĠĠĠ Ġ) ĊĠĠĠ Ġassert Configuration From Context < TestClass Gradle Configuration Producer >( ĊĠĠĠĠĠ Ġ""" ': my Ġmodule : clean Test ' Ġ': my Ġmodule : test ' Ġ-- tests Ġ" My Module TestCase """ ", ĊĠĠĠĠĠ Ġproject Data [" my Ġmodule "][" My Module TestCase "]. element ĊĠĠĠ Ġ) ĊĠĠĠ Ġassert Configuration From Context < Pattern Gradle Configuration Producer >( ĊĠĠĠĠĠ Ġ""" ': my Ġmodule : clean Test ' Ġ': my Ġmodule : test ' Ġ-- tests Ġ" My Module TestCase . test 1 " Ġ-- tests Ġ" My Module TestCase . test 2 """ ", ĊĠĠĠĠĠ Ġproject Data [" my Ġmodule "][" My Module TestCase "][" test 1 "]. element , ĊĠĠĠĠĠ Ġproject Data [" my Ġmodule "][" My Module TestCase "][" test 2 "]. element ĊĠĠĠ Ġ) ĊĠĠĠ Ġassert Configuration From Context < TestMethod Gradle Configuration Producer >( ĊĠĠĠĠĠ Ġ"" ": clean Test Ġ: test Ġ-- tests Ġ" Gro ovy TestCase . Don \' t Ġuse Ġsingle Ġ* Ġqu o \* tes """ ", ĊĠĠĠĠĠ Ġproject Data [" project "][" Gro ovy TestCase "][ """ Don \' t Ġuse Ġsingle Ġ. Ġqu o \" tes """ ]. element ĊĠĠĠ Ġ) ĊĠĠĠ Ġassert Configuration From Context < Pattern Gradle Configuration Producer >( ĊĠĠĠĠĠ Ġ"" ": clean Test Ġ: test Ġ-- tests Ġ" Gro ovy TestCase . Don \' t Ġuse Ġsingle Ġ* Ġqu o \* tes " Ġ-- tests Ġ" Gro ovy TestCase . test 2 """ ", ĊĠĠĠĠĠ Ġproject Data [" project "][" Gro ovy TestCase "][ """ Don \' t Ġuse Ġsingle Ġ. Ġqu o \" tes """ ]. element , ĊĠĠĠĠĠ Ġproject Data [" project "][" Gro ovy TestCase "][" test 2 "]. element ĊĠĠĠ Ġ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` test Ġconfiguration Ġdifferent Ġtasks Ġin Ġsingle Ġmodule `() Ġ{ ĊĠĠĠ Ġcurrent External Project Settings . is Resolve Module Per Source Set Ġ= Ġfalse ĊĠĠĠ Ġval Ġproject Data Ġ= Ġgenerate And Import Template Project () ĊĠĠĠ Ġassert Configuration From Context < Pattern Gradle Configuration Producer >( ĊĠĠĠĠĠ Ġ"" ": clean Test Ġ: test Ġ-- tests Ġ" TestCase " Ġ: clean Auto Test Ġ: auto Test Ġ-- tests Ġ" Automation TestCase " Ġ-- continue """, ĊĠĠĠĠĠ Ġproject Data [" project "][" TestCase "]. element , ĊĠĠĠĠĠ Ġproject Data [" project "][" Automation TestCase "]. element , ĊĠĠĠĠĠ Ġtest Tasks Filter Ġ= Ġ{ Ġit Ġin Ġset Of (" test ", Ġ" auto Test ") Ġ} ĊĠĠĠ Ġ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` test Ġconfiguration Ġtests Ġfor Ġdirectory `() Ġ{ ĊĠĠĠ Ġval Ġproject Data Ġ= Ġgenerate And Import Template Project () ĊĠĠĠ Ġassert Configuration From Context < All In Directory Gradle Configuration Producer >( ĊĠĠĠĠĠ Ġ"" ": clean Auto Test Ġ: auto Test Ġ-- tests Ġ* Ġ: clean Automation Test Ġ: automation Test Ġ-- tests Ġ* Ġ: clean Test Ġ: test Ġ-- tests Ġ* Ġ-- continue """, ĊĠĠĠĠĠ Ġproject Data [" project "]. root ĊĠĠĠ Ġ) ĊĠĠĠ Ġassert Configuration From Context < All In Directory Gradle Configuration Producer >( ĊĠĠĠĠĠ Ġ"" ": clean Test Ġ: test Ġ-- tests Ġ* """, ĊĠĠĠĠĠ Ġproject Data [" project "]. root . sub Directory (" src ") ĊĠĠĠ Ġ) ĊĠĠĠ Ġassert Configuration From Context < All In Directory Gradle Configuration Producer >( ĊĠĠĠĠĠ Ġ"" ": clean Test Ġ: test Ġ-- tests Ġ* """, ĊĠĠĠĠĠ Ġproject Data [" project "]. root . sub Directory (" src ", Ġ" test ") ĊĠĠĠ Ġ) ĊĠĠĠ Ġassert Configuration From Context < All In Package Gradle Configuration Producer >( ĊĠĠĠĠĠ Ġ"" ": clean Test Ġ: test Ġ-- tests Ġ* """, ĊĠĠĠĠĠ Ġproject Data [" project "]. root . sub Directory (" src ", Ġ" test ", Ġ" java ") ĊĠĠĠ Ġ) ĊĠĠĠ Ġassert Configuration From Context < All In Package Gradle Configuration Producer >( ĊĠĠĠĠĠ Ġ"" ": clean Auto Test Ġ: auto Test Ġ-- tests Ġ* Ġ: clean Automation Test Ġ: automation Test Ġ-- tests Ġ* Ġ-- continue """, ĊĠĠĠĠĠ Ġproject Data [" project "]. root . sub Directory (" automation ") ĊĠĠĠ Ġ) ĊĠĠĠ Ġassert Configuration From Context < All In Directory Gradle Configuration Producer >( ĊĠĠĠĠĠ Ġ"" ": module : clean Test Ġ: module : test Ġ-- tests Ġ* """, ĊĠĠĠĠĠ Ġproject Data [" module "]. root ĊĠĠĠ Ġ) ĊĠ Ġ} Ċ } Ċ