[Cuis-dev] [IMPROV] Testing and Debugging Deprecated Methods

Gerald Klix cuis.01 at klix.ch
Mon Sep 28 10:17:53 PDT 2020


Hi all, hi Juan,

I suggested in another post to flag unit deprecated methods in unit tests.
Now I implemented the required changes.

Please find a change set and small package with some unit test attached 
to this message.


HTH and Best Regards,

Gerald
-------------- next part --------------
'From Cuis 5.0 [latest update: #4382] on 28 September 2020 at 6:59:00 pm'!
!classDefinition: #DeprecationWarning category: #'Exceptions Extensions'!
Warning subclass: #DeprecationWarning
	instanceVariableNames: ''
	classVariableNames: ''
	poolDictionaries: ''
	category: 'Exceptions Extensions'!

!DeprecationWarning commentStamp: '<historical>' prior: 0!
I warn against the use of deprecated methods.!


!DeprecationWarning methodsFor: 'debug support' stamp: 'KLG 9/28/2020 16:33:34'!
openDebugger
	"Open the debugger on the warning."

	Debugger
		openContext: thisContext
		label: 'Warning'
		contents: self messageText
! !

!DeprecationWarning methodsFor: 'exceptionDescription' stamp: 'KLG 9/28/2020 16:35:33'!
defaultAction
	"The user should be notified of the occurrence of an exceptional occurrence and given an option of continuing or aborting the computation. The description of the occurrence should include any text specified as the argument of the #signal: message.
	
	In my case we look at the preferences."
	Preferences
		showDeprecationWarningsInTranscript ifTrue: [			self showOnTranscript ].
	Preferences 
		openDebuggerOnDeprecationWarning ifTrue: [			self openDebugger ].
	self resume! !

!DeprecationWarning methodsFor: 'printing' stamp: 'KLG 9/28/2020 16:41:20'!
showOnTranscript
	"Show the deprecation warning on the transcript."

	signalContext ifNotNil: [
		'========' print.
		signalContext sender sender print.
		'--------------' print.
		'This method is deprecated. It will be removed from the system. Please change this and any other related senders.' print.
		'--------------' print.
		signalContext sender sender printStack: 6.
		'========' print ].! !


!Preferences class methodsFor: 'deprecation' stamp: 'KLG 9/28/2020 17:46:23'!
flagDeprecationWarningsAsUnitTestError
	"Answer true if deprecation warnings should be flagged as unit test errors."

	^ self 
		valueOfFlag: #flagDeprecationWarningsAsUnitTestError
		ifAbsent: [ true ]! !

!Preferences class methodsFor: 'deprecation' stamp: 'KLG 9/28/2020 17:52:24'!
openDebuggerOnDeprecationWarning
	"Answer true if deprecation warnings should open a debugger."

	^ self
		valueOfFlag: #openDebuggerOnDeprecationWarning
		ifAbsent: [ false ].! !

!Preferences class methodsFor: 'deprecation' stamp: 'KLG 9/28/2020 16:23:12'!
showDeprecationWarningsInTranscript
	"Answer true if deprecation warnings should be shown in the transcript."

	^ self 
		valueOfFlag: #showDeprecationWarningsInTranscript 
		ifAbsent: [ self openDebuggerOnDeprecationWarning not ]! !


!Object methodsFor: 'private' stamp: 'KLG 9/28/2020 16:36:18'!
deprecatedMethod
	"Warn that this method is deprecated and should not be used"

	DeprecationWarning signal! !


!SUnitNameResolver class methodsFor: 'Camp Smalltalk' stamp: 'KLG 9/28/2020 17:38:35'!
errorObject

	"Handle deprecation warnings, too."
	^ Preferences flagDeprecationWarningsAsUnitTestError 
		ifTrue: [ UnhandledError , DeprecationWarning ]
		ifFalse: [ UnhandledError ]! !


!DeprecationWarning reorganize!
('debug support' openDebugger)
('exceptionDescription' defaultAction)
('printing' showOnTranscript)
!


!Preferences class reorganize!
('add preferences' addPreference:categories:default:balloonHelp: addPreference:categories:default:balloonHelp:changeInformee:changeSelector: addPreference:category:default:balloonHelp:)
('bigger and smaller GUI' bigFonts defaultFont05 defaultFont06 defaultFont07 defaultFont08 defaultFont09 defaultFont10 defaultFont11 defaultFont12 defaultFont14 defaultFont17 defaultFont22 defaultFont28 defaultFont36 defaultFont46 defaultFont60 defaultFont80 haloHandleSize hugeFonts smallFonts standardFonts systemWindowBorderSize tinyFonts veryBigFonts verySmallFonts)
('class state access' parameters preferencesDictionary releaseClassState)
('code generation' leftArrowAssignmentsInGeneratedCodeWithComputedDefault)
('exception handling' allowNonLocalReturnsInExceptionHandlers warnAboutNonLocalReturnsInExceptionHandlers)
('fonts' loadOnlyLatinGlyphData properDisplayAlphaForFonts restoreDefaultFonts setButtonFontTo: setCodeFontTo: setDefaultFont: setDefaultFont:spec: setListFontTo: setMenuFontTo: setSystemFontTo: setWindowTitleFontTo: standardButtonFont standardCodeFont standardListFont standardMenuFont subPixelRenderColorFonts windowTitleFont)
('get/set' disable: disableFocusFollowsMouse disableTileResizerInWindowMenu doesNotUnderstand: enable: enableFocusFollowsMouse enableTileResizerInWindowMenu setPreference:toValue: togglePreference: valueOfFlag: valueOfFlag:ifAbsent:)
('halos' haloSpecifications iconicHaloSpecifications installHaloSpecsFromArray: installHaloTheme: resetHaloSpecifications)
('hard-coded prefs' desktopMenuTitle)
('initialization' compileAccessMethodForPreference: setPreferencesFrom:)
('menu icons' useMenuIcons useNoMenuIcons)
('menu parameters' menuBorderWidth)
('misc' wantsChangeSetLogging)
('parameters' annotationInfo defaultAnnotationRequests defaultAuthorName setDefaultAnnotationInfo)
('personalization' compileHardCodedPref:enable: disableProgrammerFacilities enableProgrammerFacilities usePreDebugWindow)
('preference-object access' preferenceAt: preferenceAt:ifAbsent:)
('preferences panel' openPreferencesInspector)
('scrollbar parameters' scrollbarThickness)
('shout' backgroundColorFillsAllBackground highlightBlockNesting italicsInShout shoutInWorkspaces useAlwaysLeftArrow useAssignmentGlyphLeftArrow useAssignmentGlyphRightArrow)
('standard queries' aaFontsColormapDepth allowBlockArgumentAssignment alternativeBrowseIt assignmentGlyphSelector autoNumberUserChanges automaticPlatformSettings balloonHelpEnabled biggerCursors browseWithPrettyPrint canRecordWhilePlaying caseSensitiveFinds changeSetVersionNumbers cheapWindowReframe checkForSlips clickGrabsMorphs cmdDotEnabled ctrlArrowsScrollHorizontally debugHaloHandle debugLogTimestamp debugShowDamage debugShowDamage2 decorateBrowserButtons diffsInChangeList diffsWithPrettyPrint dismissAllOnOptionClose extraDebuggerButtons focusFollowsMouse focusIndicatorWidth fullScreenLeavesDeskMargins haloEnclosesFullBounds leftArrowAssignmentsInGeneratedCode listClassesHierarchically logDebuggerStackToFile menuKeyboardControl optionalButtons prettyPrintRectangularBlocks selectionsMayShrink selectiveHalos serverMode showAnnotations showLinesInHierarchyViews soundQuickStart soundStopWhenDone soundsEnabled subPixelRenderFonts syntaxHighlightingAsYouType syntaxHighlightingAsYouTypeAnsiAssignment syntaxHighlightingAsYouTypeLeftArrowAssignment systemWindowEmbedOK tapAndHoldEmulatesButton2 thoroughSenders tileResizerInWindowMenu transcriptLogVerbose wantsMenuIcons warnIfNoChangesFile warnIfNoSourcesFile)
('start up' checkLostChangesOnStartUp)
('user changes' use:asUserChangesFileNameExtensionWhile: userChangesFileNameExtension)
('themes' cuisDefaults forMouse forTouch slowMachine smalltalk80)
('deprecation' flagDeprecationWarningsAsUnitTestError openDebuggerOnDeprecationWarning showDeprecationWarningsInTranscript)
!

-------------- next part --------------
'From Cuis 5.0 [latest update: #4382] on 28 September 2020 at 6:57:25 pm'!
'Description '!
!provides: 'DeprecatedMethodTest' 1 2!
SystemOrganization addCategory: #DeprecatedMethodTest!


!classDefinition: #MethodDepricationTest category: #DeprecatedMethodTest!
TestCase subclass: #MethodDepricationTest
	instanceVariableNames: ''
	classVariableNames: ''
	poolDictionaries: ''
	category: 'DeprecatedMethodTest'!
!classDefinition: 'MethodDepricationTest class' category: #DeprecatedMethodTest!
MethodDepricationTest class
	instanceVariableNames: ''!


!MethodDepricationTest methodsFor: 'testing' stamp: 'KLG 9/28/2020 17:05:23'!
no_testDeprecation
	"Can be renamed to #testDeprecation to make sure the test runner shows the problem."

	self someDeprecatedMethod! !

!MethodDepricationTest methodsFor: 'testing' stamp: 'KLG 9/28/2020 17:02:55'!
testDeprecationRaises
	"Make sure we see deprecation in unit tests."

	self should: [ self someDeprecatedMethod ] raise: DeprecationWarning! !

!MethodDepricationTest methodsFor: 'running - private' stamp: 'KLG 9/28/2020 17:01:26'!
someDeprecatedMethod
	"I am a method that is deprecated."

	self deprecatedMethod! !


More information about the Cuis-dev mailing list