Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add #getTemporaryDirectory to UnixPlatform and WinPlatform #13777

Merged
merged 10 commits into from
May 26, 2023
24 changes: 24 additions & 0 deletions src/System-Platforms-Tests/UnixPlatformTest.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"
An UnixPlatformTest is a test class for testing the behavior of UnixPlatform
"
Class {
#name : #UnixPlatformTest,
#superclass : #TestCase,
#category : #'System-Platforms-Tests-Unix'
}

{ #category : #tests }
UnixPlatformTest >> testGetTemporaryDirectoryFromTMPDIR [

| value |
OSPlatform current isUnix ifFalse: [ ^ self skip ].

value := OSEnvironment current at: 'TMPDIR' ifAbsent: [ ].
gcorriga marked this conversation as resolved.
Show resolved Hide resolved
[
| actual expected |
expected := '/tmp/foo'.
OSEnvironment current at: 'TMPDIR' put: expected.
actual := OSPlatform current getTemporaryDirectory.
self assert: actual equals: expected ] ensure: [
value ifNotNil: [ OSEnvironment current at: 'TMPDIR' put: value ] ]
]
2 changes: 1 addition & 1 deletion src/System-Platforms-Tests/Win32EnvironmentTest.class.st
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Class {
#name : #Win32EnvironmentTest,
#superclass : #TestCase,
#category : #'System-Platforms-Tests-Win32'
#category : #'System-Platforms-Tests-Windows'
}

{ #category : #tests }
Expand Down
2 changes: 1 addition & 1 deletion src/System-Platforms-Tests/Win32WideStringTest.class.st
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Class {
#name : #Win32WideStringTest,
#superclass : #TestCase,
#category : #'System-Platforms-Tests-Win32'
#category : #'System-Platforms-Tests-Windows'
}

{ #category : #tests }
Expand Down
21 changes: 21 additions & 0 deletions src/System-Platforms-Tests/WinPlatformTest.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Class {
#name : #WinPlatformTest,
#superclass : #TestCase,
#category : #'System-Platforms-Tests-Windows'
}

{ #category : #tests }
WinPlatformTest >> testGetTemporaryDirectoryFromTMP [

| value |
OSPlatform current isWindows ifFalse: [ ^ self skip ].

value := OSEnvironment current at: 'TMP' ifAbsent: [ ].
gcorriga marked this conversation as resolved.
Show resolved Hide resolved
[
| actual expected |
expected := 'X:\Temp\'.
OSEnvironment current at: 'TMP' put: expected.
actual := OSPlatform current getTemporaryDirectory.
self assert: actual equals: expected ] ensure: [
value ifNotNil: [ OSEnvironment current at: 'TMP' put: value ] ]
]
8 changes: 8 additions & 0 deletions src/System-Platforms/UnixPlatform.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ UnixPlatform >> getErrorMessage: errnum [
^ self ffiCall: #(char *strerror(int errnum)) module: #LibC
]

{ #category : #accessing }
UnixPlatform >> getTemporaryDirectory [

| tmpDir |
tmpDir := self environment at: 'TMPDIR' ifAbsent: [ '/tmp' ].
^ (tmpDir endsWith: $/) ifTrue: [ tmpDir ] ifFalse: [ tmpDir , '/' ]
]

{ #category : #testing }
UnixPlatform >> isLinux [
"Some Linux versions return linux, some linux-gnu, ..."
Expand Down
23 changes: 23 additions & 0 deletions src/System-Platforms/WinPlatform.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,29 @@ WinPlatform >> getErrorMessage: anInteger [
^ buffer asString
]

{ #category : #'file paths' }
WinPlatform >> getTempPath [

| buffer length |
length := self defaultMaximumPathLength.
buffer := (String new: length) asWin32WideString.
self getTempPath: length buffer: buffer.
^buffer asString
]

{ #category : #'file paths' }
WinPlatform >> getTempPath: bufferLength buffer: buffer [

self ffiCall: #(long GetTempPath2W(long bufferLength,
void* buffer))
]

{ #category : #accessing }
WinPlatform >> getTemporaryDirectory [

^ self getTempPath
]

{ #category : #testing }
WinPlatform >> isWindows [
^ true
Expand Down