test/MCVersionTest.st
author Jan Vrany <jan.vrany@labware.com>
Fri, 17 May 2024 23:06:48 +0100
branchjv
changeset 1179 2b0400211720
parent 1121 c5661215109c
permissions -rw-r--r--
Tonel: fix possible endless recursion in `TonelRepository class >> discover:` This commit fixes horrible bug in `TonelRepository class >> discover:` when using relative directories that caused endless recursion. This is because `Filename >> directory` does not handle well relative directories: following code causes endless loop: f := '.' asFilename. [ f isRootDirectory ] whileFalse:[f := f directory]. while this one does not: f := Filename currentDirectory. [ f isRootDirectory ] whileFalse:[f := f directory]. Clearly, this is something that has to be fixed in `Filename`, but meanwhile, we fix it here too. While at it, rewrite this method using loop as opposed ro recursion.

"
COPYRIGHT (c) 2020 LabWare
"
"{ Package: 'stx:goodies/monticello/test' }"

"{ NameSpace: Smalltalk }"

MCTestCase subclass:#MCVersionTest
	instanceVariableNames:'version'
	classVariableNames:''
	poolDictionaries:''
	category:'SCM-Monticello-Tests'
!

!MCVersionTest class methodsFor:'documentation'!

copyright
"
COPYRIGHT (c) 2020 LabWare


"
! !

!MCVersionTest methodsFor:'asserting'!

assert: aSelector orders: sexpr as: array
	| expected |
	expected := OrderedCollection new.
	version := self versionFromTree: sexpr.
	version perform: aSelector with: [:ea | expected add: ea info name].
	self assert: expected asArray = array
!

assert: aSelector orders: sexpr as: expected unresolved: unresolved
	| missing visited |
	visited := OrderedCollection new.
	missing := OrderedCollection new.
	version := self versionFromTree: sexpr.
	version 
		perform: aSelector 
		with: [:ea | visited add: ea info name]
		with: [:ea | missing add: ea name].
	self assert: visited asArray = expected.
	self assert: missing asArray = unresolved.
! !

!MCVersionTest methodsFor:'building'!

dependencyFromTree: sexpr
	^ MCMockDependency fromTree: sexpr
!

versionFromTree: sexpr
	^ (self dependencyFromTree: sexpr) resolve
! !

!MCVersionTest methodsFor:'tests'!

testAllAvailablePostOrder
	self 
		assert: #allAvailableDependenciesDo: 
		orders: #(a ((b (d e)) c)) 
		as: #(d e b c)
!

testAllMissing
	self 
		assert: #allDependenciesDo: 
		orders: #(a ((b (d e)) (c missing))) 
		as: #(d e b)
!

testAllUnresolved
	self 
		assert: #allDependenciesDo:ifUnresolved: 
		orders: #(a ((b (d e)) (c missing)))
		as: #(d e b)
		unresolved: #(c)
!

testDependencyOrder
	self 
		assert: #allDependenciesDo: 
		orders: #(a (b c)) 
		as: #(b c)
!

testPostOrder
	self 
		assert: #allDependenciesDo: 
		orders: #(a ((b (d e)) c)) 
		as: #(d e b c)
!

testWithAll
	self 
		assert: #withAllDependenciesDo: 
		orders: #(a ((b (d e)) c)) 
		as: #(d e b c a)
!

testWithAllMissing
	self 
		assert: #withAllDependenciesDo: 
		orders: #(a ((b (d e)) (c missing))) 
		as: #(d e b a)
!

testWithAllUnresolved
	self 
		assert: #withAllDependenciesDo:ifUnresolved: 
		orders: #(a ((b (d e)) (c missing)))
		as: #(d e b a)
		unresolved: #(c)
! !

!MCVersionTest class methodsFor:'documentation'!

version
    ^ '$Header: /cvs/stx/stx/goodies/monticello/test/MCVersionTest.st,v 1.2 2013-05-29 00:01:51 vrany Exp $'
! !