Last active
July 15, 2017 17:46
-
-
Save mossheim/7735a484e54b59dce5dd524651586d2a to your computer and use it in GitHub Desktop.
WIP test script for SuperCollider PR #2861 (https://github.com/supercollider/supercollider/pull/2861)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // WARNING: This test script will muck your sclang_conf.yaml file. Back it up before running! | |
| ( | |
| // these should give consistent results between old and new versions | |
| // test on non-ASCII user | |
| thisProcess.platform.userHomeDir.postln; | |
| thisProcess.platform.systemAppSupportDir.postln; | |
| thisProcess.platform.userAppSupportDir.postln; | |
| thisProcess.platform.systemExtensionDir.postln; | |
| thisProcess.platform.userExtensionDir.postln; | |
| thisProcess.platform.userConfigDir.postln; | |
| thisProcess.platform.resourceDir.postln; | |
| (thisProcess.platform.name === \windows).if { | |
| thisProcess.platform.myDocumentsDir.postln; | |
| }; | |
| thisProcess.platform.ideName.postln; // should give 'scqt' | |
| // should expand to home directory, check on non-ASCII user | |
| ~path = "~/".standardizePath; | |
| // globbing behavior should match between old and new versions. not sure this covers all cases | |
| "/".pathMatch.postln; | |
| "*".pathMatch.postln; | |
| "/*".pathMatch.postln; | |
| "/*".pathMatch.postln; | |
| "????".pathMatch.postln; | |
| "U*".pathMatch.postln; | |
| ~path.pathMatch.postln; | |
| (~path +/+ "*").pathMatch.postln; | |
| (~path +/+ "???").pathMatch.postln; | |
| (~path +/+ "D*").pathMatch.postln; | |
| (~path +/+ "D*/*.*").pathMatch.postln; | |
| // from another test file I had: | |
| "".pathMatch.postln; | |
| "*".pathMatch.postln; | |
| "*/".pathMatch.postln; | |
| "/*".pathMatch.postln; | |
| "/*/".pathMatch.postln; | |
| "/????".pathMatch.postln; | |
| "????".pathMatch.postln; | |
| "/*????/".pathMatch.postln; // grabs directories of length >3 | |
| "*v*".pathMatch.postln; | |
| "/users/".pathMatch.postln; | |
| "/Users/".pathMatch.postln; | |
| "/Users*/".pathMatch.postln; | |
| "/[abc]*/".pathMatch.postln; | |
| "/[ABC]*/".pathMatch.postln; | |
| ~expect = { |a,b,m| if(a != b) { "failure: expected %, got %: %\n".postf(b, a, m) } }; | |
| ~test_names = ["aa", "b😂", "c✋", "d我", "eé"]; | |
| // test on non-ASCII user, not sure of expected result, this | |
| // returns '/' on macOS | |
| File.getcwd.postln; | |
| /***** PIPE TESTING ******/ | |
| { | |
| // not sure how to test pipes, this is from the help file | |
| var p, l; | |
| p = (thisProcess.platform.name !== \windows).if { Pipe.new("ls", "r") } { Pipe.new("dir", "r") }; | |
| // p = Pipe.new("dir", "r"); // list directory contents in long format | |
| l = p.getLine; // get the first line | |
| while({l.notNil}, {l.postln; l = p.getLine; }); // post until l = nil | |
| p.close; // close the pipe to avoid that nasty buildup | |
| }.value; | |
| /****** FILE PRIMITIVE TESTING ******/ | |
| // these do not need to be run on a non-ASCII user | |
| ~test_names.do { | |
| arg name; | |
| var filepath = ~path +/+ name; | |
| var filepath_copied = filepath ++ "_copy"; | |
| var string = "a test string".scramble; | |
| var signal = Signal.rand(5, -20, 20); | |
| var read_signal = Signal.newClear(signal.size); | |
| // testing open | |
| var file = File.open(filepath.postln, "w"); | |
| ~expect.(file.isOpen, true, "isOpen"); | |
| file.write(string); | |
| file.close(); | |
| ~expect.(file.isOpen, false, "isOpen after close"); | |
| // testing exists | |
| ~expect.(File.exists(filepath), true, "exists"); | |
| // testing mtime | |
| ~expect.(File.mtime(filepath) > 0, true, "mtime"); | |
| // testing | |
| ~expect.(File.fileSize(filepath), 13, "fileSize"); | |
| // type | |
| ~expect.(File.type(filepath), \regular, "type"); | |
| // read | |
| file = File.open(filepath, "r"); | |
| ~expect.(file.isOpen, true, "isOpen for read"); | |
| ~expect.(file.readAllString, string, "read contents"); | |
| file.close; | |
| // parseYamlFile, conversion to yaml strips trailing ws | |
| ~expect.(filepath.parseYAMLFile, string.stripWhiteSpace, "parseYAMLFile"); | |
| // copy | |
| File.copy(filepath, filepath_copied); | |
| ~expect.(File.exists(filepath_copied), true, "exists after copy"); | |
| // delete. | |
| File.delete(filepath); | |
| ~expect.(File.exists(filepath), false, "exists after delete"); | |
| // ********* Comment out this line to confirm that the files were created with the expected names | |
| File.delete(filepath_copied); | |
| ~expect.(File.exists(filepath_copied), false, "exists after deleting copy"); | |
| // mkdir | |
| File.mkdir(filepath); | |
| ~expect.(File.exists(filepath), true, "exists after mkdir"); | |
| // type | |
| ~expect.(File.type(filepath), \directory, "type after mkdir"); | |
| // realpath | |
| ~expect.(File.realpath(filepath ++ "/."), filepath, "realpath"); | |
| ~expect.(File.realpath(filepath ++ "///"), filepath, "realpath"); | |
| ~expect.(File.realpath(filepath ++ "/../" ++ name), filepath, "realpath"); | |
| // delete again | |
| File.delete(File.realpath(filepath ++ "/.")); | |
| ~expect.(File.exists(filepath), false, "exists after deleting dir"); | |
| // SoundFile stuff | |
| // openwrite | |
| file = SoundFile.openWrite(filepath ++ ".wav"); | |
| ~expect.(File.exists(filepath++".wav"), true, "SoundFile exists"); | |
| ~expect.(file.isOpen, true, "SoundFile isOpen"); | |
| file.writeData(signal); | |
| file.close; | |
| // openread | |
| file = SoundFile.openRead(filepath ++ ".wav"); | |
| ~expect.(file.isOpen, true, "SoundFile isOpen for read"); | |
| file.readData(read_signal); | |
| ~expect.(read_signal, signal, "SoundFile read data"); | |
| file.close(); | |
| // delete, already tested | |
| File.delete(filepath ++ ".wav"); | |
| "done testing filename %\n".postf(name); | |
| }; | |
| "done testing file operations".postln; | |
| /****** LANGUAGE CONFIG TESTING ******/ | |
| "now testing LanguageConfig".postln; | |
| ~string = "C:/Users/üsér/"; | |
| LanguageConfig.includePaths.do { |x| | |
| LanguageConfig.removeIncludePath(x); | |
| }; | |
| LanguageConfig.excludePaths.do { |x| | |
| LanguageConfig.removeExcludePath(x); | |
| }; | |
| LanguageConfig.addIncludePath(~string); | |
| ~expect.(LanguageConfig.includePaths[0], ~string, "adding include paths works"); | |
| LanguageConfig.addExcludePath(~string); | |
| ~expect.(LanguageConfig.excludePaths[0], ~string, "adding exclude paths works"); | |
| LanguageConfig.store; | |
| LanguageConfig.removeIncludePath(~string); | |
| ~expect.(LanguageConfig.includePaths.isEmpty, true, "removing include paths works"); | |
| LanguageConfig.removeExcludePath(~string); | |
| ~expect.(LanguageConfig.excludePaths.isEmpty, true, "removing exclude paths works"); | |
| "done testing LanguageConfig".postln; | |
| "check your sclang_conf.yaml file".postln; | |
| /* it should read: | |
| includePaths: | |
| - C:/Users/üsér/ | |
| excludePaths: | |
| - C:/Users/üsér/ | |
| postInlineWarnings: false | |
| */ | |
| "\ndone with all tests!".postln; | |
| ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment