diff --git a/SwiftShell/Context.swift b/SwiftShell/Context.swift index 544368e..8adf427 100644 --- a/SwiftShell/Context.swift +++ b/SwiftShell/Context.swift @@ -117,7 +117,9 @@ public final class MainShellContext: ShellContextType { public lazy var tempdirectory: String = createTempdirectory() public lazy var arguments: [String] = Process.arguments.count <= 1 ? [] : Array(Process.arguments.dropFirst()) - public lazy var name: String = Process.arguments.first.map(NSURL.init)?.lastPathComponent ?? "" + + /** The path to the currently running executable. Will be empty in playgrounds. */ + public lazy var path: String = Process.arguments.first ?? "" private init() { } diff --git a/SwiftShellTests/Scripts/print_name_and_args.swift b/SwiftShellTests/Scripts/print_name_and_args.swift index 705c7d6..e3c33e5 100755 --- a/SwiftShellTests/Scripts/print_name_and_args.swift +++ b/SwiftShellTests/Scripts/print_name_and_args.swift @@ -2,4 +2,4 @@ import SwiftShell -print(main.name, main.arguments.map {"\""+($0)+"\""} .joinWithSeparator(" ")) +print(NSURL(fileURLWithPath: main.path).lastPathComponent!, main.arguments.map {"\""+($0)+"\""} .joinWithSeparator(" ")) diff --git a/SwiftShellTests/Scripts/runtests.bash b/SwiftShellTests/Scripts/runtests.bash index f41676c..7b3bc1f 100755 --- a/SwiftShellTests/Scripts/runtests.bash +++ b/SwiftShellTests/Scripts/runtests.bash @@ -21,9 +21,9 @@ export SWIFTSHELL_FRAMEWORK_PATH=$PROJECT_ROOT/build/Release/ assert "./print_name_and_args.swift 1 2" "print_name_and_args.swift \"1\" \"2\"" assert_raises "./exitswhenopeningnon-existentfile.swift" 132 -assert "cat onetwothree.txt | ./print_linenumbers.swift" "line 1: one\nline 2: two\nline 3: three" +assert "cat onetwothree.txt | ./print_linenumbers.swift" "1: one\n2: two\n3: three" assert "./stream_out.swift" " 3" -assert "./callswiftscriptfromswift.swift" "line 1: one\nline 2: two\nline 3: three" +assert "./callswiftscriptfromswift.swift" "1: one\n2: two\n3: three" assert "./readfilelinebyline.swift" "one\ntwo\nthree" assert_raises "./readandwritefiles.swift" 0