Last active
November 3, 2019 03:36
-
-
Save petertseng/e3e88bf1c383865ff67f4095413993b2 to your computer and use it in GitHub Desktop.
Exercism autosubmit
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
| #!/usr/bin/env ruby | |
| if ARGV.empty? | |
| puts "usage: #{$PROGRAM_NAME} dir" | |
| Kernel.exit(1) | |
| end | |
| track = File.basename(File.dirname(File.realpath(ARGV[0]))) | |
| def glob(*components, except: []) | |
| except = [*except] | |
| Dir.glob(File.join(ARGV[0], *components)).reject { |f| | |
| # Thanks, R track, for naming your files test_{exercise}.R | |
| except.any? { |e| e.is_a?(Regexp) ? f.match?(e) : f.end_with?(e) } | |
| } | |
| end | |
| files = case track | |
| when 'ballerina' | |
| glob('*.bal') | |
| when 'c' | |
| glob('src', '*.c') | |
| when 'ceylon' | |
| glob('source', '*', '*.ceylon', except: %w(module.ceylon Test.ceylon)) | |
| when 'cfml' | |
| glob('*.cfc', except: %w(Test.cfc TestRunner.cfc)) | |
| when 'clojure' | |
| glob('src', '*.clj') | |
| when 'coq' | |
| glob('*.v', except: 'test.v') | |
| when 'cpp' | |
| glob('*.cpp', except: '_test.cpp') | |
| when 'crystal' | |
| glob('src', '*.cr') | |
| when 'csharp' | |
| glob('*.cs', except: 'Test.cs') | |
| when 'd' | |
| glob('source', '*.d') | |
| when 'dart' | |
| glob('lib', '*.dart') | |
| when 'ecmascript' | |
| # Note: I include .ts files, typically students won't have. | |
| glob('*.ts') + glob('*.js', except: %w(.spec.js gulpfile.js)) | |
| when 'elixir' | |
| # Note: I rename the lib files from exs to ex | |
| glob('*.ex') + glob('*.exs', except: '_test.exs') | |
| when 'elm' | |
| glob('*.elm', except: 'Tests.elm') | |
| when 'erlang' | |
| glob('src', '*.erl') | |
| when 'factor' | |
| glob('*.factor', except: '-tests.factor') | |
| when 'fsharp' | |
| glob('*.fs', except: %w(Test.fs Program.fs)) | |
| when 'go' | |
| glob('*.go', except: '_test.go') | |
| when 'groovy' | |
| glob('*.groovy', except: 'Spec.groovy') | |
| when 'haskell' | |
| glob('src', '*.hs') | |
| when 'haxe' | |
| glob('src', '*.hx') | |
| when 'idris' | |
| glob('src', '*.idr') | |
| when 'java' | |
| glob('src', 'main', 'java', '*.java') | |
| when 'javascript' | |
| # Note: I include .ts files, typically students won't have. | |
| glob('*.ts') + glob('*.js', except: '.spec.js') | |
| when 'julia' | |
| glob('*.jl', except: 'runtests.jl') | |
| when 'kotlin' | |
| glob('src', 'main', 'kotlin', '*.kt') | |
| when 'lua' | |
| glob('*.lua', except: '_spec.lua') | |
| when 'nim' | |
| glob('*.nim', except: '_test.nim') | |
| when 'ocaml' | |
| glob('*.ml', except: 'test.ml') | |
| when 'perl5' | |
| # Note: tests have .t ext, files have *.pm extension. | |
| # So, "files of same extension as test file" wouldn't work | |
| # This script doesn't care, but an autodetector will fail. | |
| glob('*.pm') | |
| when 'perl6' | |
| # Same idea w/ "files of same extension as test file" | |
| glob('*.pm6') | |
| when 'php' | |
| glob('*.php', except: '_test.php') | |
| when 'pony' | |
| glob('*.pony', except: 'test.pony') | |
| when 'prolog' | |
| glob('*.pl') | |
| when 'purescript' | |
| glob('src', '*.purs') | |
| when 'python' | |
| glob('*.py', except: '_test.py') | |
| when 'r' | |
| glob('*.R', except: /test_\S+\.R/) | |
| when 'racket' | |
| glob('*.rkt', except: '-test.rkt') | |
| when 'reasonml' | |
| glob('src', '*.re') | |
| when 'ruby' | |
| glob('*.rb', except: '_test.rb') | |
| when 'rust' | |
| glob('src', '*.rs') | |
| when 'scala' | |
| glob('src', 'main', 'scala', '*.scala') | |
| when 'sml' | |
| glob('*.sml', except: %w(test.sml testlib.sml)) | |
| when 'swift' | |
| glob('Sources', '*.swift') + glob('Sources', ?*, '*.swift') | |
| # At some point (https://github.com/exercism/swift/pull/363) everything got moved into directories: | |
| when 'typescript' | |
| glob('*.ts', except: '.test.ts') | |
| when 'vimscript' | |
| glob('*.vim') | |
| else | |
| puts "unknown track #{track}, maybe you should add it!" | |
| Kernel.exit(1) | |
| end | |
| puts files | |
| puts 'No files to submit, this probably will not work' if files.empty? | |
| system('exercism', 'submit', *files) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment