From 44bca8f8e89578b4e9d6b8070d2675b7159738f8 Mon Sep 17 00:00:00 2001 From: chenhuiz Date: Thu, 14 May 2020 07:44:34 +0300 Subject: [PATCH 01/61] Some tests of CSharpPlugin --- .gitignore | 5 +++ .../cs/tmc/langs/csharp/CSharpPluginTest.java | 39 +++++++++++++++++++ .../test/PassingTest/ProgramTest.cs | 14 +++++++ .../PassingProject/src/Passing/Passing.csproj | 8 ++++ .../PassingProject/src/Passing/Program.cs | 12 ++++++ .../test/PassingTest/PassingTest.csproj | 16 ++++++++ .../test/PassingTest/ProgramTest.cs | 14 +++++++ 7 files changed, 108 insertions(+) create mode 100644 tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java create mode 100644 tmc-langs-csharp/src/test/java/resources/PassingProject/test/PassingTest/ProgramTest.cs create mode 100644 tmc-langs-csharp/src/test/resources/PassingProject/src/Passing/Passing.csproj create mode 100644 tmc-langs-csharp/src/test/resources/PassingProject/src/Passing/Program.cs create mode 100644 tmc-langs-csharp/src/test/resources/PassingProject/test/PassingTest/PassingTest.csproj create mode 100644 tmc-langs-csharp/src/test/resources/PassingProject/test/PassingTest/ProgramTest.cs diff --git a/.gitignore b/.gitignore index 1bd35ec4e..9635affe1 100644 --- a/.gitignore +++ b/.gitignore @@ -54,3 +54,8 @@ __pycache__/ *.pro.user* *.qmlc *.qmake.stash +/tmc-langs-csharp/nbproject/ + +# CSharp +obj/ +bin/ diff --git a/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java b/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java new file mode 100644 index 000000000..b68e09a6f --- /dev/null +++ b/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java @@ -0,0 +1,39 @@ +package fi.helsinki.cs.tmc.langs.csharp; + +import fi.helsinki.cs.tmc.langs.domain.RunResult; +import fi.helsinki.cs.tmc.langs.io.StudentFilePolicy; +import fi.helsinki.cs.tmc.langs.utils.TestUtils; +import java.nio.file.Path; +import java.nio.file.Paths; +import org.junit.Before; +import org.junit.Test; +import static org.junit.Assert.*; + +public class CSharpPluginTest { + + private CSharpPlugin csPlugin; + + @Before + public void setUp() { + this.csPlugin = new CSharpPlugin(); + } + + @Test + public void testGetLanguageName() { + assertEquals("csharp", this.csPlugin.getPluginName()); + } + + @Test + public void getStudentFilePolicyReturnsPython3StudentFilePolicy() { + StudentFilePolicy policy = this.csPlugin.getStudentFilePolicy(Paths.get("")); + + assertTrue(policy instanceof CSharpStudentFilePolicy); + } + + @Test + public void testRunTestsRunsTests() { + Path path = TestUtils.getPath(getClass(), "PassingProject"); + + + } +} diff --git a/tmc-langs-csharp/src/test/java/resources/PassingProject/test/PassingTest/ProgramTest.cs b/tmc-langs-csharp/src/test/java/resources/PassingProject/test/PassingTest/ProgramTest.cs new file mode 100644 index 000000000..f56dfe8d8 --- /dev/null +++ b/tmc-langs-csharp/src/test/java/resources/PassingProject/test/PassingTest/ProgramTest.cs @@ -0,0 +1,14 @@ +using System; +using Xunit; + +namespace PassingTest +{ + public class ProgramTest: IDisposable + { + [Fact] + public void Test1() + { + Assert.Equal("a", "a"); + } + } +} diff --git a/tmc-langs-csharp/src/test/resources/PassingProject/src/Passing/Passing.csproj b/tmc-langs-csharp/src/test/resources/PassingProject/src/Passing/Passing.csproj new file mode 100644 index 000000000..d453e9a07 --- /dev/null +++ b/tmc-langs-csharp/src/test/resources/PassingProject/src/Passing/Passing.csproj @@ -0,0 +1,8 @@ + + + + Exe + netcoreapp3.1 + + + diff --git a/tmc-langs-csharp/src/test/resources/PassingProject/src/Passing/Program.cs b/tmc-langs-csharp/src/test/resources/PassingProject/src/Passing/Program.cs new file mode 100644 index 000000000..bbf4f1b60 --- /dev/null +++ b/tmc-langs-csharp/src/test/resources/PassingProject/src/Passing/Program.cs @@ -0,0 +1,12 @@ +using System; + +namespace Passing +{ + class Program + { + static void Main(string[] args) + { + Console.WriteLine("This is a passed test."); + } + } +} diff --git a/tmc-langs-csharp/src/test/resources/PassingProject/test/PassingTest/PassingTest.csproj b/tmc-langs-csharp/src/test/resources/PassingProject/test/PassingTest/PassingTest.csproj new file mode 100644 index 000000000..6b415753d --- /dev/null +++ b/tmc-langs-csharp/src/test/resources/PassingProject/test/PassingTest/PassingTest.csproj @@ -0,0 +1,16 @@ + + + + netcoreapp3.1 + + false + + + + + + + + + + diff --git a/tmc-langs-csharp/src/test/resources/PassingProject/test/PassingTest/ProgramTest.cs b/tmc-langs-csharp/src/test/resources/PassingProject/test/PassingTest/ProgramTest.cs new file mode 100644 index 000000000..d70784d01 --- /dev/null +++ b/tmc-langs-csharp/src/test/resources/PassingProject/test/PassingTest/ProgramTest.cs @@ -0,0 +1,14 @@ +using System; +using Xunit; + +namespace PassingTest +{ + public class ProgramTest + { + [Fact] + public void Test1() + { + Assert.Equal("a", "a"); + } + } +} From e6ba6e8fcd01781f493ac19766786d1e8f554ddc Mon Sep 17 00:00:00 2001 From: chenhuiz Date: Thu, 14 May 2020 17:59:31 +0300 Subject: [PATCH 02/61] Fixed PassingProject & Added FailingProject --- .gitignore | 3 ++- tmc-langs-csharp/.gitignore | 4 +++- .../cs/tmc/langs/csharp/CSharpPlugin.java | 2 +- .../cs/tmc/langs/csharp/CSharpPluginTest.java | 17 ++++++++++++++-- .../test/PassingTest/ProgramTest.cs | 14 ------------- .../FailingProject/src/Failing/Failing.csproj | 8 ++++++++ .../FailingProject/src/Failing/Program.cs | 12 +++++++++++ .../test/FailingTest/FailingTest.csproj | 20 +++++++++++++++++++ .../test/FailingTest/ProgramTest.cs | 14 +++++++++++++ .../test/PassingTest/PassingTest.csproj | 4 ++++ 10 files changed, 79 insertions(+), 19 deletions(-) delete mode 100644 tmc-langs-csharp/src/test/java/resources/PassingProject/test/PassingTest/ProgramTest.cs create mode 100644 tmc-langs-csharp/src/test/resources/FailingProject/src/Failing/Failing.csproj create mode 100644 tmc-langs-csharp/src/test/resources/FailingProject/src/Failing/Program.cs create mode 100644 tmc-langs-csharp/src/test/resources/FailingProject/test/FailingTest/FailingTest.csproj create mode 100644 tmc-langs-csharp/src/test/resources/FailingProject/test/FailingTest/ProgramTest.cs diff --git a/.gitignore b/.gitignore index 9635affe1..eb8bc896c 100644 --- a/.gitignore +++ b/.gitignore @@ -54,8 +54,9 @@ __pycache__/ *.pro.user* *.qmlc *.qmake.stash -/tmc-langs-csharp/nbproject/ # CSharp obj/ bin/ +/tmc-langs-csharp/nbproject/ + diff --git a/tmc-langs-csharp/.gitignore b/tmc-langs-csharp/.gitignore index 148ca8b3a..13d43b1d6 100644 --- a/tmc-langs-csharp/.gitignore +++ b/tmc-langs-csharp/.gitignore @@ -1 +1,3 @@ -bootstrapPath.txt \ No newline at end of file +bootstrapPath.txt +.tmc_test_results.json +.vscode/ diff --git a/tmc-langs-csharp/src/main/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPlugin.java b/tmc-langs-csharp/src/main/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPlugin.java index 889f61606..4b52df58e 100644 --- a/tmc-langs-csharp/src/main/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPlugin.java +++ b/tmc-langs-csharp/src/main/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPlugin.java @@ -84,7 +84,7 @@ public Optional scanExercise(Path path, String exerciseName) { @Override public RunResult runTests(Path path) { - deleteOldResults(path); +// deleteOldResults(path); ProcessRunner runner = new ProcessRunner(getTestCommand(), path); diff --git a/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java b/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java index b68e09a6f..5cb4e74b4 100644 --- a/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java +++ b/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java @@ -1,6 +1,7 @@ package fi.helsinki.cs.tmc.langs.csharp; import fi.helsinki.cs.tmc.langs.domain.RunResult; +import fi.helsinki.cs.tmc.langs.domain.TestResult; import fi.helsinki.cs.tmc.langs.io.StudentFilePolicy; import fi.helsinki.cs.tmc.langs.utils.TestUtils; import java.nio.file.Path; @@ -31,9 +32,21 @@ public void getStudentFilePolicyReturnsPython3StudentFilePolicy() { } @Test - public void testRunTestsRunsTests() { + public void testRunTestsPassing() { Path path = TestUtils.getPath(getClass(), "PassingProject"); - + RunResult runResult = this.csPlugin.runTests(path); + + assertEquals(RunResult.Status.PASSED, runResult.status); + + } + + @Test + public void testRunTestsFailing() { + Path path = TestUtils.getPath(getClass(), "FailingProject"); + + RunResult runResult = this.csPlugin.runTests(path); + + assertEquals(RunResult.Status.TESTS_FAILED, runResult.status); } } diff --git a/tmc-langs-csharp/src/test/java/resources/PassingProject/test/PassingTest/ProgramTest.cs b/tmc-langs-csharp/src/test/java/resources/PassingProject/test/PassingTest/ProgramTest.cs deleted file mode 100644 index f56dfe8d8..000000000 --- a/tmc-langs-csharp/src/test/java/resources/PassingProject/test/PassingTest/ProgramTest.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using Xunit; - -namespace PassingTest -{ - public class ProgramTest: IDisposable - { - [Fact] - public void Test1() - { - Assert.Equal("a", "a"); - } - } -} diff --git a/tmc-langs-csharp/src/test/resources/FailingProject/src/Failing/Failing.csproj b/tmc-langs-csharp/src/test/resources/FailingProject/src/Failing/Failing.csproj new file mode 100644 index 000000000..d453e9a07 --- /dev/null +++ b/tmc-langs-csharp/src/test/resources/FailingProject/src/Failing/Failing.csproj @@ -0,0 +1,8 @@ + + + + Exe + netcoreapp3.1 + + + diff --git a/tmc-langs-csharp/src/test/resources/FailingProject/src/Failing/Program.cs b/tmc-langs-csharp/src/test/resources/FailingProject/src/Failing/Program.cs new file mode 100644 index 000000000..c01d0faea --- /dev/null +++ b/tmc-langs-csharp/src/test/resources/FailingProject/src/Failing/Program.cs @@ -0,0 +1,12 @@ +using System; + +namespace Failing +{ + class Program + { + static void Main(string[] args) + { + Console.WriteLine("This is a failed test."); + } + } +} diff --git a/tmc-langs-csharp/src/test/resources/FailingProject/test/FailingTest/FailingTest.csproj b/tmc-langs-csharp/src/test/resources/FailingProject/test/FailingTest/FailingTest.csproj new file mode 100644 index 000000000..4fb5841c6 --- /dev/null +++ b/tmc-langs-csharp/src/test/resources/FailingProject/test/FailingTest/FailingTest.csproj @@ -0,0 +1,20 @@ + + + + netcoreapp3.1 + + false + + + + + + + + + + + + + + diff --git a/tmc-langs-csharp/src/test/resources/FailingProject/test/FailingTest/ProgramTest.cs b/tmc-langs-csharp/src/test/resources/FailingProject/test/FailingTest/ProgramTest.cs new file mode 100644 index 000000000..94ef52d32 --- /dev/null +++ b/tmc-langs-csharp/src/test/resources/FailingProject/test/FailingTest/ProgramTest.cs @@ -0,0 +1,14 @@ +using System; +using Xunit; + +namespace FailingTest +{ + public class ProgramTest + { + [Fact] + public void Test1() + { + Assert.Equal("abc", "ab"); + } + } +} diff --git a/tmc-langs-csharp/src/test/resources/PassingProject/test/PassingTest/PassingTest.csproj b/tmc-langs-csharp/src/test/resources/PassingProject/test/PassingTest/PassingTest.csproj index 6b415753d..ddd106c06 100644 --- a/tmc-langs-csharp/src/test/resources/PassingProject/test/PassingTest/PassingTest.csproj +++ b/tmc-langs-csharp/src/test/resources/PassingProject/test/PassingTest/PassingTest.csproj @@ -13,4 +13,8 @@ + + + + From 7adfb77cd6e3afafec19aef31c0de54db22833d4 Mon Sep 17 00:00:00 2001 From: chenhuiz Date: Sat, 16 May 2020 10:53:51 +0300 Subject: [PATCH 03/61] Fixed test projects & set test env --- .../cs/tmc/langs/csharp/CSharpPlugin.java | 20 +++++++++------ .../cs/tmc/langs/csharp/CSharpPluginTest.java | 20 ++++++++------- .../FailingProject/src/Failing/Program.cs | 12 --------- .../FailingSample.csproj} | 0 .../src/FailingSample/Program.cs | 14 +++++++++++ .../FailingSampleTests.csproj} | 5 ++-- .../test/FailingSampleTests/ProgramTest.cs | 18 +++++++++++++ .../test/FailingTest/ProgramTest.cs | 14 ----------- .../PassingProject/src/Passing/Program.cs | 12 --------- .../PassingSample.csproj} | 0 .../src/PassingSample/Program.cs | 17 +++++++++++++ .../PassingSampleTests.csproj} | 5 ++-- .../test/PassingSampleTests/ProgramTest.cs | 25 +++++++++++++++++++ .../test/PassingTest/ProgramTest.cs | 14 ----------- 14 files changed, 104 insertions(+), 72 deletions(-) delete mode 100644 tmc-langs-csharp/src/test/resources/FailingProject/src/Failing/Program.cs rename tmc-langs-csharp/src/test/resources/FailingProject/src/{Failing/Failing.csproj => FailingSample/FailingSample.csproj} (100%) create mode 100644 tmc-langs-csharp/src/test/resources/FailingProject/src/FailingSample/Program.cs rename tmc-langs-csharp/src/test/resources/{PassingProject/test/PassingTest/PassingTest.csproj => FailingProject/test/FailingSampleTests/FailingSampleTests.csproj} (74%) create mode 100644 tmc-langs-csharp/src/test/resources/FailingProject/test/FailingSampleTests/ProgramTest.cs delete mode 100644 tmc-langs-csharp/src/test/resources/FailingProject/test/FailingTest/ProgramTest.cs delete mode 100644 tmc-langs-csharp/src/test/resources/PassingProject/src/Passing/Program.cs rename tmc-langs-csharp/src/test/resources/PassingProject/src/{Passing/Passing.csproj => PassingSample/PassingSample.csproj} (100%) create mode 100644 tmc-langs-csharp/src/test/resources/PassingProject/src/PassingSample/Program.cs rename tmc-langs-csharp/src/test/resources/{FailingProject/test/FailingTest/FailingTest.csproj => PassingProject/test/PassingSampleTests/PassingSampleTests.csproj} (74%) create mode 100644 tmc-langs-csharp/src/test/resources/PassingProject/test/PassingSampleTests/ProgramTest.cs delete mode 100644 tmc-langs-csharp/src/test/resources/PassingProject/test/PassingTest/ProgramTest.cs diff --git a/tmc-langs-csharp/src/main/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPlugin.java b/tmc-langs-csharp/src/main/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPlugin.java index a4eb566d8..b7ce87f08 100644 --- a/tmc-langs-csharp/src/main/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPlugin.java +++ b/tmc-langs-csharp/src/main/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPlugin.java @@ -36,7 +36,6 @@ import java.util.Map; import java.util.Scanner; - public class CSharpPlugin extends AbstractLanguagePlugin { private static final Path SRC_PATH = Paths.get("src"); @@ -44,7 +43,7 @@ public class CSharpPlugin extends AbstractLanguagePlugin { private static final String CANNOT_RUN_TESTS_MESSAGE = "Failed to run tests."; private static final String CANNOT_PARSE_TEST_RESULTS_MESSAGE = "Failed to read test results."; private static final String CANNOT_SCAN_EXERCISE_MESSAGE = "Failed to scan exercise."; - private static final String CANNOT_PARSE_EXERCISE_DESCRIPTION_MESSAGE = + private static final String CANNOT_PARSE_EXERCISE_DESCRIPTION_MESSAGE = "Failed to parse exercise description."; private static final String CANNOT_LOCATE_RUNNER_MESSAGE = "Failed to locate runner."; private static final String CANNOT_PURGE_OLD_RESULTS_MESSAGE = @@ -82,7 +81,7 @@ public Optional scanExercise(Path path, String exerciseName) { try { ProcessResult result = runner.call(); - + if (result.statusCode != 0) { log.error(CANNOT_SCAN_EXERCISE_MESSAGE); return Optional.absent(); @@ -104,13 +103,13 @@ public Optional scanExercise(Path path, String exerciseName) { @Override public RunResult runTests(Path path) { -// deleteOldResults(path); + deleteOldResults(path); ProcessRunner runner = new ProcessRunner(getTestCommand(), path); try { ProcessResult result = runner.call(); - + if (result.statusCode != 0) { log.error(CANNOT_RUN_TESTS_MESSAGE); return null; @@ -169,10 +168,17 @@ private String getBootstrapPath() { if (envVarPath != null) { return envVarPath; } - + + String testEnv = System.getProperty("TEST_ENV"); try { - Scanner in = new Scanner(new FileReader("tmc-langs-csharp/bootstrapPath.txt")); + Scanner in; + if (testEnv == null) { + in = new Scanner(new FileReader("tmc-langs-csharp/bootstrapPath.txt")); + } else { + in = new Scanner(new FileReader("bootstrapPath.txt")); + } return in.nextLine(); + } catch (Exception e) { log.error(CANNOT_LOCATE_RUNNER_MESSAGE, e); return null; diff --git a/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java b/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java index 5cb4e74b4..bc34ff209 100644 --- a/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java +++ b/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java @@ -1,14 +1,17 @@ package fi.helsinki.cs.tmc.langs.csharp; +import static org.junit.Assert.*; + import fi.helsinki.cs.tmc.langs.domain.RunResult; import fi.helsinki.cs.tmc.langs.domain.TestResult; import fi.helsinki.cs.tmc.langs.io.StudentFilePolicy; import fi.helsinki.cs.tmc.langs.utils.TestUtils; -import java.nio.file.Path; -import java.nio.file.Paths; + import org.junit.Before; import org.junit.Test; -import static org.junit.Assert.*; + +import java.nio.file.Path; +import java.nio.file.Paths; public class CSharpPluginTest { @@ -17,6 +20,7 @@ public class CSharpPluginTest { @Before public void setUp() { this.csPlugin = new CSharpPlugin(); + System.setProperty("TEST_ENV", "TEST"); } @Test @@ -34,19 +38,17 @@ public void getStudentFilePolicyReturnsPython3StudentFilePolicy() { @Test public void testRunTestsPassing() { Path path = TestUtils.getPath(getClass(), "PassingProject"); - RunResult runResult = this.csPlugin.runTests(path); - assertEquals(RunResult.Status.PASSED, runResult.status); - + } - + @Test public void testRunTestsFailing() { Path path = TestUtils.getPath(getClass(), "FailingProject"); - + RunResult runResult = this.csPlugin.runTests(path); - + assertEquals(RunResult.Status.TESTS_FAILED, runResult.status); } } diff --git a/tmc-langs-csharp/src/test/resources/FailingProject/src/Failing/Program.cs b/tmc-langs-csharp/src/test/resources/FailingProject/src/Failing/Program.cs deleted file mode 100644 index c01d0faea..000000000 --- a/tmc-langs-csharp/src/test/resources/FailingProject/src/Failing/Program.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; - -namespace Failing -{ - class Program - { - static void Main(string[] args) - { - Console.WriteLine("This is a failed test."); - } - } -} diff --git a/tmc-langs-csharp/src/test/resources/FailingProject/src/Failing/Failing.csproj b/tmc-langs-csharp/src/test/resources/FailingProject/src/FailingSample/FailingSample.csproj similarity index 100% rename from tmc-langs-csharp/src/test/resources/FailingProject/src/Failing/Failing.csproj rename to tmc-langs-csharp/src/test/resources/FailingProject/src/FailingSample/FailingSample.csproj diff --git a/tmc-langs-csharp/src/test/resources/FailingProject/src/FailingSample/Program.cs b/tmc-langs-csharp/src/test/resources/FailingProject/src/FailingSample/Program.cs new file mode 100644 index 000000000..69b07f331 --- /dev/null +++ b/tmc-langs-csharp/src/test/resources/FailingProject/src/FailingSample/Program.cs @@ -0,0 +1,14 @@ +using System; + +namespace FailingSample +{ + public class Program + { + + public static bool CheckSame => true; + public static void Main(string[] args) + { + Console.WriteLine("This is a failed test."); + } + } +} diff --git a/tmc-langs-csharp/src/test/resources/PassingProject/test/PassingTest/PassingTest.csproj b/tmc-langs-csharp/src/test/resources/FailingProject/test/FailingSampleTests/FailingSampleTests.csproj similarity index 74% rename from tmc-langs-csharp/src/test/resources/PassingProject/test/PassingTest/PassingTest.csproj rename to tmc-langs-csharp/src/test/resources/FailingProject/test/FailingSampleTests/FailingSampleTests.csproj index ddd106c06..25355f0e5 100644 --- a/tmc-langs-csharp/src/test/resources/PassingProject/test/PassingTest/PassingTest.csproj +++ b/tmc-langs-csharp/src/test/resources/FailingProject/test/FailingSampleTests/FailingSampleTests.csproj @@ -11,10 +11,11 @@ + - - + + diff --git a/tmc-langs-csharp/src/test/resources/FailingProject/test/FailingSampleTests/ProgramTest.cs b/tmc-langs-csharp/src/test/resources/FailingProject/test/FailingSampleTests/ProgramTest.cs new file mode 100644 index 000000000..6aac930fb --- /dev/null +++ b/tmc-langs-csharp/src/test/resources/FailingProject/test/FailingSampleTests/ProgramTest.cs @@ -0,0 +1,18 @@ +using System; +using Xunit; +using FailingSample; +using TestMyCode.CSharp.API.Attributes; + +namespace FailingSampleTests +{ + [Points("2")] + public class ProgramTest + { + [Fact] + [Points("2.1")] + public void TestCheckSameFailed() + { + Assert.False(Program.CheckSame); + } + } +} diff --git a/tmc-langs-csharp/src/test/resources/FailingProject/test/FailingTest/ProgramTest.cs b/tmc-langs-csharp/src/test/resources/FailingProject/test/FailingTest/ProgramTest.cs deleted file mode 100644 index 94ef52d32..000000000 --- a/tmc-langs-csharp/src/test/resources/FailingProject/test/FailingTest/ProgramTest.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using Xunit; - -namespace FailingTest -{ - public class ProgramTest - { - [Fact] - public void Test1() - { - Assert.Equal("abc", "ab"); - } - } -} diff --git a/tmc-langs-csharp/src/test/resources/PassingProject/src/Passing/Program.cs b/tmc-langs-csharp/src/test/resources/PassingProject/src/Passing/Program.cs deleted file mode 100644 index bbf4f1b60..000000000 --- a/tmc-langs-csharp/src/test/resources/PassingProject/src/Passing/Program.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; - -namespace Passing -{ - class Program - { - static void Main(string[] args) - { - Console.WriteLine("This is a passed test."); - } - } -} diff --git a/tmc-langs-csharp/src/test/resources/PassingProject/src/Passing/Passing.csproj b/tmc-langs-csharp/src/test/resources/PassingProject/src/PassingSample/PassingSample.csproj similarity index 100% rename from tmc-langs-csharp/src/test/resources/PassingProject/src/Passing/Passing.csproj rename to tmc-langs-csharp/src/test/resources/PassingProject/src/PassingSample/PassingSample.csproj diff --git a/tmc-langs-csharp/src/test/resources/PassingProject/src/PassingSample/Program.cs b/tmc-langs-csharp/src/test/resources/PassingProject/src/PassingSample/Program.cs new file mode 100644 index 000000000..e36b07285 --- /dev/null +++ b/tmc-langs-csharp/src/test/resources/PassingProject/src/PassingSample/Program.cs @@ -0,0 +1,17 @@ +using System; + +namespace PassingSample +{ + public class Program + { + + public static string GetName(string name) => name; + + public static int GetYear(int year) => year; + + public static void Main(string[] args) + { + Console.WriteLine("This is a passing test."); + } + } +} diff --git a/tmc-langs-csharp/src/test/resources/FailingProject/test/FailingTest/FailingTest.csproj b/tmc-langs-csharp/src/test/resources/PassingProject/test/PassingSampleTests/PassingSampleTests.csproj similarity index 74% rename from tmc-langs-csharp/src/test/resources/FailingProject/test/FailingTest/FailingTest.csproj rename to tmc-langs-csharp/src/test/resources/PassingProject/test/PassingSampleTests/PassingSampleTests.csproj index 4fb5841c6..71eec4288 100644 --- a/tmc-langs-csharp/src/test/resources/FailingProject/test/FailingTest/FailingTest.csproj +++ b/tmc-langs-csharp/src/test/resources/PassingProject/test/PassingSampleTests/PassingSampleTests.csproj @@ -11,10 +11,11 @@ + - - + + diff --git a/tmc-langs-csharp/src/test/resources/PassingProject/test/PassingSampleTests/ProgramTest.cs b/tmc-langs-csharp/src/test/resources/PassingProject/test/PassingSampleTests/ProgramTest.cs new file mode 100644 index 000000000..0ffc1c399 --- /dev/null +++ b/tmc-langs-csharp/src/test/resources/PassingProject/test/PassingSampleTests/ProgramTest.cs @@ -0,0 +1,25 @@ +using System; +using Xunit; +using PassingSample; +using TestMyCode.CSharp.API.Attributes; + +namespace PassingSampleTests +{ + [Points("1")] + public class ProgramTest + { + [Fact] + [Points("1.1")] + public void TestGetName() + { + Assert.Equal("Clare", Program.GetName("Clare")); + } + + [Fact] + [Points("1.2")] + public void TestGetYear() + { + Assert.Equal(1900, Program.GetYear(1900)); + } + } +} diff --git a/tmc-langs-csharp/src/test/resources/PassingProject/test/PassingTest/ProgramTest.cs b/tmc-langs-csharp/src/test/resources/PassingProject/test/PassingTest/ProgramTest.cs deleted file mode 100644 index d70784d01..000000000 --- a/tmc-langs-csharp/src/test/resources/PassingProject/test/PassingTest/ProgramTest.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using Xunit; - -namespace PassingTest -{ - public class ProgramTest - { - [Fact] - public void Test1() - { - Assert.Equal("a", "a"); - } - } -} From 767134a6fdb210b105a8b4d2f40a20fce1118e59 Mon Sep 17 00:00:00 2001 From: chenhuiz Date: Sat, 16 May 2020 11:39:11 +0300 Subject: [PATCH 04/61] Configured checkstyle in the tests --- .../fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java b/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java index bc34ff209..98138cd8e 100644 --- a/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java +++ b/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java @@ -1,6 +1,7 @@ package fi.helsinki.cs.tmc.langs.csharp; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import fi.helsinki.cs.tmc.langs.domain.RunResult; import fi.helsinki.cs.tmc.langs.domain.TestResult; @@ -46,9 +47,7 @@ public void testRunTestsPassing() { @Test public void testRunTestsFailing() { Path path = TestUtils.getPath(getClass(), "FailingProject"); - RunResult runResult = this.csPlugin.runTests(path); - assertEquals(RunResult.Status.TESTS_FAILED, runResult.status); } } From ed73554c10b2eb5a993f20bd1dcddc0ccdce3e64 Mon Sep 17 00:00:00 2001 From: chenhuiz Date: Mon, 18 May 2020 17:30:41 +0300 Subject: [PATCH 05/61] more tests --- .../cs/tmc/langs/csharp/CSharpPluginTest.java | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java b/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java index 98138cd8e..559184ae2 100644 --- a/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java +++ b/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java @@ -3,6 +3,9 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; +import fi.helsinki.cs.tmc.langs.abstraction.Strategy; +import fi.helsinki.cs.tmc.langs.abstraction.ValidationResult; +import fi.helsinki.cs.tmc.langs.domain.ExerciseDesc; import fi.helsinki.cs.tmc.langs.domain.RunResult; import fi.helsinki.cs.tmc.langs.domain.TestResult; import fi.helsinki.cs.tmc.langs.io.StudentFilePolicy; @@ -13,6 +16,7 @@ import java.nio.file.Path; import java.nio.file.Paths; +import java.util.Locale; public class CSharpPluginTest { @@ -42,6 +46,14 @@ public void testRunTestsPassing() { RunResult runResult = this.csPlugin.runTests(path); assertEquals(RunResult.Status.PASSED, runResult.status); + TestResult testResult = runResult.testResults.get(0); + assertTrue(testResult.isSuccessful()); + assertEquals("PassingSampleTests.ProgramTest.TestGetYear", testResult.getName()); + assertEquals(2, testResult.points.size()); + assertTrue(testResult.points.contains("1")); + assertTrue(testResult.points.contains("1.2")); + assertEquals("", testResult.getMessage()); + assertEquals(0, testResult.getException().size()); } @Test @@ -49,5 +61,27 @@ public void testRunTestsFailing() { Path path = TestUtils.getPath(getClass(), "FailingProject"); RunResult runResult = this.csPlugin.runTests(path); assertEquals(RunResult.Status.TESTS_FAILED, runResult.status); + + TestResult testResult = runResult.testResults.get(0); + assertTrue(!testResult.isSuccessful()); + assertTrue(!testResult.getMessage().isEmpty()); + assertEquals(0, testResult.points.size()); + assertEquals(3, testResult.getException().size()); + } + + @Test + public void testScanExercise() { + Path path = TestUtils.getPath(getClass(), "PassingProject"); + ExerciseDesc testDesc = this.csPlugin.scanExercise(path, "cs-tests").get(); + assertEquals("cs-tests", testDesc.name); + assertEquals("PassingSampleTests.ProgramTest.TestGetName", testDesc.tests.get(0).name); + assertEquals(2, testDesc.tests.get(0).points.size()); + } + + @Test() + public void checkCodeStyleReturnsEmptyResult() { + Path path = TestUtils.getPath(getClass(), "PassingProject"); + ValidationResult result = this.csPlugin.checkCodeStyle(path, new Locale("en")); + assertTrue(result.getStrategy() == Strategy.DISABLED); } } From c22c8b2a1e3b17c8d78a007d9acf13aeb3fbc04e Mon Sep 17 00:00:00 2001 From: chenhuiz Date: Tue, 19 May 2020 16:10:04 +0300 Subject: [PATCH 06/61] tests for CSharpStudentFilePolicy --- .../cs/tmc/langs/csharp/CSharpPluginTest.java | 3 +- .../csharp/CSharpStudentFilePolicyTest.java | 53 +++++++++++++++++++ .../src/PolicySample/PolicySample.csproj | 8 +++ .../PolicyProject/src/PolicySample/Program.cs | 12 +++++ .../PolicySampleTests/PolicySamplTests.csproj | 21 ++++++++ .../test/PolicySampleTests/ProgramTest.cs | 17 ++++++ 6 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpStudentFilePolicyTest.java create mode 100644 tmc-langs-csharp/src/test/resources/PolicyProject/src/PolicySample/PolicySample.csproj create mode 100644 tmc-langs-csharp/src/test/resources/PolicyProject/src/PolicySample/Program.cs create mode 100644 tmc-langs-csharp/src/test/resources/PolicyProject/test/PolicySampleTests/PolicySamplTests.csproj create mode 100644 tmc-langs-csharp/src/test/resources/PolicyProject/test/PolicySampleTests/ProgramTest.cs diff --git a/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java b/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java index 559184ae2..4a220e7ac 100644 --- a/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java +++ b/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java @@ -79,9 +79,10 @@ public void testScanExercise() { } @Test() - public void checkCodeStyleReturnsEmptyResult() { + public void testCheckCodeStyleStratery() { Path path = TestUtils.getPath(getClass(), "PassingProject"); ValidationResult result = this.csPlugin.checkCodeStyle(path, new Locale("en")); assertTrue(result.getStrategy() == Strategy.DISABLED); } + } diff --git a/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpStudentFilePolicyTest.java b/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpStudentFilePolicyTest.java new file mode 100644 index 000000000..3ad8b4979 --- /dev/null +++ b/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpStudentFilePolicyTest.java @@ -0,0 +1,53 @@ +package fi.helsinki.cs.tmc.langs.csharp; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import fi.helsinki.cs.tmc.langs.utils.TestUtils; + +import org.junit.Before; +import org.junit.Test; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.List; + +public class CSharpStudentFilePolicyTest { + + private Path projectPath; + private CSharpStudentFilePolicy policy; + + @Before + public void setUp() { + this.projectPath = TestUtils.getPath(getClass(), "PolicyProject"); + this.policy = new CSharpStudentFilePolicy(projectPath); + } + + @Test + public void testFilesInSrcDirectoryAreStudentFiles() throws IOException { + final List studentFiles = new ArrayList<>(); + TestUtils.collectPaths(projectPath, studentFiles, policy); + + assertEquals(23, studentFiles.size()); + assertTrue(studentFiles.contains("src" + File.separator + "PolicySample" + + File.separator + "Program.cs")); + assertTrue(studentFiles.contains("src" + File.separator + "PolicySample" + + File.separator + "PolicySample.csproj")); + } + + @Test + public void testFilesInTestDirectoryAreNotStudentFiles() throws IOException { + final List studentFiles = new ArrayList<>(); + TestUtils.collectPaths(projectPath, studentFiles, policy); + + assertEquals(23, studentFiles.size()); + assertFalse(studentFiles.contains("test" + File.separator + "PolicySampleTests" + + File.separator + "PrgramTest.cs")); + assertFalse(studentFiles.contains("test" + File.separator + "PolicySampleTests" + + File.separator + "PolicySampleTests.csproj")); + + } +} diff --git a/tmc-langs-csharp/src/test/resources/PolicyProject/src/PolicySample/PolicySample.csproj b/tmc-langs-csharp/src/test/resources/PolicyProject/src/PolicySample/PolicySample.csproj new file mode 100644 index 000000000..d453e9a07 --- /dev/null +++ b/tmc-langs-csharp/src/test/resources/PolicyProject/src/PolicySample/PolicySample.csproj @@ -0,0 +1,8 @@ + + + + Exe + netcoreapp3.1 + + + diff --git a/tmc-langs-csharp/src/test/resources/PolicyProject/src/PolicySample/Program.cs b/tmc-langs-csharp/src/test/resources/PolicyProject/src/PolicySample/Program.cs new file mode 100644 index 000000000..d38e52aa3 --- /dev/null +++ b/tmc-langs-csharp/src/test/resources/PolicyProject/src/PolicySample/Program.cs @@ -0,0 +1,12 @@ +using System; + +namespace PolicySample +{ + class Program + { + static void Main(string[] args) + { + Console.WriteLine("Hello Policy"); + } + } +} diff --git a/tmc-langs-csharp/src/test/resources/PolicyProject/test/PolicySampleTests/PolicySamplTests.csproj b/tmc-langs-csharp/src/test/resources/PolicyProject/test/PolicySampleTests/PolicySamplTests.csproj new file mode 100644 index 000000000..a584472f2 --- /dev/null +++ b/tmc-langs-csharp/src/test/resources/PolicyProject/test/PolicySampleTests/PolicySamplTests.csproj @@ -0,0 +1,21 @@ + + + + netcoreapp3.1 + + false + + + + + + + + + + + + + + + diff --git a/tmc-langs-csharp/src/test/resources/PolicyProject/test/PolicySampleTests/ProgramTest.cs b/tmc-langs-csharp/src/test/resources/PolicyProject/test/PolicySampleTests/ProgramTest.cs new file mode 100644 index 000000000..11bec34f9 --- /dev/null +++ b/tmc-langs-csharp/src/test/resources/PolicyProject/test/PolicySampleTests/ProgramTest.cs @@ -0,0 +1,17 @@ +using System; +using Xunit; +using TestMyCode.CSharp.API.Attributes; + +namespace PolicySamplTests +{ + [Points("3")] + public class ProgramTest + { + [Fact] + [Points("3.1")] + public void Test1() + { + Assert.True("abc".Equals("abc")); + } + } +} From f1afe5b53a18ead94ff772b680b68ce5abd14df3 Mon Sep 17 00:00:00 2001 From: PPeltola Date: Tue, 19 May 2020 16:10:17 +0300 Subject: [PATCH 07/61] tried to make travis download csharp-runner to run the tests --- .travis.yml | 3 +++ .../java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 8613c5b2d..38ed07ca2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -28,6 +28,9 @@ before_install: - sudo chmod 277 /usr/local/lib/R/site-library - Rscript -e 'install.packages(c("devtools","testthat"),repos="http://cran.us.r-project.org")' - Rscript -e 'devtools::install_github("RTMC/tmc-r-tester/tmcRtestrunner")' + - wget https://github.com/TMC-C/tmc-csharp-runner/releases/download/v1.0.0/tmc-csharp-runner.tar.gz -O /tmp/tmc-csharp-runner.tar.gz + - tar -xvf /tmp/tmc-csharp-runner.tar.gz + - export TMC_CSHARP_BOOTSTRAP_PATH=/tmp/publish/Bootstrap.dll - export PATH=$PATH:$PWD/bin - source /opt/qt59/bin/qt59-env.sh - export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$PWD/lib diff --git a/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java b/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java index 559184ae2..8628b37bf 100644 --- a/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java +++ b/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java @@ -34,7 +34,7 @@ public void testGetLanguageName() { } @Test - public void getStudentFilePolicyReturnsPython3StudentFilePolicy() { + public void getStudentFilePolicyReturnsCSharpStudentFilePolicy() { StudentFilePolicy policy = this.csPlugin.getStudentFilePolicy(Paths.get("")); assertTrue(policy instanceof CSharpStudentFilePolicy); From 6f8ac85a685971e74a7b475ed221026c13304d49 Mon Sep 17 00:00:00 2001 From: PPeltola Date: Tue, 19 May 2020 16:58:39 +0300 Subject: [PATCH 08/61] fixed tests (i hope) --- .../cs/tmc/langs/csharp/CSharpStudentFilePolicyTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpStudentFilePolicyTest.java b/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpStudentFilePolicyTest.java index 3ad8b4979..c2c358d2e 100644 --- a/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpStudentFilePolicyTest.java +++ b/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpStudentFilePolicyTest.java @@ -31,7 +31,7 @@ public void testFilesInSrcDirectoryAreStudentFiles() throws IOException { final List studentFiles = new ArrayList<>(); TestUtils.collectPaths(projectPath, studentFiles, policy); - assertEquals(23, studentFiles.size()); + assertEquals(2, studentFiles.size()); assertTrue(studentFiles.contains("src" + File.separator + "PolicySample" + File.separator + "Program.cs")); assertTrue(studentFiles.contains("src" + File.separator + "PolicySample" + @@ -43,7 +43,7 @@ public void testFilesInTestDirectoryAreNotStudentFiles() throws IOException { final List studentFiles = new ArrayList<>(); TestUtils.collectPaths(projectPath, studentFiles, policy); - assertEquals(23, studentFiles.size()); + assertEquals(2, studentFiles.size()); assertFalse(studentFiles.contains("test" + File.separator + "PolicySampleTests" + File.separator + "PrgramTest.cs")); assertFalse(studentFiles.contains("test" + File.separator + "PolicySampleTests" + From d802d068180bdbc14988cd51475dc1d9d3fc35c8 Mon Sep 17 00:00:00 2001 From: PPeltola Date: Wed, 20 May 2020 13:21:08 +0300 Subject: [PATCH 09/61] tried to make travis install dotnet --- .travis.yml | 2 + tmc-langs-csharp/dotnet-install.sh | 1093 +++++++++++++++++ .../cs/tmc/langs/csharp/CSharpPluginTest.java | 4 + 3 files changed, 1099 insertions(+) create mode 100755 tmc-langs-csharp/dotnet-install.sh diff --git a/.travis.yml b/.travis.yml index 38ed07ca2..53c3aabd2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -28,6 +28,8 @@ before_install: - sudo chmod 277 /usr/local/lib/R/site-library - Rscript -e 'install.packages(c("devtools","testthat"),repos="http://cran.us.r-project.org")' - Rscript -e 'devtools::install_github("RTMC/tmc-r-tester/tmcRtestrunner")' + - chmod +x tmc-langs-csharp/dotnet-install.sh + - ./tmc-langs-csharp/dotnet-install.sh - wget https://github.com/TMC-C/tmc-csharp-runner/releases/download/v1.0.0/tmc-csharp-runner.tar.gz -O /tmp/tmc-csharp-runner.tar.gz - tar -xvf /tmp/tmc-csharp-runner.tar.gz - export TMC_CSHARP_BOOTSTRAP_PATH=/tmp/publish/Bootstrap.dll diff --git a/tmc-langs-csharp/dotnet-install.sh b/tmc-langs-csharp/dotnet-install.sh new file mode 100755 index 000000000..0c20299a5 --- /dev/null +++ b/tmc-langs-csharp/dotnet-install.sh @@ -0,0 +1,1093 @@ +#!/usr/bin/env bash +# Copyright (c) .NET Foundation and contributors. All rights reserved. +# Licensed under the MIT license. See LICENSE file in the project root for full license information. +# + +# Stop script on NZEC +set -e +# Stop script if unbound variable found (use ${var:-} if intentional) +set -u +# By default cmd1 | cmd2 returns exit code of cmd2 regardless of cmd1 success +# This is causing it to fail +set -o pipefail + +# Use in the the functions: eval $invocation +invocation='say_verbose "Calling: ${yellow:-}${FUNCNAME[0]} ${green:-}$*${normal:-}"' + +# standard output may be used as a return value in the functions +# we need a way to write text on the screen in the functions so that +# it won't interfere with the return value. +# Exposing stream 3 as a pipe to standard output of the script itself +exec 3>&1 + +# Setup some colors to use. These need to work in fairly limited shells, like the Ubuntu Docker container where there are only 8 colors. +# See if stdout is a terminal +if [ -t 1 ] && command -v tput > /dev/null; then + # see if it supports colors + ncolors=$(tput colors) + if [ -n "$ncolors" ] && [ $ncolors -ge 8 ]; then + bold="$(tput bold || echo)" + normal="$(tput sgr0 || echo)" + black="$(tput setaf 0 || echo)" + red="$(tput setaf 1 || echo)" + green="$(tput setaf 2 || echo)" + yellow="$(tput setaf 3 || echo)" + blue="$(tput setaf 4 || echo)" + magenta="$(tput setaf 5 || echo)" + cyan="$(tput setaf 6 || echo)" + white="$(tput setaf 7 || echo)" + fi +fi + +say_warning() { + printf "%b\n" "${yellow:-}dotnet_install: Warning: $1${normal:-}" +} + +say_err() { + printf "%b\n" "${red:-}dotnet_install: Error: $1${normal:-}" >&2 +} + +say() { + # using stream 3 (defined in the beginning) to not interfere with stdout of functions + # which may be used as return value + printf "%b\n" "${cyan:-}dotnet-install:${normal:-} $1" >&3 +} + +say_verbose() { + if [ "$verbose" = true ]; then + say "$1" + fi +} + +# This platform list is finite - if the SDK/Runtime has supported Linux distribution-specific assets, +# then and only then should the Linux distribution appear in this list. +# Adding a Linux distribution to this list does not imply distribution-specific support. +get_legacy_os_name_from_platform() { + eval $invocation + + platform="$1" + case "$platform" in + "centos.7") + echo "centos" + return 0 + ;; + "debian.8") + echo "debian" + return 0 + ;; + "debian.9") + echo "debian.9" + return 0 + ;; + "fedora.23") + echo "fedora.23" + return 0 + ;; + "fedora.24") + echo "fedora.24" + return 0 + ;; + "fedora.27") + echo "fedora.27" + return 0 + ;; + "fedora.28") + echo "fedora.28" + return 0 + ;; + "opensuse.13.2") + echo "opensuse.13.2" + return 0 + ;; + "opensuse.42.1") + echo "opensuse.42.1" + return 0 + ;; + "opensuse.42.3") + echo "opensuse.42.3" + return 0 + ;; + "rhel.7"*) + echo "rhel" + return 0 + ;; + "ubuntu.14.04") + echo "ubuntu" + return 0 + ;; + "ubuntu.16.04") + echo "ubuntu.16.04" + return 0 + ;; + "ubuntu.16.10") + echo "ubuntu.16.10" + return 0 + ;; + "ubuntu.18.04") + echo "ubuntu.18.04" + return 0 + ;; + "alpine.3.4.3") + echo "alpine" + return 0 + ;; + esac + return 1 +} + +get_linux_platform_name() { + eval $invocation + + if [ -n "$runtime_id" ]; then + echo "${runtime_id%-*}" + return 0 + else + if [ -e /etc/os-release ]; then + . /etc/os-release + echo "$ID${VERSION_ID:+.${VERSION_ID}}" + return 0 + elif [ -e /etc/redhat-release ]; then + local redhatRelease=$(&1 || true) | grep -q musl +} + +get_current_os_name() { + eval $invocation + + local uname=$(uname) + if [ "$uname" = "Darwin" ]; then + echo "osx" + return 0 + elif [ "$uname" = "FreeBSD" ]; then + echo "freebsd" + return 0 + elif [ "$uname" = "Linux" ]; then + local linux_platform_name + linux_platform_name="$(get_linux_platform_name)" || { echo "linux" && return 0 ; } + + if [ "$linux_platform_name" = "rhel.6" ]; then + echo $linux_platform_name + return 0 + elif is_musl_based_distro; then + echo "linux-musl" + return 0 + else + echo "linux" + return 0 + fi + fi + + say_err "OS name could not be detected: UName = $uname" + return 1 +} + +get_legacy_os_name() { + eval $invocation + + local uname=$(uname) + if [ "$uname" = "Darwin" ]; then + echo "osx" + return 0 + elif [ -n "$runtime_id" ]; then + echo $(get_legacy_os_name_from_platform "${runtime_id%-*}" || echo "${runtime_id%-*}") + return 0 + else + if [ -e /etc/os-release ]; then + . /etc/os-release + os=$(get_legacy_os_name_from_platform "$ID${VERSION_ID:+.${VERSION_ID}}" || echo "") + if [ -n "$os" ]; then + echo "$os" + return 0 + fi + fi + fi + + say_verbose "Distribution specific OS name and version could not be detected: UName = $uname" + return 1 +} + +machine_has() { + eval $invocation + + hash "$1" > /dev/null 2>&1 + return $? +} + + +check_min_reqs() { + local hasMinimum=false + if machine_has "curl"; then + hasMinimum=true + elif machine_has "wget"; then + hasMinimum=true + fi + + if [ "$hasMinimum" = "false" ]; then + say_err "curl (recommended) or wget are required to download dotnet. Install missing prerequisite to proceed." + return 1 + fi + return 0 +} + +check_pre_reqs() { + eval $invocation + + if [ "${DOTNET_INSTALL_SKIP_PREREQS:-}" = "1" ]; then + return 0 + fi + + if [ "$(uname)" = "Linux" ]; then + if is_musl_based_distro; then + if ! command -v scanelf > /dev/null; then + say_warning "scanelf not found, please install pax-utils package." + return 0 + fi + LDCONFIG_COMMAND="scanelf --ldpath -BF '%f'" + [ -z "$($LDCONFIG_COMMAND 2>/dev/null | grep libintl)" ] && say_warning "Unable to locate libintl. Probable prerequisite missing; install libintl (or gettext)." + else + if [ ! -x "$(command -v ldconfig)" ]; then + say_verbose "ldconfig is not in PATH, trying /sbin/ldconfig." + LDCONFIG_COMMAND="/sbin/ldconfig" + else + LDCONFIG_COMMAND="ldconfig" + fi + local librarypath=${LD_LIBRARY_PATH:-} + LDCONFIG_COMMAND="$LDCONFIG_COMMAND -NXv ${librarypath//:/ }" + fi + + [ -z "$($LDCONFIG_COMMAND 2>/dev/null | grep zlib)" ] && say_warning "Unable to locate zlib. Probable prerequisite missing; install zlib." + [ -z "$($LDCONFIG_COMMAND 2>/dev/null | grep ssl)" ] && say_warning "Unable to locate libssl. Probable prerequisite missing; install libssl." + [ -z "$($LDCONFIG_COMMAND 2>/dev/null | grep libicu)" ] && say_warning "Unable to locate libicu. Probable prerequisite missing; install libicu." + [ -z "$($LDCONFIG_COMMAND 2>/dev/null | grep lttng)" ] && say_warning "Unable to locate liblttng. Probable prerequisite missing; install libcurl." + [ -z "$($LDCONFIG_COMMAND 2>/dev/null | grep libcurl)" ] && say_warning "Unable to locate libcurl. Probable prerequisite missing; install libcurl." + fi + + return 0 +} + +# args: +# input - $1 +to_lowercase() { + #eval $invocation + + echo "$1" | tr '[:upper:]' '[:lower:]' + return 0 +} + +# args: +# input - $1 +remove_trailing_slash() { + #eval $invocation + + local input="${1:-}" + echo "${input%/}" + return 0 +} + +# args: +# input - $1 +remove_beginning_slash() { + #eval $invocation + + local input="${1:-}" + echo "${input#/}" + return 0 +} + +# args: +# root_path - $1 +# child_path - $2 - this parameter can be empty +combine_paths() { + eval $invocation + + # TODO: Consider making it work with any number of paths. For now: + if [ ! -z "${3:-}" ]; then + say_err "combine_paths: Function takes two parameters." + return 1 + fi + + local root_path="$(remove_trailing_slash "$1")" + local child_path="$(remove_beginning_slash "${2:-}")" + say_verbose "combine_paths: root_path=$root_path" + say_verbose "combine_paths: child_path=$child_path" + echo "$root_path/$child_path" + return 0 +} + +get_machine_architecture() { + eval $invocation + + if command -v uname > /dev/null; then + CPUName=$(uname -m) + case $CPUName in + armv7l) + echo "arm" + return 0 + ;; + aarch64) + echo "arm64" + return 0 + ;; + esac + fi + + # Always default to 'x64' + echo "x64" + return 0 +} + +# args: +# architecture - $1 +get_normalized_architecture_from_architecture() { + eval $invocation + + local architecture="$(to_lowercase "$1")" + case "$architecture" in + \) + echo "$(get_normalized_architecture_from_architecture "$(get_machine_architecture)")" + return 0 + ;; + amd64|x64) + echo "x64" + return 0 + ;; + arm) + echo "arm" + return 0 + ;; + arm64) + echo "arm64" + return 0 + ;; + esac + + say_err "Architecture \`$architecture\` not supported. If you think this is a bug, report it at https://github.com/dotnet/sdk/issues" + return 1 +} + +# The version text returned from the feeds is a 1-line or 2-line string: +# For the SDK and the dotnet runtime (2 lines): +# Line 1: # commit_hash +# Line 2: # 4-part version +# For the aspnetcore runtime (1 line): +# Line 1: # 4-part version + +# args: +# version_text - stdin +get_version_from_version_info() { + eval $invocation + + cat | tail -n 1 | sed 's/\r$//' + return 0 +} + +# args: +# install_root - $1 +# relative_path_to_package - $2 +# specific_version - $3 +is_dotnet_package_installed() { + eval $invocation + + local install_root="$1" + local relative_path_to_package="$2" + local specific_version="${3//[$'\t\r\n']}" + + local dotnet_package_path="$(combine_paths "$(combine_paths "$install_root" "$relative_path_to_package")" "$specific_version")" + say_verbose "is_dotnet_package_installed: dotnet_package_path=$dotnet_package_path" + + if [ -d "$dotnet_package_path" ]; then + return 0 + else + return 1 + fi +} + +# args: +# azure_feed - $1 +# channel - $2 +# normalized_architecture - $3 +# coherent - $4 +get_latest_version_info() { + eval $invocation + + local azure_feed="$1" + local channel="$2" + local normalized_architecture="$3" + local coherent="$4" + + local version_file_url=null + if [[ "$runtime" == "dotnet" ]]; then + version_file_url="$uncached_feed/Runtime/$channel/latest.version" + elif [[ "$runtime" == "aspnetcore" ]]; then + version_file_url="$uncached_feed/aspnetcore/Runtime/$channel/latest.version" + elif [ -z "$runtime" ]; then + if [ "$coherent" = true ]; then + version_file_url="$uncached_feed/Sdk/$channel/latest.coherent.version" + else + version_file_url="$uncached_feed/Sdk/$channel/latest.version" + fi + else + say_err "Invalid value for \$runtime" + return 1 + fi + say_verbose "get_latest_version_info: latest url: $version_file_url" + + download "$version_file_url" + return $? +} + +# args: +# json_file - $1 +parse_jsonfile_for_version() { + eval $invocation + + local json_file="$1" + if [ ! -f "$json_file" ]; then + say_err "Unable to find \`$json_file\`" + return 1 + fi + + sdk_section=$(cat $json_file | awk '/"sdk"/,/}/') + if [ -z "$sdk_section" ]; then + say_err "Unable to parse the SDK node in \`$json_file\`" + return 1 + fi + + sdk_list=$(echo $sdk_section | awk -F"[{}]" '{print $2}') + sdk_list=${sdk_list//[\" ]/} + sdk_list=${sdk_list//,/$'\n'} + sdk_list="$(echo -e "${sdk_list}" | tr -d '[[:space:]]')" + + local version_info="" + while read -r line; do + IFS=: + while read -r key value; do + if [[ "$key" == "version" ]]; then + version_info=$value + fi + done <<< "$line" + done <<< "$sdk_list" + if [ -z "$version_info" ]; then + say_err "Unable to find the SDK:version node in \`$json_file\`" + return 1 + fi + + unset IFS; + echo "$version_info" + return 0 +} + +# args: +# azure_feed - $1 +# channel - $2 +# normalized_architecture - $3 +# version - $4 +# json_file - $5 +get_specific_version_from_version() { + eval $invocation + + local azure_feed="$1" + local channel="$2" + local normalized_architecture="$3" + local version="$(to_lowercase "$4")" + local json_file="$5" + + if [ -z "$json_file" ]; then + case "$version" in + latest) + local version_info + version_info="$(get_latest_version_info "$azure_feed" "$channel" "$normalized_architecture" false)" || return 1 + say_verbose "get_specific_version_from_version: version_info=$version_info" + echo "$version_info" | get_version_from_version_info + return 0 + ;; + coherent) + local version_info + version_info="$(get_latest_version_info "$azure_feed" "$channel" "$normalized_architecture" true)" || return 1 + say_verbose "get_specific_version_from_version: version_info=$version_info" + echo "$version_info" | get_version_from_version_info + return 0 + ;; + *) + echo "$version" + return 0 + ;; + esac + else + local version_info + version_info="$(parse_jsonfile_for_version "$json_file")" || return 1 + echo "$version_info" + return 0 + fi +} + +# args: +# azure_feed - $1 +# channel - $2 +# normalized_architecture - $3 +# specific_version - $4 +construct_download_link() { + eval $invocation + + local azure_feed="$1" + local channel="$2" + local normalized_architecture="$3" + local specific_version="${4//[$'\t\r\n']}" + + local osname + osname="$(get_current_os_name)" || return 1 + + local download_link=null + if [[ "$runtime" == "dotnet" ]]; then + download_link="$azure_feed/Runtime/$specific_version/dotnet-runtime-$specific_version-$osname-$normalized_architecture.tar.gz" + elif [[ "$runtime" == "aspnetcore" ]]; then + download_link="$azure_feed/aspnetcore/Runtime/$specific_version/aspnetcore-runtime-$specific_version-$osname-$normalized_architecture.tar.gz" + elif [ -z "$runtime" ]; then + download_link="$azure_feed/Sdk/$specific_version/dotnet-sdk-$specific_version-$osname-$normalized_architecture.tar.gz" + else + return 1 + fi + + echo "$download_link" + return 0 +} + +# args: +# azure_feed - $1 +# channel - $2 +# normalized_architecture - $3 +# specific_version - $4 +construct_legacy_download_link() { + eval $invocation + + local azure_feed="$1" + local channel="$2" + local normalized_architecture="$3" + local specific_version="${4//[$'\t\r\n']}" + + local distro_specific_osname + distro_specific_osname="$(get_legacy_os_name)" || return 1 + + local legacy_download_link=null + if [[ "$runtime" == "dotnet" ]]; then + legacy_download_link="$azure_feed/Runtime/$specific_version/dotnet-$distro_specific_osname-$normalized_architecture.$specific_version.tar.gz" + elif [ -z "$runtime" ]; then + legacy_download_link="$azure_feed/Sdk/$specific_version/dotnet-dev-$distro_specific_osname-$normalized_architecture.$specific_version.tar.gz" + else + return 1 + fi + + echo "$legacy_download_link" + return 0 +} + +get_user_install_path() { + eval $invocation + + if [ ! -z "${DOTNET_INSTALL_DIR:-}" ]; then + echo "$DOTNET_INSTALL_DIR" + else + echo "$HOME/.dotnet" + fi + return 0 +} + +# args: +# install_dir - $1 +resolve_installation_path() { + eval $invocation + + local install_dir=$1 + if [ "$install_dir" = "" ]; then + local user_install_path="$(get_user_install_path)" + say_verbose "resolve_installation_path: user_install_path=$user_install_path" + echo "$user_install_path" + return 0 + fi + + echo "$install_dir" + return 0 +} + +# args: +# relative_or_absolute_path - $1 +get_absolute_path() { + eval $invocation + + local relative_or_absolute_path=$1 + echo "$(cd "$(dirname "$1")" && pwd -P)/$(basename "$1")" + return 0 +} + +# args: +# input_files - stdin +# root_path - $1 +# out_path - $2 +# override - $3 +copy_files_or_dirs_from_list() { + eval $invocation + + local root_path="$(remove_trailing_slash "$1")" + local out_path="$(remove_trailing_slash "$2")" + local override="$3" + local osname="$(get_current_os_name)" + local override_switch=$( + if [ "$override" = false ]; then + if [ "$osname" = "linux-musl" ]; then + printf -- "-u"; + else + printf -- "-n"; + fi + fi) + + cat | uniq | while read -r file_path; do + local path="$(remove_beginning_slash "${file_path#$root_path}")" + local target="$out_path/$path" + if [ "$override" = true ] || (! ([ -d "$target" ] || [ -e "$target" ])); then + mkdir -p "$out_path/$(dirname "$path")" + if [ -d "$target" ]; then + rm -rf "$target" + fi + cp -R $override_switch "$root_path/$path" "$target" + fi + done +} + +# args: +# zip_path - $1 +# out_path - $2 +extract_dotnet_package() { + eval $invocation + + local zip_path="$1" + local out_path="$2" + + local temp_out_path="$(mktemp -d "$temporary_file_template")" + + local failed=false + tar -xzf "$zip_path" -C "$temp_out_path" > /dev/null || failed=true + + local folders_with_version_regex='^.*/[0-9]+\.[0-9]+[^/]+/' + find "$temp_out_path" -type f | grep -Eo "$folders_with_version_regex" | sort | copy_files_or_dirs_from_list "$temp_out_path" "$out_path" false + find "$temp_out_path" -type f | grep -Ev "$folders_with_version_regex" | copy_files_or_dirs_from_list "$temp_out_path" "$out_path" "$override_non_versioned_files" + + rm -rf "$temp_out_path" + + if [ "$failed" = true ]; then + say_err "Extraction failed" + return 1 + fi +} + +# args: +# remote_path - $1 +# [out_path] - $2 - stdout if not provided +download() { + eval $invocation + + local remote_path="$1" + local out_path="${2:-}" + + if [[ "$remote_path" != "http"* ]]; then + cp "$remote_path" "$out_path" + return $? + fi + + local failed=false + if machine_has "curl"; then + downloadcurl "$remote_path" "$out_path" || failed=true + elif machine_has "wget"; then + downloadwget "$remote_path" "$out_path" || failed=true + else + failed=true + fi + if [ "$failed" = true ]; then + say_verbose "Download failed: $remote_path" + return 1 + fi + return 0 +} + +downloadcurl() { + eval $invocation + local remote_path="$1" + local out_path="${2:-}" + + # Append feed_credential as late as possible before calling curl to avoid logging feed_credential + remote_path="${remote_path}${feed_credential}" + + local curl_options="--retry 20 --retry-delay 2 --connect-timeout 15 -sSL -f --create-dirs " + local failed=false + if [ -z "$out_path" ]; then + curl $curl_options "$remote_path" || failed=true + else + curl $curl_options -o "$out_path" "$remote_path" || failed=true + fi + if [ "$failed" = true ]; then + say_verbose "Curl download failed" + return 1 + fi + return 0 +} + +downloadwget() { + eval $invocation + local remote_path="$1" + local out_path="${2:-}" + + # Append feed_credential as late as possible before calling wget to avoid logging feed_credential + remote_path="${remote_path}${feed_credential}" + local wget_options="--tries 20 --waitretry 2 --connect-timeout 15 " + local failed=false + if [ -z "$out_path" ]; then + wget -q $wget_options -O - "$remote_path" || failed=true + else + wget $wget_options -O "$out_path" "$remote_path" || failed=true + fi + if [ "$failed" = true ]; then + say_verbose "Wget download failed" + return 1 + fi + return 0 +} + +calculate_vars() { + eval $invocation + valid_legacy_download_link=true + + normalized_architecture="$(get_normalized_architecture_from_architecture "$architecture")" + say_verbose "normalized_architecture=$normalized_architecture" + + specific_version="$(get_specific_version_from_version "$azure_feed" "$channel" "$normalized_architecture" "$version" "$json_file")" + say_verbose "specific_version=$specific_version" + if [ -z "$specific_version" ]; then + say_err "Could not resolve version information." + return 1 + fi + + download_link="$(construct_download_link "$azure_feed" "$channel" "$normalized_architecture" "$specific_version")" + say_verbose "Constructed primary named payload URL: $download_link" + + legacy_download_link="$(construct_legacy_download_link "$azure_feed" "$channel" "$normalized_architecture" "$specific_version")" || valid_legacy_download_link=false + + if [ "$valid_legacy_download_link" = true ]; then + say_verbose "Constructed legacy named payload URL: $legacy_download_link" + else + say_verbose "Cound not construct a legacy_download_link; omitting..." + fi + + install_root="$(resolve_installation_path "$install_dir")" + say_verbose "InstallRoot: $install_root" +} + +install_dotnet() { + eval $invocation + local download_failed=false + local asset_name='' + local asset_relative_path='' + + if [[ "$runtime" == "dotnet" ]]; then + asset_relative_path="shared/Microsoft.NETCore.App" + asset_name=".NET Core Runtime" + elif [[ "$runtime" == "aspnetcore" ]]; then + asset_relative_path="shared/Microsoft.AspNetCore.App" + asset_name="ASP.NET Core Runtime" + elif [ -z "$runtime" ]; then + asset_relative_path="sdk" + asset_name=".NET Core SDK" + else + say_err "Invalid value for \$runtime" + return 1 + fi + + # Check if the SDK version is already installed. + if is_dotnet_package_installed "$install_root" "$asset_relative_path" "$specific_version"; then + say "$asset_name version $specific_version is already installed." + return 0 + fi + + mkdir -p "$install_root" + zip_path="$(mktemp "$temporary_file_template")" + say_verbose "Zip path: $zip_path" + + say "Downloading link: $download_link" + + # Failures are normal in the non-legacy case for ultimately legacy downloads. + # Do not output to stderr, since output to stderr is considered an error. + download "$download_link" "$zip_path" 2>&1 || download_failed=true + + # if the download fails, download the legacy_download_link + if [ "$download_failed" = true ]; then + say "Cannot download: $download_link" + + if [ "$valid_legacy_download_link" = true ]; then + download_failed=false + download_link="$legacy_download_link" + zip_path="$(mktemp "$temporary_file_template")" + say_verbose "Legacy zip path: $zip_path" + say "Downloading legacy link: $download_link" + download "$download_link" "$zip_path" 2>&1 || download_failed=true + + if [ "$download_failed" = true ]; then + say "Cannot download: $download_link" + fi + fi + fi + + if [ "$download_failed" = true ]; then + say_err "Could not find/download: \`$asset_name\` with version = $specific_version" + say_err "Refer to: https://aka.ms/dotnet-os-lifecycle for information on .NET Core support" + return 1 + fi + + say "Extracting zip from $download_link" + extract_dotnet_package "$zip_path" "$install_root" + + # Check if the SDK version is installed; if not, fail the installation. + # if the version contains "RTM" or "servicing"; check if a 'release-type' SDK version is installed. + if [[ $specific_version == *"rtm"* || $specific_version == *"servicing"* ]]; then + IFS='-' + read -ra verArr <<< "$specific_version" + release_version="${verArr[0]}" + unset IFS; + say_verbose "Checking installation: version = $release_version" + if is_dotnet_package_installed "$install_root" "$asset_relative_path" "$release_version"; then + return 0 + fi + fi + + # Check if the standard SDK version is installed. + say_verbose "Checking installation: version = $specific_version" + if is_dotnet_package_installed "$install_root" "$asset_relative_path" "$specific_version"; then + return 0 + fi + + say_err "\`$asset_name\` with version = $specific_version failed to install with an unknown error." + return 1 +} + +args=("$@") + +local_version_file_relative_path="/.version" +bin_folder_relative_path="" +temporary_file_template="${TMPDIR:-/tmp}/dotnet.XXXXXXXXX" + +channel="LTS" +version="Latest" +json_file="" +install_dir="" +architecture="" +dry_run=false +no_path=false +no_cdn=false +azure_feed="https://dotnetcli.azureedge.net/dotnet" +uncached_feed="https://dotnetcli.blob.core.windows.net/dotnet" +feed_credential="" +verbose=false +runtime="" +runtime_id="" +override_non_versioned_files=true +non_dynamic_parameters="" + +while [ $# -ne 0 ] +do + name="$1" + case "$name" in + -c|--channel|-[Cc]hannel) + shift + channel="$1" + ;; + -v|--version|-[Vv]ersion) + shift + version="$1" + ;; + -i|--install-dir|-[Ii]nstall[Dd]ir) + shift + install_dir="$1" + ;; + --arch|--architecture|-[Aa]rch|-[Aa]rchitecture) + shift + architecture="$1" + ;; + --shared-runtime|-[Ss]hared[Rr]untime) + say_warning "The --shared-runtime flag is obsolete and may be removed in a future version of this script. The recommended usage is to specify '--runtime dotnet'." + if [ -z "$runtime" ]; then + runtime="dotnet" + fi + ;; + --runtime|-[Rr]untime) + shift + runtime="$1" + if [[ "$runtime" != "dotnet" ]] && [[ "$runtime" != "aspnetcore" ]]; then + say_err "Unsupported value for --runtime: '$1'. Valid values are 'dotnet' and 'aspnetcore'." + if [[ "$runtime" == "windowsdesktop" ]]; then + say_err "WindowsDesktop archives are manufactured for Windows platforms only." + fi + exit 1 + fi + ;; + --dry-run|-[Dd]ry[Rr]un) + dry_run=true + ;; + --no-path|-[Nn]o[Pp]ath) + no_path=true + non_dynamic_parameters+=" $name" + ;; + --verbose|-[Vv]erbose) + verbose=true + non_dynamic_parameters+=" $name" + ;; + --no-cdn|-[Nn]o[Cc]dn) + no_cdn=true + non_dynamic_parameters+=" $name" + ;; + --azure-feed|-[Aa]zure[Ff]eed) + shift + azure_feed="$1" + non_dynamic_parameters+=" $name "\""$1"\""" + ;; + --uncached-feed|-[Uu]ncached[Ff]eed) + shift + uncached_feed="$1" + non_dynamic_parameters+=" $name "\""$1"\""" + ;; + --feed-credential|-[Ff]eed[Cc]redential) + shift + feed_credential="$1" + non_dynamic_parameters+=" $name "\""$1"\""" + ;; + --runtime-id|-[Rr]untime[Ii]d) + shift + runtime_id="$1" + non_dynamic_parameters+=" $name "\""$1"\""" + ;; + --jsonfile|-[Jj][Ss]on[Ff]ile) + shift + json_file="$1" + ;; + --skip-non-versioned-files|-[Ss]kip[Nn]on[Vv]ersioned[Ff]iles) + override_non_versioned_files=false + non_dynamic_parameters+=" $name" + ;; + -?|--?|-h|--help|-[Hh]elp) + script_name="$(basename "$0")" + echo ".NET Tools Installer" + echo "Usage: $script_name [-c|--channel ] [-v|--version ] [-p|--prefix ]" + echo " $script_name -h|-?|--help" + echo "" + echo "$script_name is a simple command line interface for obtaining dotnet cli." + echo "" + echo "Options:" + echo " -c,--channel Download from the channel specified, Defaults to \`$channel\`." + echo " -Channel" + echo " Possible values:" + echo " - Current - most current release" + echo " - LTS - most current supported release" + echo " - 2-part version in a format A.B - represents a specific release" + echo " examples: 2.0; 1.0" + echo " - Branch name" + echo " examples: release/2.0.0; Master" + echo " Note: The version parameter overrides the channel parameter." + echo " -v,--version Use specific VERSION, Defaults to \`$version\`." + echo " -Version" + echo " Possible values:" + echo " - latest - most latest build on specific channel" + echo " - coherent - most latest coherent build on specific channel" + echo " coherent applies only to SDK downloads" + echo " - 3-part version in a format A.B.C - represents specific version of build" + echo " examples: 2.0.0-preview2-006120; 1.1.0" + echo " -i,--install-dir Install under specified location (see Install Location below)" + echo " -InstallDir" + echo " --architecture Architecture of dotnet binaries to be installed, Defaults to \`$architecture\`." + echo " --arch,-Architecture,-Arch" + echo " Possible values: x64, arm, and arm64" + echo " --runtime Installs a shared runtime only, without the SDK." + echo " -Runtime" + echo " Possible values:" + echo " - dotnet - the Microsoft.NETCore.App shared runtime" + echo " - aspnetcore - the Microsoft.AspNetCore.App shared runtime" + echo " --dry-run,-DryRun Do not perform installation. Display download link." + echo " --no-path, -NoPath Do not set PATH for the current process." + echo " --verbose,-Verbose Display diagnostics information." + echo " --azure-feed,-AzureFeed Azure feed location. Defaults to $azure_feed, This parameter typically is not changed by the user." + echo " --uncached-feed,-UncachedFeed Uncached feed location. This parameter typically is not changed by the user." + echo " --feed-credential,-FeedCredential Azure feed shared access token. This parameter typically is not specified." + echo " --skip-non-versioned-files Skips non-versioned files if they already exist, such as the dotnet executable." + echo " -SkipNonVersionedFiles" + echo " --no-cdn,-NoCdn Disable downloading from the Azure CDN, and use the uncached feed directly." + echo " --jsonfile Determines the SDK version from a user specified global.json file." + echo " Note: global.json must have a value for 'SDK:Version'" + echo " --runtime-id Installs the .NET Tools for the given platform (use linux-x64 for portable linux)." + echo " -RuntimeId" + echo " -?,--?,-h,--help,-Help Shows this help message" + echo "" + echo "Obsolete parameters:" + echo " --shared-runtime The recommended alternative is '--runtime dotnet'." + echo " This parameter is obsolete and may be removed in a future version of this script." + echo " Installs just the shared runtime bits, not the entire SDK." + echo "" + echo "Install Location:" + echo " Location is chosen in following order:" + echo " - --install-dir option" + echo " - Environmental variable DOTNET_INSTALL_DIR" + echo " - $HOME/.dotnet" + exit 0 + ;; + *) + say_err "Unknown argument \`$name\`" + exit 1 + ;; + esac + + shift +done + +if [ "$no_cdn" = true ]; then + azure_feed="$uncached_feed" +fi + +check_min_reqs +calculate_vars +script_name=$(basename "$0") + +if [ "$dry_run" = true ]; then + say "Payload URLs:" + say "Primary named payload URL: $download_link" + if [ "$valid_legacy_download_link" = true ]; then + say "Legacy named payload URL: $legacy_download_link" + fi + repeatable_command="./$script_name --version "\""$specific_version"\"" --install-dir "\""$install_root"\"" --architecture "\""$normalized_architecture"\""" + if [[ "$runtime" == "dotnet" ]]; then + repeatable_command+=" --runtime "\""dotnet"\""" + elif [[ "$runtime" == "aspnetcore" ]]; then + repeatable_command+=" --runtime "\""aspnetcore"\""" + fi + repeatable_command+="$non_dynamic_parameters" + say "Repeatable invocation: $repeatable_command" + exit 0 +fi + +check_pre_reqs +install_dotnet + +bin_path="$(get_absolute_path "$(combine_paths "$install_root" "$bin_folder_relative_path")")" +if [ "$no_path" = false ]; then + say "Adding to current process PATH: \`$bin_path\`. Note: This change will be visible only when sourcing script." + export PATH="$bin_path":"$PATH" +else + say "Binaries of dotnet can be found in $bin_path" +fi + +say "Installation finished successfully." diff --git a/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java b/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java index 6a604ba28..fd8db7a4a 100644 --- a/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java +++ b/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java @@ -21,6 +21,10 @@ public class CSharpPluginTest { private CSharpPlugin csPlugin; + + public CSharpPluginTest() { + TestUtils.skipIfNotAvailable("dotnet"); + } @Before public void setUp() { From c000940afe6af0757e4c9a997b144f17488df1f9 Mon Sep 17 00:00:00 2001 From: PPeltola Date: Wed, 20 May 2020 13:40:40 +0300 Subject: [PATCH 10/61] fix checkstyle(?) --- .../csharp/CSharpStudentFilePolicyTest.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpStudentFilePolicyTest.java b/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpStudentFilePolicyTest.java index c2c358d2e..b78a91700 100644 --- a/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpStudentFilePolicyTest.java +++ b/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpStudentFilePolicyTest.java @@ -32,10 +32,10 @@ public void testFilesInSrcDirectoryAreStudentFiles() throws IOException { TestUtils.collectPaths(projectPath, studentFiles, policy); assertEquals(2, studentFiles.size()); - assertTrue(studentFiles.contains("src" + File.separator + "PolicySample" + - File.separator + "Program.cs")); - assertTrue(studentFiles.contains("src" + File.separator + "PolicySample" + - File.separator + "PolicySample.csproj")); + assertTrue(studentFiles.contains("src" + File.separator + "PolicySample" + + File.separator + "Program.cs")); + assertTrue(studentFiles.contains("src" + File.separator + "PolicySample" + + File.separator + "PolicySample.csproj")); } @Test @@ -44,10 +44,10 @@ public void testFilesInTestDirectoryAreNotStudentFiles() throws IOException { TestUtils.collectPaths(projectPath, studentFiles, policy); assertEquals(2, studentFiles.size()); - assertFalse(studentFiles.contains("test" + File.separator + "PolicySampleTests" + - File.separator + "PrgramTest.cs")); - assertFalse(studentFiles.contains("test" + File.separator + "PolicySampleTests" + - File.separator + "PolicySampleTests.csproj")); + assertFalse(studentFiles.contains("test" + File.separator + "PolicySampleTests" + + File.separator + "PrgramTest.cs")); + assertFalse(studentFiles.contains("test" + File.separator + "PolicySampleTests" + + File.separator + "PolicySampleTests.csproj")); } } From de6fb58e38192ee486d9103ed4ecf7ce1a3055ff Mon Sep 17 00:00:00 2001 From: PPeltola Date: Wed, 20 May 2020 15:01:52 +0300 Subject: [PATCH 11/61] lets break travis for science! --- .../java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java b/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java index fd8db7a4a..7bf9736c2 100644 --- a/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java +++ b/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java @@ -23,7 +23,7 @@ public class CSharpPluginTest { private CSharpPlugin csPlugin; public CSharpPluginTest() { - TestUtils.skipIfNotAvailable("dotnet"); + //TestUtils.skipIfNotAvailable("dotnet"); } @Before From 7da27f7ba531eb9085ac510bd6d1cb121b43460e Mon Sep 17 00:00:00 2001 From: chenhuiz Date: Wed, 20 May 2020 15:47:36 +0300 Subject: [PATCH 12/61] CsharpExerciseDescParser tests --- .../csharp/CSharpExerciseDescParserTest.java | 50 +++++++++++++++++++ .../.tmc_available_points.json | 11 ++++ .../.tmc_available_points.json | 11 ++++ 3 files changed, 72 insertions(+) create mode 100644 tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpExerciseDescParserTest.java create mode 100644 tmc-langs-csharp/src/test/resources/Desc_samples/all_tests_passed_sample/.tmc_available_points.json create mode 100644 tmc-langs-csharp/src/test/resources/Desc_samples/some_tests_failed_sample/.tmc_available_points.json diff --git a/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpExerciseDescParserTest.java b/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpExerciseDescParserTest.java new file mode 100644 index 000000000..9f82c6176 --- /dev/null +++ b/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpExerciseDescParserTest.java @@ -0,0 +1,50 @@ +package fi.helsinki.cs.tmc.langs.csharp; + +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; + +import fi.helsinki.cs.tmc.langs.domain.TestDesc; +import fi.helsinki.cs.tmc.langs.utils.TestUtils; + +import com.google.common.collect.ImmutableList; + +import org.junit.Test; + +import java.io.IOException; +import java.nio.file.Path; + +public class CSharpExerciseDescParserTest { + + private final Path allPassedSampleDir; + private final Path someFailedSampleDir; + + public CSharpExerciseDescParserTest() { + Path desc_samples_dir = TestUtils.getPath(getClass(), "Desc_samples"); + allPassedSampleDir = desc_samples_dir.resolve("all_tests_passed_sample"); + someFailedSampleDir = desc_samples_dir.resolve("some_tests_failed_sample"); + } + + private void testDescAsExpected(TestDesc desc, String name, String[] points) { + assertEquals(name, desc.name); + assertArrayEquals(points, desc.points.toArray()); + } + + @Test + public void testDescParsePointsCorrectly() throws IOException { + ImmutableList descs = new CSharpExerciseDescParser(allPassedSampleDir).parse(); + + testDescAsExpected(descs.get(0), "PassingSampleTests.ProgramTest.TestGetName", new String[]{"1", "1.1"}); + testDescAsExpected(descs.get(1), "PassingSampleTests.ProgramTest.TestGetYear", new String[]{"1", "1.2"}); + } + + @Test + public void testThatParseWorksForNoPointsJson() throws IOException { + ImmutableList descs = new CSharpExerciseDescParser(someFailedSampleDir).parse(); + + testDescAsExpected(descs.get(0), + "PartiallyFailingSampleTests.ProgramTest.TestCheckFinePassed", + new String[]{"2", "2.2"}); + testDescAsExpected(descs.get(1), + "PartiallyFailingSampleTests.ProgramTest.TestCheckFinePassed", new String[]{}); + } +} diff --git a/tmc-langs-csharp/src/test/resources/Desc_samples/all_tests_passed_sample/.tmc_available_points.json b/tmc-langs-csharp/src/test/resources/Desc_samples/all_tests_passed_sample/.tmc_available_points.json new file mode 100644 index 000000000..f4be267d3 --- /dev/null +++ b/tmc-langs-csharp/src/test/resources/Desc_samples/all_tests_passed_sample/.tmc_available_points.json @@ -0,0 +1,11 @@ +{ + "PassingSampleTests.ProgramTest.TestGetName": [ + "1", + "1.1" + ], + "PassingSampleTests.ProgramTest.TestGetYear": [ + "1", + "1.2" + ] +} + diff --git a/tmc-langs-csharp/src/test/resources/Desc_samples/some_tests_failed_sample/.tmc_available_points.json b/tmc-langs-csharp/src/test/resources/Desc_samples/some_tests_failed_sample/.tmc_available_points.json new file mode 100644 index 000000000..be6e4e9cd --- /dev/null +++ b/tmc-langs-csharp/src/test/resources/Desc_samples/some_tests_failed_sample/.tmc_available_points.json @@ -0,0 +1,11 @@ +{ + "PartiallyFailingSampleTests.ProgramTest.TestCheckSameFailed": [ + "2", + "2.1" + ], + "PartiallyFailingSampleTests.ProgramTest.TestCheckFinePassed": [ + "2", + "2.2" + ] +} + From 12ebe60e3e7b9647d8d7037a69708ca5a82b24f3 Mon Sep 17 00:00:00 2001 From: PPeltola Date: Wed, 20 May 2020 15:52:03 +0300 Subject: [PATCH 13/61] perhaps mr travis would like an another way to install dotnet --- .travis.yml | 3 +- tmc-langs-csharp/dotnet-install.sh | 1093 ----------------- .../cs/tmc/langs/csharp/CSharpPluginTest.java | 2 +- 3 files changed, 2 insertions(+), 1096 deletions(-) delete mode 100755 tmc-langs-csharp/dotnet-install.sh diff --git a/.travis.yml b/.travis.yml index 53c3aabd2..bb8f82c2c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -28,8 +28,7 @@ before_install: - sudo chmod 277 /usr/local/lib/R/site-library - Rscript -e 'install.packages(c("devtools","testthat"),repos="http://cran.us.r-project.org")' - Rscript -e 'devtools::install_github("RTMC/tmc-r-tester/tmcRtestrunner")' - - chmod +x tmc-langs-csharp/dotnet-install.sh - - ./tmc-langs-csharp/dotnet-install.sh + - curl -sSL https://dot.net/v1/dotnet-install.sh | bash /dev/stdin - wget https://github.com/TMC-C/tmc-csharp-runner/releases/download/v1.0.0/tmc-csharp-runner.tar.gz -O /tmp/tmc-csharp-runner.tar.gz - tar -xvf /tmp/tmc-csharp-runner.tar.gz - export TMC_CSHARP_BOOTSTRAP_PATH=/tmp/publish/Bootstrap.dll diff --git a/tmc-langs-csharp/dotnet-install.sh b/tmc-langs-csharp/dotnet-install.sh deleted file mode 100755 index 0c20299a5..000000000 --- a/tmc-langs-csharp/dotnet-install.sh +++ /dev/null @@ -1,1093 +0,0 @@ -#!/usr/bin/env bash -# Copyright (c) .NET Foundation and contributors. All rights reserved. -# Licensed under the MIT license. See LICENSE file in the project root for full license information. -# - -# Stop script on NZEC -set -e -# Stop script if unbound variable found (use ${var:-} if intentional) -set -u -# By default cmd1 | cmd2 returns exit code of cmd2 regardless of cmd1 success -# This is causing it to fail -set -o pipefail - -# Use in the the functions: eval $invocation -invocation='say_verbose "Calling: ${yellow:-}${FUNCNAME[0]} ${green:-}$*${normal:-}"' - -# standard output may be used as a return value in the functions -# we need a way to write text on the screen in the functions so that -# it won't interfere with the return value. -# Exposing stream 3 as a pipe to standard output of the script itself -exec 3>&1 - -# Setup some colors to use. These need to work in fairly limited shells, like the Ubuntu Docker container where there are only 8 colors. -# See if stdout is a terminal -if [ -t 1 ] && command -v tput > /dev/null; then - # see if it supports colors - ncolors=$(tput colors) - if [ -n "$ncolors" ] && [ $ncolors -ge 8 ]; then - bold="$(tput bold || echo)" - normal="$(tput sgr0 || echo)" - black="$(tput setaf 0 || echo)" - red="$(tput setaf 1 || echo)" - green="$(tput setaf 2 || echo)" - yellow="$(tput setaf 3 || echo)" - blue="$(tput setaf 4 || echo)" - magenta="$(tput setaf 5 || echo)" - cyan="$(tput setaf 6 || echo)" - white="$(tput setaf 7 || echo)" - fi -fi - -say_warning() { - printf "%b\n" "${yellow:-}dotnet_install: Warning: $1${normal:-}" -} - -say_err() { - printf "%b\n" "${red:-}dotnet_install: Error: $1${normal:-}" >&2 -} - -say() { - # using stream 3 (defined in the beginning) to not interfere with stdout of functions - # which may be used as return value - printf "%b\n" "${cyan:-}dotnet-install:${normal:-} $1" >&3 -} - -say_verbose() { - if [ "$verbose" = true ]; then - say "$1" - fi -} - -# This platform list is finite - if the SDK/Runtime has supported Linux distribution-specific assets, -# then and only then should the Linux distribution appear in this list. -# Adding a Linux distribution to this list does not imply distribution-specific support. -get_legacy_os_name_from_platform() { - eval $invocation - - platform="$1" - case "$platform" in - "centos.7") - echo "centos" - return 0 - ;; - "debian.8") - echo "debian" - return 0 - ;; - "debian.9") - echo "debian.9" - return 0 - ;; - "fedora.23") - echo "fedora.23" - return 0 - ;; - "fedora.24") - echo "fedora.24" - return 0 - ;; - "fedora.27") - echo "fedora.27" - return 0 - ;; - "fedora.28") - echo "fedora.28" - return 0 - ;; - "opensuse.13.2") - echo "opensuse.13.2" - return 0 - ;; - "opensuse.42.1") - echo "opensuse.42.1" - return 0 - ;; - "opensuse.42.3") - echo "opensuse.42.3" - return 0 - ;; - "rhel.7"*) - echo "rhel" - return 0 - ;; - "ubuntu.14.04") - echo "ubuntu" - return 0 - ;; - "ubuntu.16.04") - echo "ubuntu.16.04" - return 0 - ;; - "ubuntu.16.10") - echo "ubuntu.16.10" - return 0 - ;; - "ubuntu.18.04") - echo "ubuntu.18.04" - return 0 - ;; - "alpine.3.4.3") - echo "alpine" - return 0 - ;; - esac - return 1 -} - -get_linux_platform_name() { - eval $invocation - - if [ -n "$runtime_id" ]; then - echo "${runtime_id%-*}" - return 0 - else - if [ -e /etc/os-release ]; then - . /etc/os-release - echo "$ID${VERSION_ID:+.${VERSION_ID}}" - return 0 - elif [ -e /etc/redhat-release ]; then - local redhatRelease=$(&1 || true) | grep -q musl -} - -get_current_os_name() { - eval $invocation - - local uname=$(uname) - if [ "$uname" = "Darwin" ]; then - echo "osx" - return 0 - elif [ "$uname" = "FreeBSD" ]; then - echo "freebsd" - return 0 - elif [ "$uname" = "Linux" ]; then - local linux_platform_name - linux_platform_name="$(get_linux_platform_name)" || { echo "linux" && return 0 ; } - - if [ "$linux_platform_name" = "rhel.6" ]; then - echo $linux_platform_name - return 0 - elif is_musl_based_distro; then - echo "linux-musl" - return 0 - else - echo "linux" - return 0 - fi - fi - - say_err "OS name could not be detected: UName = $uname" - return 1 -} - -get_legacy_os_name() { - eval $invocation - - local uname=$(uname) - if [ "$uname" = "Darwin" ]; then - echo "osx" - return 0 - elif [ -n "$runtime_id" ]; then - echo $(get_legacy_os_name_from_platform "${runtime_id%-*}" || echo "${runtime_id%-*}") - return 0 - else - if [ -e /etc/os-release ]; then - . /etc/os-release - os=$(get_legacy_os_name_from_platform "$ID${VERSION_ID:+.${VERSION_ID}}" || echo "") - if [ -n "$os" ]; then - echo "$os" - return 0 - fi - fi - fi - - say_verbose "Distribution specific OS name and version could not be detected: UName = $uname" - return 1 -} - -machine_has() { - eval $invocation - - hash "$1" > /dev/null 2>&1 - return $? -} - - -check_min_reqs() { - local hasMinimum=false - if machine_has "curl"; then - hasMinimum=true - elif machine_has "wget"; then - hasMinimum=true - fi - - if [ "$hasMinimum" = "false" ]; then - say_err "curl (recommended) or wget are required to download dotnet. Install missing prerequisite to proceed." - return 1 - fi - return 0 -} - -check_pre_reqs() { - eval $invocation - - if [ "${DOTNET_INSTALL_SKIP_PREREQS:-}" = "1" ]; then - return 0 - fi - - if [ "$(uname)" = "Linux" ]; then - if is_musl_based_distro; then - if ! command -v scanelf > /dev/null; then - say_warning "scanelf not found, please install pax-utils package." - return 0 - fi - LDCONFIG_COMMAND="scanelf --ldpath -BF '%f'" - [ -z "$($LDCONFIG_COMMAND 2>/dev/null | grep libintl)" ] && say_warning "Unable to locate libintl. Probable prerequisite missing; install libintl (or gettext)." - else - if [ ! -x "$(command -v ldconfig)" ]; then - say_verbose "ldconfig is not in PATH, trying /sbin/ldconfig." - LDCONFIG_COMMAND="/sbin/ldconfig" - else - LDCONFIG_COMMAND="ldconfig" - fi - local librarypath=${LD_LIBRARY_PATH:-} - LDCONFIG_COMMAND="$LDCONFIG_COMMAND -NXv ${librarypath//:/ }" - fi - - [ -z "$($LDCONFIG_COMMAND 2>/dev/null | grep zlib)" ] && say_warning "Unable to locate zlib. Probable prerequisite missing; install zlib." - [ -z "$($LDCONFIG_COMMAND 2>/dev/null | grep ssl)" ] && say_warning "Unable to locate libssl. Probable prerequisite missing; install libssl." - [ -z "$($LDCONFIG_COMMAND 2>/dev/null | grep libicu)" ] && say_warning "Unable to locate libicu. Probable prerequisite missing; install libicu." - [ -z "$($LDCONFIG_COMMAND 2>/dev/null | grep lttng)" ] && say_warning "Unable to locate liblttng. Probable prerequisite missing; install libcurl." - [ -z "$($LDCONFIG_COMMAND 2>/dev/null | grep libcurl)" ] && say_warning "Unable to locate libcurl. Probable prerequisite missing; install libcurl." - fi - - return 0 -} - -# args: -# input - $1 -to_lowercase() { - #eval $invocation - - echo "$1" | tr '[:upper:]' '[:lower:]' - return 0 -} - -# args: -# input - $1 -remove_trailing_slash() { - #eval $invocation - - local input="${1:-}" - echo "${input%/}" - return 0 -} - -# args: -# input - $1 -remove_beginning_slash() { - #eval $invocation - - local input="${1:-}" - echo "${input#/}" - return 0 -} - -# args: -# root_path - $1 -# child_path - $2 - this parameter can be empty -combine_paths() { - eval $invocation - - # TODO: Consider making it work with any number of paths. For now: - if [ ! -z "${3:-}" ]; then - say_err "combine_paths: Function takes two parameters." - return 1 - fi - - local root_path="$(remove_trailing_slash "$1")" - local child_path="$(remove_beginning_slash "${2:-}")" - say_verbose "combine_paths: root_path=$root_path" - say_verbose "combine_paths: child_path=$child_path" - echo "$root_path/$child_path" - return 0 -} - -get_machine_architecture() { - eval $invocation - - if command -v uname > /dev/null; then - CPUName=$(uname -m) - case $CPUName in - armv7l) - echo "arm" - return 0 - ;; - aarch64) - echo "arm64" - return 0 - ;; - esac - fi - - # Always default to 'x64' - echo "x64" - return 0 -} - -# args: -# architecture - $1 -get_normalized_architecture_from_architecture() { - eval $invocation - - local architecture="$(to_lowercase "$1")" - case "$architecture" in - \) - echo "$(get_normalized_architecture_from_architecture "$(get_machine_architecture)")" - return 0 - ;; - amd64|x64) - echo "x64" - return 0 - ;; - arm) - echo "arm" - return 0 - ;; - arm64) - echo "arm64" - return 0 - ;; - esac - - say_err "Architecture \`$architecture\` not supported. If you think this is a bug, report it at https://github.com/dotnet/sdk/issues" - return 1 -} - -# The version text returned from the feeds is a 1-line or 2-line string: -# For the SDK and the dotnet runtime (2 lines): -# Line 1: # commit_hash -# Line 2: # 4-part version -# For the aspnetcore runtime (1 line): -# Line 1: # 4-part version - -# args: -# version_text - stdin -get_version_from_version_info() { - eval $invocation - - cat | tail -n 1 | sed 's/\r$//' - return 0 -} - -# args: -# install_root - $1 -# relative_path_to_package - $2 -# specific_version - $3 -is_dotnet_package_installed() { - eval $invocation - - local install_root="$1" - local relative_path_to_package="$2" - local specific_version="${3//[$'\t\r\n']}" - - local dotnet_package_path="$(combine_paths "$(combine_paths "$install_root" "$relative_path_to_package")" "$specific_version")" - say_verbose "is_dotnet_package_installed: dotnet_package_path=$dotnet_package_path" - - if [ -d "$dotnet_package_path" ]; then - return 0 - else - return 1 - fi -} - -# args: -# azure_feed - $1 -# channel - $2 -# normalized_architecture - $3 -# coherent - $4 -get_latest_version_info() { - eval $invocation - - local azure_feed="$1" - local channel="$2" - local normalized_architecture="$3" - local coherent="$4" - - local version_file_url=null - if [[ "$runtime" == "dotnet" ]]; then - version_file_url="$uncached_feed/Runtime/$channel/latest.version" - elif [[ "$runtime" == "aspnetcore" ]]; then - version_file_url="$uncached_feed/aspnetcore/Runtime/$channel/latest.version" - elif [ -z "$runtime" ]; then - if [ "$coherent" = true ]; then - version_file_url="$uncached_feed/Sdk/$channel/latest.coherent.version" - else - version_file_url="$uncached_feed/Sdk/$channel/latest.version" - fi - else - say_err "Invalid value for \$runtime" - return 1 - fi - say_verbose "get_latest_version_info: latest url: $version_file_url" - - download "$version_file_url" - return $? -} - -# args: -# json_file - $1 -parse_jsonfile_for_version() { - eval $invocation - - local json_file="$1" - if [ ! -f "$json_file" ]; then - say_err "Unable to find \`$json_file\`" - return 1 - fi - - sdk_section=$(cat $json_file | awk '/"sdk"/,/}/') - if [ -z "$sdk_section" ]; then - say_err "Unable to parse the SDK node in \`$json_file\`" - return 1 - fi - - sdk_list=$(echo $sdk_section | awk -F"[{}]" '{print $2}') - sdk_list=${sdk_list//[\" ]/} - sdk_list=${sdk_list//,/$'\n'} - sdk_list="$(echo -e "${sdk_list}" | tr -d '[[:space:]]')" - - local version_info="" - while read -r line; do - IFS=: - while read -r key value; do - if [[ "$key" == "version" ]]; then - version_info=$value - fi - done <<< "$line" - done <<< "$sdk_list" - if [ -z "$version_info" ]; then - say_err "Unable to find the SDK:version node in \`$json_file\`" - return 1 - fi - - unset IFS; - echo "$version_info" - return 0 -} - -# args: -# azure_feed - $1 -# channel - $2 -# normalized_architecture - $3 -# version - $4 -# json_file - $5 -get_specific_version_from_version() { - eval $invocation - - local azure_feed="$1" - local channel="$2" - local normalized_architecture="$3" - local version="$(to_lowercase "$4")" - local json_file="$5" - - if [ -z "$json_file" ]; then - case "$version" in - latest) - local version_info - version_info="$(get_latest_version_info "$azure_feed" "$channel" "$normalized_architecture" false)" || return 1 - say_verbose "get_specific_version_from_version: version_info=$version_info" - echo "$version_info" | get_version_from_version_info - return 0 - ;; - coherent) - local version_info - version_info="$(get_latest_version_info "$azure_feed" "$channel" "$normalized_architecture" true)" || return 1 - say_verbose "get_specific_version_from_version: version_info=$version_info" - echo "$version_info" | get_version_from_version_info - return 0 - ;; - *) - echo "$version" - return 0 - ;; - esac - else - local version_info - version_info="$(parse_jsonfile_for_version "$json_file")" || return 1 - echo "$version_info" - return 0 - fi -} - -# args: -# azure_feed - $1 -# channel - $2 -# normalized_architecture - $3 -# specific_version - $4 -construct_download_link() { - eval $invocation - - local azure_feed="$1" - local channel="$2" - local normalized_architecture="$3" - local specific_version="${4//[$'\t\r\n']}" - - local osname - osname="$(get_current_os_name)" || return 1 - - local download_link=null - if [[ "$runtime" == "dotnet" ]]; then - download_link="$azure_feed/Runtime/$specific_version/dotnet-runtime-$specific_version-$osname-$normalized_architecture.tar.gz" - elif [[ "$runtime" == "aspnetcore" ]]; then - download_link="$azure_feed/aspnetcore/Runtime/$specific_version/aspnetcore-runtime-$specific_version-$osname-$normalized_architecture.tar.gz" - elif [ -z "$runtime" ]; then - download_link="$azure_feed/Sdk/$specific_version/dotnet-sdk-$specific_version-$osname-$normalized_architecture.tar.gz" - else - return 1 - fi - - echo "$download_link" - return 0 -} - -# args: -# azure_feed - $1 -# channel - $2 -# normalized_architecture - $3 -# specific_version - $4 -construct_legacy_download_link() { - eval $invocation - - local azure_feed="$1" - local channel="$2" - local normalized_architecture="$3" - local specific_version="${4//[$'\t\r\n']}" - - local distro_specific_osname - distro_specific_osname="$(get_legacy_os_name)" || return 1 - - local legacy_download_link=null - if [[ "$runtime" == "dotnet" ]]; then - legacy_download_link="$azure_feed/Runtime/$specific_version/dotnet-$distro_specific_osname-$normalized_architecture.$specific_version.tar.gz" - elif [ -z "$runtime" ]; then - legacy_download_link="$azure_feed/Sdk/$specific_version/dotnet-dev-$distro_specific_osname-$normalized_architecture.$specific_version.tar.gz" - else - return 1 - fi - - echo "$legacy_download_link" - return 0 -} - -get_user_install_path() { - eval $invocation - - if [ ! -z "${DOTNET_INSTALL_DIR:-}" ]; then - echo "$DOTNET_INSTALL_DIR" - else - echo "$HOME/.dotnet" - fi - return 0 -} - -# args: -# install_dir - $1 -resolve_installation_path() { - eval $invocation - - local install_dir=$1 - if [ "$install_dir" = "" ]; then - local user_install_path="$(get_user_install_path)" - say_verbose "resolve_installation_path: user_install_path=$user_install_path" - echo "$user_install_path" - return 0 - fi - - echo "$install_dir" - return 0 -} - -# args: -# relative_or_absolute_path - $1 -get_absolute_path() { - eval $invocation - - local relative_or_absolute_path=$1 - echo "$(cd "$(dirname "$1")" && pwd -P)/$(basename "$1")" - return 0 -} - -# args: -# input_files - stdin -# root_path - $1 -# out_path - $2 -# override - $3 -copy_files_or_dirs_from_list() { - eval $invocation - - local root_path="$(remove_trailing_slash "$1")" - local out_path="$(remove_trailing_slash "$2")" - local override="$3" - local osname="$(get_current_os_name)" - local override_switch=$( - if [ "$override" = false ]; then - if [ "$osname" = "linux-musl" ]; then - printf -- "-u"; - else - printf -- "-n"; - fi - fi) - - cat | uniq | while read -r file_path; do - local path="$(remove_beginning_slash "${file_path#$root_path}")" - local target="$out_path/$path" - if [ "$override" = true ] || (! ([ -d "$target" ] || [ -e "$target" ])); then - mkdir -p "$out_path/$(dirname "$path")" - if [ -d "$target" ]; then - rm -rf "$target" - fi - cp -R $override_switch "$root_path/$path" "$target" - fi - done -} - -# args: -# zip_path - $1 -# out_path - $2 -extract_dotnet_package() { - eval $invocation - - local zip_path="$1" - local out_path="$2" - - local temp_out_path="$(mktemp -d "$temporary_file_template")" - - local failed=false - tar -xzf "$zip_path" -C "$temp_out_path" > /dev/null || failed=true - - local folders_with_version_regex='^.*/[0-9]+\.[0-9]+[^/]+/' - find "$temp_out_path" -type f | grep -Eo "$folders_with_version_regex" | sort | copy_files_or_dirs_from_list "$temp_out_path" "$out_path" false - find "$temp_out_path" -type f | grep -Ev "$folders_with_version_regex" | copy_files_or_dirs_from_list "$temp_out_path" "$out_path" "$override_non_versioned_files" - - rm -rf "$temp_out_path" - - if [ "$failed" = true ]; then - say_err "Extraction failed" - return 1 - fi -} - -# args: -# remote_path - $1 -# [out_path] - $2 - stdout if not provided -download() { - eval $invocation - - local remote_path="$1" - local out_path="${2:-}" - - if [[ "$remote_path" != "http"* ]]; then - cp "$remote_path" "$out_path" - return $? - fi - - local failed=false - if machine_has "curl"; then - downloadcurl "$remote_path" "$out_path" || failed=true - elif machine_has "wget"; then - downloadwget "$remote_path" "$out_path" || failed=true - else - failed=true - fi - if [ "$failed" = true ]; then - say_verbose "Download failed: $remote_path" - return 1 - fi - return 0 -} - -downloadcurl() { - eval $invocation - local remote_path="$1" - local out_path="${2:-}" - - # Append feed_credential as late as possible before calling curl to avoid logging feed_credential - remote_path="${remote_path}${feed_credential}" - - local curl_options="--retry 20 --retry-delay 2 --connect-timeout 15 -sSL -f --create-dirs " - local failed=false - if [ -z "$out_path" ]; then - curl $curl_options "$remote_path" || failed=true - else - curl $curl_options -o "$out_path" "$remote_path" || failed=true - fi - if [ "$failed" = true ]; then - say_verbose "Curl download failed" - return 1 - fi - return 0 -} - -downloadwget() { - eval $invocation - local remote_path="$1" - local out_path="${2:-}" - - # Append feed_credential as late as possible before calling wget to avoid logging feed_credential - remote_path="${remote_path}${feed_credential}" - local wget_options="--tries 20 --waitretry 2 --connect-timeout 15 " - local failed=false - if [ -z "$out_path" ]; then - wget -q $wget_options -O - "$remote_path" || failed=true - else - wget $wget_options -O "$out_path" "$remote_path" || failed=true - fi - if [ "$failed" = true ]; then - say_verbose "Wget download failed" - return 1 - fi - return 0 -} - -calculate_vars() { - eval $invocation - valid_legacy_download_link=true - - normalized_architecture="$(get_normalized_architecture_from_architecture "$architecture")" - say_verbose "normalized_architecture=$normalized_architecture" - - specific_version="$(get_specific_version_from_version "$azure_feed" "$channel" "$normalized_architecture" "$version" "$json_file")" - say_verbose "specific_version=$specific_version" - if [ -z "$specific_version" ]; then - say_err "Could not resolve version information." - return 1 - fi - - download_link="$(construct_download_link "$azure_feed" "$channel" "$normalized_architecture" "$specific_version")" - say_verbose "Constructed primary named payload URL: $download_link" - - legacy_download_link="$(construct_legacy_download_link "$azure_feed" "$channel" "$normalized_architecture" "$specific_version")" || valid_legacy_download_link=false - - if [ "$valid_legacy_download_link" = true ]; then - say_verbose "Constructed legacy named payload URL: $legacy_download_link" - else - say_verbose "Cound not construct a legacy_download_link; omitting..." - fi - - install_root="$(resolve_installation_path "$install_dir")" - say_verbose "InstallRoot: $install_root" -} - -install_dotnet() { - eval $invocation - local download_failed=false - local asset_name='' - local asset_relative_path='' - - if [[ "$runtime" == "dotnet" ]]; then - asset_relative_path="shared/Microsoft.NETCore.App" - asset_name=".NET Core Runtime" - elif [[ "$runtime" == "aspnetcore" ]]; then - asset_relative_path="shared/Microsoft.AspNetCore.App" - asset_name="ASP.NET Core Runtime" - elif [ -z "$runtime" ]; then - asset_relative_path="sdk" - asset_name=".NET Core SDK" - else - say_err "Invalid value for \$runtime" - return 1 - fi - - # Check if the SDK version is already installed. - if is_dotnet_package_installed "$install_root" "$asset_relative_path" "$specific_version"; then - say "$asset_name version $specific_version is already installed." - return 0 - fi - - mkdir -p "$install_root" - zip_path="$(mktemp "$temporary_file_template")" - say_verbose "Zip path: $zip_path" - - say "Downloading link: $download_link" - - # Failures are normal in the non-legacy case for ultimately legacy downloads. - # Do not output to stderr, since output to stderr is considered an error. - download "$download_link" "$zip_path" 2>&1 || download_failed=true - - # if the download fails, download the legacy_download_link - if [ "$download_failed" = true ]; then - say "Cannot download: $download_link" - - if [ "$valid_legacy_download_link" = true ]; then - download_failed=false - download_link="$legacy_download_link" - zip_path="$(mktemp "$temporary_file_template")" - say_verbose "Legacy zip path: $zip_path" - say "Downloading legacy link: $download_link" - download "$download_link" "$zip_path" 2>&1 || download_failed=true - - if [ "$download_failed" = true ]; then - say "Cannot download: $download_link" - fi - fi - fi - - if [ "$download_failed" = true ]; then - say_err "Could not find/download: \`$asset_name\` with version = $specific_version" - say_err "Refer to: https://aka.ms/dotnet-os-lifecycle for information on .NET Core support" - return 1 - fi - - say "Extracting zip from $download_link" - extract_dotnet_package "$zip_path" "$install_root" - - # Check if the SDK version is installed; if not, fail the installation. - # if the version contains "RTM" or "servicing"; check if a 'release-type' SDK version is installed. - if [[ $specific_version == *"rtm"* || $specific_version == *"servicing"* ]]; then - IFS='-' - read -ra verArr <<< "$specific_version" - release_version="${verArr[0]}" - unset IFS; - say_verbose "Checking installation: version = $release_version" - if is_dotnet_package_installed "$install_root" "$asset_relative_path" "$release_version"; then - return 0 - fi - fi - - # Check if the standard SDK version is installed. - say_verbose "Checking installation: version = $specific_version" - if is_dotnet_package_installed "$install_root" "$asset_relative_path" "$specific_version"; then - return 0 - fi - - say_err "\`$asset_name\` with version = $specific_version failed to install with an unknown error." - return 1 -} - -args=("$@") - -local_version_file_relative_path="/.version" -bin_folder_relative_path="" -temporary_file_template="${TMPDIR:-/tmp}/dotnet.XXXXXXXXX" - -channel="LTS" -version="Latest" -json_file="" -install_dir="" -architecture="" -dry_run=false -no_path=false -no_cdn=false -azure_feed="https://dotnetcli.azureedge.net/dotnet" -uncached_feed="https://dotnetcli.blob.core.windows.net/dotnet" -feed_credential="" -verbose=false -runtime="" -runtime_id="" -override_non_versioned_files=true -non_dynamic_parameters="" - -while [ $# -ne 0 ] -do - name="$1" - case "$name" in - -c|--channel|-[Cc]hannel) - shift - channel="$1" - ;; - -v|--version|-[Vv]ersion) - shift - version="$1" - ;; - -i|--install-dir|-[Ii]nstall[Dd]ir) - shift - install_dir="$1" - ;; - --arch|--architecture|-[Aa]rch|-[Aa]rchitecture) - shift - architecture="$1" - ;; - --shared-runtime|-[Ss]hared[Rr]untime) - say_warning "The --shared-runtime flag is obsolete and may be removed in a future version of this script. The recommended usage is to specify '--runtime dotnet'." - if [ -z "$runtime" ]; then - runtime="dotnet" - fi - ;; - --runtime|-[Rr]untime) - shift - runtime="$1" - if [[ "$runtime" != "dotnet" ]] && [[ "$runtime" != "aspnetcore" ]]; then - say_err "Unsupported value for --runtime: '$1'. Valid values are 'dotnet' and 'aspnetcore'." - if [[ "$runtime" == "windowsdesktop" ]]; then - say_err "WindowsDesktop archives are manufactured for Windows platforms only." - fi - exit 1 - fi - ;; - --dry-run|-[Dd]ry[Rr]un) - dry_run=true - ;; - --no-path|-[Nn]o[Pp]ath) - no_path=true - non_dynamic_parameters+=" $name" - ;; - --verbose|-[Vv]erbose) - verbose=true - non_dynamic_parameters+=" $name" - ;; - --no-cdn|-[Nn]o[Cc]dn) - no_cdn=true - non_dynamic_parameters+=" $name" - ;; - --azure-feed|-[Aa]zure[Ff]eed) - shift - azure_feed="$1" - non_dynamic_parameters+=" $name "\""$1"\""" - ;; - --uncached-feed|-[Uu]ncached[Ff]eed) - shift - uncached_feed="$1" - non_dynamic_parameters+=" $name "\""$1"\""" - ;; - --feed-credential|-[Ff]eed[Cc]redential) - shift - feed_credential="$1" - non_dynamic_parameters+=" $name "\""$1"\""" - ;; - --runtime-id|-[Rr]untime[Ii]d) - shift - runtime_id="$1" - non_dynamic_parameters+=" $name "\""$1"\""" - ;; - --jsonfile|-[Jj][Ss]on[Ff]ile) - shift - json_file="$1" - ;; - --skip-non-versioned-files|-[Ss]kip[Nn]on[Vv]ersioned[Ff]iles) - override_non_versioned_files=false - non_dynamic_parameters+=" $name" - ;; - -?|--?|-h|--help|-[Hh]elp) - script_name="$(basename "$0")" - echo ".NET Tools Installer" - echo "Usage: $script_name [-c|--channel ] [-v|--version ] [-p|--prefix ]" - echo " $script_name -h|-?|--help" - echo "" - echo "$script_name is a simple command line interface for obtaining dotnet cli." - echo "" - echo "Options:" - echo " -c,--channel Download from the channel specified, Defaults to \`$channel\`." - echo " -Channel" - echo " Possible values:" - echo " - Current - most current release" - echo " - LTS - most current supported release" - echo " - 2-part version in a format A.B - represents a specific release" - echo " examples: 2.0; 1.0" - echo " - Branch name" - echo " examples: release/2.0.0; Master" - echo " Note: The version parameter overrides the channel parameter." - echo " -v,--version Use specific VERSION, Defaults to \`$version\`." - echo " -Version" - echo " Possible values:" - echo " - latest - most latest build on specific channel" - echo " - coherent - most latest coherent build on specific channel" - echo " coherent applies only to SDK downloads" - echo " - 3-part version in a format A.B.C - represents specific version of build" - echo " examples: 2.0.0-preview2-006120; 1.1.0" - echo " -i,--install-dir Install under specified location (see Install Location below)" - echo " -InstallDir" - echo " --architecture Architecture of dotnet binaries to be installed, Defaults to \`$architecture\`." - echo " --arch,-Architecture,-Arch" - echo " Possible values: x64, arm, and arm64" - echo " --runtime Installs a shared runtime only, without the SDK." - echo " -Runtime" - echo " Possible values:" - echo " - dotnet - the Microsoft.NETCore.App shared runtime" - echo " - aspnetcore - the Microsoft.AspNetCore.App shared runtime" - echo " --dry-run,-DryRun Do not perform installation. Display download link." - echo " --no-path, -NoPath Do not set PATH for the current process." - echo " --verbose,-Verbose Display diagnostics information." - echo " --azure-feed,-AzureFeed Azure feed location. Defaults to $azure_feed, This parameter typically is not changed by the user." - echo " --uncached-feed,-UncachedFeed Uncached feed location. This parameter typically is not changed by the user." - echo " --feed-credential,-FeedCredential Azure feed shared access token. This parameter typically is not specified." - echo " --skip-non-versioned-files Skips non-versioned files if they already exist, such as the dotnet executable." - echo " -SkipNonVersionedFiles" - echo " --no-cdn,-NoCdn Disable downloading from the Azure CDN, and use the uncached feed directly." - echo " --jsonfile Determines the SDK version from a user specified global.json file." - echo " Note: global.json must have a value for 'SDK:Version'" - echo " --runtime-id Installs the .NET Tools for the given platform (use linux-x64 for portable linux)." - echo " -RuntimeId" - echo " -?,--?,-h,--help,-Help Shows this help message" - echo "" - echo "Obsolete parameters:" - echo " --shared-runtime The recommended alternative is '--runtime dotnet'." - echo " This parameter is obsolete and may be removed in a future version of this script." - echo " Installs just the shared runtime bits, not the entire SDK." - echo "" - echo "Install Location:" - echo " Location is chosen in following order:" - echo " - --install-dir option" - echo " - Environmental variable DOTNET_INSTALL_DIR" - echo " - $HOME/.dotnet" - exit 0 - ;; - *) - say_err "Unknown argument \`$name\`" - exit 1 - ;; - esac - - shift -done - -if [ "$no_cdn" = true ]; then - azure_feed="$uncached_feed" -fi - -check_min_reqs -calculate_vars -script_name=$(basename "$0") - -if [ "$dry_run" = true ]; then - say "Payload URLs:" - say "Primary named payload URL: $download_link" - if [ "$valid_legacy_download_link" = true ]; then - say "Legacy named payload URL: $legacy_download_link" - fi - repeatable_command="./$script_name --version "\""$specific_version"\"" --install-dir "\""$install_root"\"" --architecture "\""$normalized_architecture"\""" - if [[ "$runtime" == "dotnet" ]]; then - repeatable_command+=" --runtime "\""dotnet"\""" - elif [[ "$runtime" == "aspnetcore" ]]; then - repeatable_command+=" --runtime "\""aspnetcore"\""" - fi - repeatable_command+="$non_dynamic_parameters" - say "Repeatable invocation: $repeatable_command" - exit 0 -fi - -check_pre_reqs -install_dotnet - -bin_path="$(get_absolute_path "$(combine_paths "$install_root" "$bin_folder_relative_path")")" -if [ "$no_path" = false ]; then - say "Adding to current process PATH: \`$bin_path\`. Note: This change will be visible only when sourcing script." - export PATH="$bin_path":"$PATH" -else - say "Binaries of dotnet can be found in $bin_path" -fi - -say "Installation finished successfully." diff --git a/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java b/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java index 7bf9736c2..fd8db7a4a 100644 --- a/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java +++ b/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java @@ -23,7 +23,7 @@ public class CSharpPluginTest { private CSharpPlugin csPlugin; public CSharpPluginTest() { - //TestUtils.skipIfNotAvailable("dotnet"); + TestUtils.skipIfNotAvailable("dotnet"); } @Before From d851cbbdf6d09ebd6204188f053d7726c5702950 Mon Sep 17 00:00:00 2001 From: chenhuiz Date: Wed, 20 May 2020 16:24:38 +0300 Subject: [PATCH 14/61] fixed descParserTest --- .../langs/csharp/CSharpExerciseDescParserTest.java | 13 ++++++------- .../.tmc_available_points.json | 13 +++++-------- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpExerciseDescParserTest.java b/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpExerciseDescParserTest.java index 9f82c6176..78084777b 100644 --- a/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpExerciseDescParserTest.java +++ b/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpExerciseDescParserTest.java @@ -16,12 +16,12 @@ public class CSharpExerciseDescParserTest { private final Path allPassedSampleDir; - private final Path someFailedSampleDir; + private final Path noPointsSampleDir; public CSharpExerciseDescParserTest() { Path desc_samples_dir = TestUtils.getPath(getClass(), "Desc_samples"); allPassedSampleDir = desc_samples_dir.resolve("all_tests_passed_sample"); - someFailedSampleDir = desc_samples_dir.resolve("some_tests_failed_sample"); + noPointsSampleDir = desc_samples_dir.resolve("no_points_sample"); } private void testDescAsExpected(TestDesc desc, String name, String[] points) { @@ -38,13 +38,12 @@ public void testDescParsePointsCorrectly() throws IOException { } @Test - public void testThatParseWorksForNoPointsJson() throws IOException { - ImmutableList descs = new CSharpExerciseDescParser(someFailedSampleDir).parse(); + public void testDescParseEmptyPointsCorrectly() throws IOException { + ImmutableList descs = new CSharpExerciseDescParser(noPointsSampleDir).parse(); testDescAsExpected(descs.get(0), - "PartiallyFailingSampleTests.ProgramTest.TestCheckFinePassed", - new String[]{"2", "2.2"}); + "NoPoints.ProgramTest.TestCheckSameFailed", new String[]{}); testDescAsExpected(descs.get(1), - "PartiallyFailingSampleTests.ProgramTest.TestCheckFinePassed", new String[]{}); + "NoPoints.ProgramTest.TestCheckFinePassed", new String[]{}); } } diff --git a/tmc-langs-csharp/src/test/resources/Desc_samples/some_tests_failed_sample/.tmc_available_points.json b/tmc-langs-csharp/src/test/resources/Desc_samples/some_tests_failed_sample/.tmc_available_points.json index be6e4e9cd..c32e59df0 100644 --- a/tmc-langs-csharp/src/test/resources/Desc_samples/some_tests_failed_sample/.tmc_available_points.json +++ b/tmc-langs-csharp/src/test/resources/Desc_samples/some_tests_failed_sample/.tmc_available_points.json @@ -1,11 +1,8 @@ { - "PartiallyFailingSampleTests.ProgramTest.TestCheckSameFailed": [ - "2", - "2.1" + "NoPoints.ProgramTest.TestCheckSameFailed": [ + ], - "PartiallyFailingSampleTests.ProgramTest.TestCheckFinePassed": [ - "2", - "2.2" - ] -} + "NoPoints.ProgramTest.TestCheckFinePassed": [ + ] +} \ No newline at end of file From da3a7b091948ab87df600d2c0a96bf9b4e0ccc4a Mon Sep 17 00:00:00 2001 From: chenhuiz Date: Wed, 20 May 2020 16:33:17 +0300 Subject: [PATCH 15/61] fixed tests --- .../.tmc_available_points.json | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tmc-langs-csharp/src/test/resources/Desc_samples/{some_tests_failed_sample => no_points_sample}/.tmc_available_points.json (100%) diff --git a/tmc-langs-csharp/src/test/resources/Desc_samples/some_tests_failed_sample/.tmc_available_points.json b/tmc-langs-csharp/src/test/resources/Desc_samples/no_points_sample/.tmc_available_points.json similarity index 100% rename from tmc-langs-csharp/src/test/resources/Desc_samples/some_tests_failed_sample/.tmc_available_points.json rename to tmc-langs-csharp/src/test/resources/Desc_samples/no_points_sample/.tmc_available_points.json From cd9f2c87e18c6e8fa2c9bea0b0b28aa15957c4f6 Mon Sep 17 00:00:00 2001 From: PPeltola Date: Wed, 20 May 2020 16:39:13 +0300 Subject: [PATCH 16/61] changed dotnet instal method to the obvious one --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index bb8f82c2c..4d3b75c2a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -28,7 +28,7 @@ before_install: - sudo chmod 277 /usr/local/lib/R/site-library - Rscript -e 'install.packages(c("devtools","testthat"),repos="http://cran.us.r-project.org")' - Rscript -e 'devtools::install_github("RTMC/tmc-r-tester/tmcRtestrunner")' - - curl -sSL https://dot.net/v1/dotnet-install.sh | bash /dev/stdin + - sudo apt-get install dotnet-sdk-3.1 -y -qq - wget https://github.com/TMC-C/tmc-csharp-runner/releases/download/v1.0.0/tmc-csharp-runner.tar.gz -O /tmp/tmc-csharp-runner.tar.gz - tar -xvf /tmp/tmc-csharp-runner.tar.gz - export TMC_CSHARP_BOOTSTRAP_PATH=/tmp/publish/Bootstrap.dll From c9a96e6ccab1107acf14fceb7d478018eda67f94 Mon Sep 17 00:00:00 2001 From: chenhuiz Date: Wed, 20 May 2020 16:56:10 +0300 Subject: [PATCH 17/61] fixed checkstyle --- .../langs/csharp/CSharpExerciseDescParserTest.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpExerciseDescParserTest.java b/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpExerciseDescParserTest.java index 78084777b..82f6c1e7f 100644 --- a/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpExerciseDescParserTest.java +++ b/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpExerciseDescParserTest.java @@ -19,9 +19,9 @@ public class CSharpExerciseDescParserTest { private final Path noPointsSampleDir; public CSharpExerciseDescParserTest() { - Path desc_samples_dir = TestUtils.getPath(getClass(), "Desc_samples"); - allPassedSampleDir = desc_samples_dir.resolve("all_tests_passed_sample"); - noPointsSampleDir = desc_samples_dir.resolve("no_points_sample"); + Path descSamplesDir = TestUtils.getPath(getClass(), "Desc_samples"); + allPassedSampleDir = descSamplesDir.resolve("all_tests_passed_sample"); + noPointsSampleDir = descSamplesDir.resolve("no_points_sample"); } private void testDescAsExpected(TestDesc desc, String name, String[] points) { @@ -33,8 +33,10 @@ private void testDescAsExpected(TestDesc desc, String name, String[] points) { public void testDescParsePointsCorrectly() throws IOException { ImmutableList descs = new CSharpExerciseDescParser(allPassedSampleDir).parse(); - testDescAsExpected(descs.get(0), "PassingSampleTests.ProgramTest.TestGetName", new String[]{"1", "1.1"}); - testDescAsExpected(descs.get(1), "PassingSampleTests.ProgramTest.TestGetYear", new String[]{"1", "1.2"}); + testDescAsExpected(descs.get(0), "PassingSampleTests.ProgramTest.TestGetName", + new String[]{"1", "1.1"}); + testDescAsExpected(descs.get(1), "PassingSampleTests.ProgramTest.TestGetYear", + new String[]{"1", "1.2"}); } @Test From cab4fef49ca7e8e51940db1616468709c9029259 Mon Sep 17 00:00:00 2001 From: PPeltola Date: Thu, 21 May 2020 11:10:24 +0300 Subject: [PATCH 18/61] added travis install steps to hopefully install dotnet --- .travis.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.travis.yml b/.travis.yml index 4d3b75c2a..5c9538d72 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,6 +21,9 @@ env: before_install: - sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9 - echo "deb https://cloud.r-project.org/bin/linux/ubuntu trusty/" | sudo tee -a /etc/apt/sources.list + - wget https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb + - sudo dpkg -i packages-microsoft-prod.deb + - sudo add-apt-repository universe - sudo add-apt-repository --yes ppa:beineri/opt-qt591-trusty - sudo apt-get update -qq - sudo apt-get install r-base -y -qq @@ -28,6 +31,8 @@ before_install: - sudo chmod 277 /usr/local/lib/R/site-library - Rscript -e 'install.packages(c("devtools","testthat"),repos="http://cran.us.r-project.org")' - Rscript -e 'devtools::install_github("RTMC/tmc-r-tester/tmcRtestrunner")' + - sudo apt-get install apt-transport-https -y -qq + - sudo apt-get update -qq - sudo apt-get install dotnet-sdk-3.1 -y -qq - wget https://github.com/TMC-C/tmc-csharp-runner/releases/download/v1.0.0/tmc-csharp-runner.tar.gz -O /tmp/tmc-csharp-runner.tar.gz - tar -xvf /tmp/tmc-csharp-runner.tar.gz From db47d3bf9461d130f551e11bf0610ca2a928fd76 Mon Sep 17 00:00:00 2001 From: PPeltola Date: Thu, 21 May 2020 11:27:55 +0300 Subject: [PATCH 19/61] changed dotnet version to correct one --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 5c9538d72..38daa20fa 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,7 +21,7 @@ env: before_install: - sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9 - echo "deb https://cloud.r-project.org/bin/linux/ubuntu trusty/" | sudo tee -a /etc/apt/sources.list - - wget https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb + - wget https://packages.microsoft.com/config/ubuntu/14.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb - sudo dpkg -i packages-microsoft-prod.deb - sudo add-apt-repository universe - sudo add-apt-repository --yes ppa:beineri/opt-qt591-trusty From e8a36ced59014aa44d1d47d29602a923e739d371 Mon Sep 17 00:00:00 2001 From: PPeltola Date: Thu, 21 May 2020 11:44:15 +0300 Subject: [PATCH 20/61] trying to fix travis dotnet installation ep. 74 --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 38daa20fa..1dc422270 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,6 +8,8 @@ addons: apt: sources: - deadsnakes + - sourceline: 'deb [arch=amd64] https://apt-mo.trafficmanager.net/repos/dotnet/ trusty main' + key_url: 'https://apt-mo.trafficmanager.net/repos/dotnet/dists/trusty/Release.gpg' packages: - valgrind - check From 4e80804ae09fc2da23e1fe4d5a7f514c43c668f9 Mon Sep 17 00:00:00 2001 From: PPeltola Date: Thu, 21 May 2020 11:53:11 +0300 Subject: [PATCH 21/61] trying to fix travis dotnet installation ep. 75 --- .travis.yml | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index 1dc422270..0814a3566 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,12 +8,13 @@ addons: apt: sources: - deadsnakes - - sourceline: 'deb [arch=amd64] https://apt-mo.trafficmanager.net/repos/dotnet/ trusty main' - key_url: 'https://apt-mo.trafficmanager.net/repos/dotnet/dists/trusty/Release.gpg' + - sourceline: 'deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-ubuntu-trusty-prod trusty main' + key_url: 'https://packages.microsoft.com/keys/microsoft.asc' packages: - valgrind - check - python3.4 + - dotnet-sdk-3.1 env: global: - secure: yiW+hXiZEycKFzF19rLlejJX8BTGbncSisBHyE8uulZee5n7UVGXnG1yvt9+6hz0nvMbxL7r1Daql0xxRHXUFB9VYVUKhF0ycHyJO5ze87U51mlIKAL8UnCkmxpkHNdxY45olEdK+mEbZBtot67nenlwGDfxLI7laITkR8IBAvY= @@ -23,9 +24,6 @@ env: before_install: - sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9 - echo "deb https://cloud.r-project.org/bin/linux/ubuntu trusty/" | sudo tee -a /etc/apt/sources.list - - wget https://packages.microsoft.com/config/ubuntu/14.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb - - sudo dpkg -i packages-microsoft-prod.deb - - sudo add-apt-repository universe - sudo add-apt-repository --yes ppa:beineri/opt-qt591-trusty - sudo apt-get update -qq - sudo apt-get install r-base -y -qq @@ -34,8 +32,6 @@ before_install: - Rscript -e 'install.packages(c("devtools","testthat"),repos="http://cran.us.r-project.org")' - Rscript -e 'devtools::install_github("RTMC/tmc-r-tester/tmcRtestrunner")' - sudo apt-get install apt-transport-https -y -qq - - sudo apt-get update -qq - - sudo apt-get install dotnet-sdk-3.1 -y -qq - wget https://github.com/TMC-C/tmc-csharp-runner/releases/download/v1.0.0/tmc-csharp-runner.tar.gz -O /tmp/tmc-csharp-runner.tar.gz - tar -xvf /tmp/tmc-csharp-runner.tar.gz - export TMC_CSHARP_BOOTSTRAP_PATH=/tmp/publish/Bootstrap.dll From dff62a4cdb760973901024454b17cc79aaec0b7e Mon Sep 17 00:00:00 2001 From: PPeltola Date: Thu, 21 May 2020 12:30:47 +0300 Subject: [PATCH 22/61] changing ubuntu version, probably breaking stuff --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 0814a3566..959f13a33 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ language: java sudo: false -dist: trusty +dist: xenial cache: directories: - "$HOME/.m2" From 9c4793438b7244196c1d7861a16fdbb4790c86e3 Mon Sep 17 00:00:00 2001 From: PPeltola Date: Thu, 21 May 2020 12:31:56 +0300 Subject: [PATCH 23/61] update dotnet source --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 959f13a33..381cab11d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,7 +8,7 @@ addons: apt: sources: - deadsnakes - - sourceline: 'deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-ubuntu-trusty-prod trusty main' + - sourceline: 'deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-ubuntu-xenial-prod xenial main' key_url: 'https://packages.microsoft.com/keys/microsoft.asc' packages: - valgrind From 222aeb453066ebee45c66d563b64f68040c18374 Mon Sep 17 00:00:00 2001 From: PPeltola Date: Thu, 21 May 2020 12:38:48 +0300 Subject: [PATCH 24/61] update r-langs dependencies --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 381cab11d..8d2059411 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,8 +23,8 @@ env: before_install: - sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9 - - echo "deb https://cloud.r-project.org/bin/linux/ubuntu trusty/" | sudo tee -a /etc/apt/sources.list - - sudo add-apt-repository --yes ppa:beineri/opt-qt591-trusty + - echo "deb https://cloud.r-project.org/bin/linux/ubuntu xenial/" | sudo tee -a /etc/apt/sources.list + - sudo add-apt-repository --yes ppa:beineri/opt-qt591-xenial - sudo apt-get update -qq - sudo apt-get install r-base -y -qq - sudo apt-get install qt59base -qq From 5e4f3e4eb4efc226566ee4a00128860d87144dfe Mon Sep 17 00:00:00 2001 From: PPeltola Date: Thu, 21 May 2020 13:04:49 +0300 Subject: [PATCH 25/61] updated csharp-runner version --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 8d2059411..54b695fa0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -32,7 +32,7 @@ before_install: - Rscript -e 'install.packages(c("devtools","testthat"),repos="http://cran.us.r-project.org")' - Rscript -e 'devtools::install_github("RTMC/tmc-r-tester/tmcRtestrunner")' - sudo apt-get install apt-transport-https -y -qq - - wget https://github.com/TMC-C/tmc-csharp-runner/releases/download/v1.0.0/tmc-csharp-runner.tar.gz -O /tmp/tmc-csharp-runner.tar.gz + - wget https://github.com/TMC-C/tmc-csharp-runner/releases/download/v1.0.1/tmc-csharp-runner.tar.gz -O /tmp/tmc-csharp-runner.tar.gz - tar -xvf /tmp/tmc-csharp-runner.tar.gz - export TMC_CSHARP_BOOTSTRAP_PATH=/tmp/publish/Bootstrap.dll - export PATH=$PATH:$PWD/bin From afc1cd25e9841af08bf5eb91ae91c9df57848849 Mon Sep 17 00:00:00 2001 From: PPeltola Date: Thu, 21 May 2020 14:20:08 +0300 Subject: [PATCH 26/61] testing travis workaround --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 54b695fa0..5423f6efb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -34,6 +34,7 @@ before_install: - sudo apt-get install apt-transport-https -y -qq - wget https://github.com/TMC-C/tmc-csharp-runner/releases/download/v1.0.1/tmc-csharp-runner.tar.gz -O /tmp/tmc-csharp-runner.tar.gz - tar -xvf /tmp/tmc-csharp-runner.tar.gz + - export MSBUILD_EXE_PATH=/usr/share/dotnet/sdk/3.1.202/MSBuild.dll - export TMC_CSHARP_BOOTSTRAP_PATH=/tmp/publish/Bootstrap.dll - export PATH=$PATH:$PWD/bin - source /opt/qt59/bin/qt59-env.sh From d8309e6923199dd259823170bddfd88e7107c4cb Mon Sep 17 00:00:00 2001 From: PPeltola Date: Thu, 21 May 2020 15:11:53 +0300 Subject: [PATCH 27/61] i did a stupid before, fixed i think --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5423f6efb..90a44dc6c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -34,8 +34,8 @@ before_install: - sudo apt-get install apt-transport-https -y -qq - wget https://github.com/TMC-C/tmc-csharp-runner/releases/download/v1.0.1/tmc-csharp-runner.tar.gz -O /tmp/tmc-csharp-runner.tar.gz - tar -xvf /tmp/tmc-csharp-runner.tar.gz - - export MSBUILD_EXE_PATH=/usr/share/dotnet/sdk/3.1.202/MSBuild.dll - - export TMC_CSHARP_BOOTSTRAP_PATH=/tmp/publish/Bootstrap.dll + - export MSBUILD_EXE_PATH="/usr/share/dotnet/sdk/3.1.202/MSBuild.dll" + - export TMC_CSHARP_BOOTSTRAP_PATH="/tmp/publish/Bootstrap.dll" - export PATH=$PATH:$PWD/bin - source /opt/qt59/bin/qt59-env.sh - export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$PWD/lib From 6adf9969e0dde6a21ecbed3491298fdcb9872b4e Mon Sep 17 00:00:00 2001 From: PPeltola Date: Thu, 21 May 2020 15:34:58 +0300 Subject: [PATCH 28/61] Fixed the tar extracting to correct file (figuring this out only took like 4 hours) --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 90a44dc6c..a30858c89 100644 --- a/.travis.yml +++ b/.travis.yml @@ -33,7 +33,7 @@ before_install: - Rscript -e 'devtools::install_github("RTMC/tmc-r-tester/tmcRtestrunner")' - sudo apt-get install apt-transport-https -y -qq - wget https://github.com/TMC-C/tmc-csharp-runner/releases/download/v1.0.1/tmc-csharp-runner.tar.gz -O /tmp/tmc-csharp-runner.tar.gz - - tar -xvf /tmp/tmc-csharp-runner.tar.gz + - tar -xf /tmp/tmc-csharp-runner.tar.gz -C /tmp - export MSBUILD_EXE_PATH="/usr/share/dotnet/sdk/3.1.202/MSBuild.dll" - export TMC_CSHARP_BOOTSTRAP_PATH="/tmp/publish/Bootstrap.dll" - export PATH=$PATH:$PWD/bin From fd7597685158d05e21cd16ceda537f69eadb4f35 Mon Sep 17 00:00:00 2001 From: PPeltola Date: Thu, 21 May 2020 15:52:06 +0300 Subject: [PATCH 29/61] try the automatic setting of msbuild path --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index a30858c89..bae44b1e2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -34,7 +34,6 @@ before_install: - sudo apt-get install apt-transport-https -y -qq - wget https://github.com/TMC-C/tmc-csharp-runner/releases/download/v1.0.1/tmc-csharp-runner.tar.gz -O /tmp/tmc-csharp-runner.tar.gz - tar -xf /tmp/tmc-csharp-runner.tar.gz -C /tmp - - export MSBUILD_EXE_PATH="/usr/share/dotnet/sdk/3.1.202/MSBuild.dll" - export TMC_CSHARP_BOOTSTRAP_PATH="/tmp/publish/Bootstrap.dll" - export PATH=$PATH:$PWD/bin - source /opt/qt59/bin/qt59-env.sh From 84bdfc217ca52c568e742316425b116cac4c5e9d Mon Sep 17 00:00:00 2001 From: PPeltola Date: Thu, 21 May 2020 16:08:10 +0300 Subject: [PATCH 30/61] didn't work, added back the manual path setting --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index bae44b1e2..a30858c89 100644 --- a/.travis.yml +++ b/.travis.yml @@ -34,6 +34,7 @@ before_install: - sudo apt-get install apt-transport-https -y -qq - wget https://github.com/TMC-C/tmc-csharp-runner/releases/download/v1.0.1/tmc-csharp-runner.tar.gz -O /tmp/tmc-csharp-runner.tar.gz - tar -xf /tmp/tmc-csharp-runner.tar.gz -C /tmp + - export MSBUILD_EXE_PATH="/usr/share/dotnet/sdk/3.1.202/MSBuild.dll" - export TMC_CSHARP_BOOTSTRAP_PATH="/tmp/publish/Bootstrap.dll" - export PATH=$PATH:$PWD/bin - source /opt/qt59/bin/qt59-env.sh From 8e746ec0c32aeabebed6015e0d1f1ba40bc1a205 Mon Sep 17 00:00:00 2001 From: PPeltola Date: Thu, 21 May 2020 20:13:03 +0300 Subject: [PATCH 31/61] print path in tests --- .../java/fi/helsinki/cs/tmc/langs/csharp/CSharpPlugin.java | 4 ++-- .../fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/tmc-langs-csharp/src/main/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPlugin.java b/tmc-langs-csharp/src/main/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPlugin.java index 62e3edcd0..e82ce3807 100644 --- a/tmc-langs-csharp/src/main/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPlugin.java +++ b/tmc-langs-csharp/src/main/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPlugin.java @@ -164,11 +164,11 @@ private void deleteOldResults(Path path) { } private String[] getAvailablePointsCommand() { - return new String[]{"dotnet", getBootstrapPath(), "-p"}; + return new String[]{"dotnet", getBootstrapPath(), "-p --project-dir"}; } private String[] getTestCommand() { - return new String[]{"dotnet", getBootstrapPath(), "-t"}; + return new String[]{"dotnet", getBootstrapPath(), "-t --project-dir"}; } private String getBootstrapPath() { diff --git a/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java b/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java index fd8db7a4a..ef7f133ff 100644 --- a/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java +++ b/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java @@ -47,6 +47,7 @@ public void getStudentFilePolicyReturnsCSharpStudentFilePolicy() { @Test public void testRunTestsPassing() { Path path = TestUtils.getPath(getClass(), "PassingProject"); + System.out.println(path); RunResult runResult = this.csPlugin.runTests(path); assertEquals(RunResult.Status.PASSED, runResult.status); @@ -63,6 +64,7 @@ public void testRunTestsPassing() { @Test public void testRunTestsFailing() { Path path = TestUtils.getPath(getClass(), "FailingProject"); + System.out.println(path); RunResult runResult = this.csPlugin.runTests(path); assertEquals(RunResult.Status.TESTS_FAILED, runResult.status); From e9a180ddcea915bd5527bbab582811c2d36a58c9 Mon Sep 17 00:00:00 2001 From: PPeltola Date: Fri, 22 May 2020 05:00:01 +0300 Subject: [PATCH 32/61] removed unnecessary switches --- .../java/fi/helsinki/cs/tmc/langs/csharp/CSharpPlugin.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tmc-langs-csharp/src/main/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPlugin.java b/tmc-langs-csharp/src/main/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPlugin.java index e82ce3807..62e3edcd0 100644 --- a/tmc-langs-csharp/src/main/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPlugin.java +++ b/tmc-langs-csharp/src/main/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPlugin.java @@ -164,11 +164,11 @@ private void deleteOldResults(Path path) { } private String[] getAvailablePointsCommand() { - return new String[]{"dotnet", getBootstrapPath(), "-p --project-dir"}; + return new String[]{"dotnet", getBootstrapPath(), "-p"}; } private String[] getTestCommand() { - return new String[]{"dotnet", getBootstrapPath(), "-t --project-dir"}; + return new String[]{"dotnet", getBootstrapPath(), "-t"}; } private String getBootstrapPath() { From 86d6d1feb9114c36b4831c6b5414a8c964574f81 Mon Sep 17 00:00:00 2001 From: PPeltola Date: Fri, 22 May 2020 05:19:15 +0300 Subject: [PATCH 33/61] make travis list dotnet path for debugging --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index a30858c89..e0908b243 100644 --- a/.travis.yml +++ b/.travis.yml @@ -28,6 +28,7 @@ before_install: - sudo apt-get update -qq - sudo apt-get install r-base -y -qq - sudo apt-get install qt59base -qq + - dotnet --list-sdks - sudo chmod 277 /usr/local/lib/R/site-library - Rscript -e 'install.packages(c("devtools","testthat"),repos="http://cran.us.r-project.org")' - Rscript -e 'devtools::install_github("RTMC/tmc-r-tester/tmcRtestrunner")' From 1aebac8495ca105a0ce3ea6eabe60ced3b9cbbf2 Mon Sep 17 00:00:00 2001 From: PPeltola Date: Fri, 22 May 2020 05:24:34 +0300 Subject: [PATCH 34/61] update travis msbuild path variable --- .travis.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index e0908b243..fcc3cc4d1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -28,14 +28,13 @@ before_install: - sudo apt-get update -qq - sudo apt-get install r-base -y -qq - sudo apt-get install qt59base -qq - - dotnet --list-sdks - sudo chmod 277 /usr/local/lib/R/site-library - Rscript -e 'install.packages(c("devtools","testthat"),repos="http://cran.us.r-project.org")' - Rscript -e 'devtools::install_github("RTMC/tmc-r-tester/tmcRtestrunner")' - sudo apt-get install apt-transport-https -y -qq - wget https://github.com/TMC-C/tmc-csharp-runner/releases/download/v1.0.1/tmc-csharp-runner.tar.gz -O /tmp/tmc-csharp-runner.tar.gz - tar -xf /tmp/tmc-csharp-runner.tar.gz -C /tmp - - export MSBUILD_EXE_PATH="/usr/share/dotnet/sdk/3.1.202/MSBuild.dll" + - export MSBUILD_EXE_PATH="/usr/share/dotnet/sdk/3.1.300/MSBuild.dll" - export TMC_CSHARP_BOOTSTRAP_PATH="/tmp/publish/Bootstrap.dll" - export PATH=$PATH:$PWD/bin - source /opt/qt59/bin/qt59-env.sh From 05e0efdbfc1e8d6182ad7db29c73bb56ca959b07 Mon Sep 17 00:00:00 2001 From: PPeltola Date: Fri, 22 May 2020 13:59:51 +0300 Subject: [PATCH 35/61] lets break this again for science --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index fcc3cc4d1..bae44b1e2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -34,7 +34,6 @@ before_install: - sudo apt-get install apt-transport-https -y -qq - wget https://github.com/TMC-C/tmc-csharp-runner/releases/download/v1.0.1/tmc-csharp-runner.tar.gz -O /tmp/tmc-csharp-runner.tar.gz - tar -xf /tmp/tmc-csharp-runner.tar.gz -C /tmp - - export MSBUILD_EXE_PATH="/usr/share/dotnet/sdk/3.1.300/MSBuild.dll" - export TMC_CSHARP_BOOTSTRAP_PATH="/tmp/publish/Bootstrap.dll" - export PATH=$PATH:$PWD/bin - source /opt/qt59/bin/qt59-env.sh From 07158d0a211a9f8ae27c1499dbe9f983074e6476 Mon Sep 17 00:00:00 2001 From: PPeltola Date: Fri, 22 May 2020 14:26:11 +0300 Subject: [PATCH 36/61] added debugging prints --- .travis.yml | 1 + .../java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java | 2 ++ 2 files changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index bae44b1e2..a30858c89 100644 --- a/.travis.yml +++ b/.travis.yml @@ -34,6 +34,7 @@ before_install: - sudo apt-get install apt-transport-https -y -qq - wget https://github.com/TMC-C/tmc-csharp-runner/releases/download/v1.0.1/tmc-csharp-runner.tar.gz -O /tmp/tmc-csharp-runner.tar.gz - tar -xf /tmp/tmc-csharp-runner.tar.gz -C /tmp + - export MSBUILD_EXE_PATH="/usr/share/dotnet/sdk/3.1.202/MSBuild.dll" - export TMC_CSHARP_BOOTSTRAP_PATH="/tmp/publish/Bootstrap.dll" - export PATH=$PATH:$PWD/bin - source /opt/qt59/bin/qt59-env.sh diff --git a/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java b/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java index ef7f133ff..d46e91955 100644 --- a/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java +++ b/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java @@ -48,6 +48,8 @@ public void getStudentFilePolicyReturnsCSharpStudentFilePolicy() { public void testRunTestsPassing() { Path path = TestUtils.getPath(getClass(), "PassingProject"); System.out.println(path); + System.out.println(System.getenv("TMC_CSHARP_BOOTSTRAP_PATH")); + System.out.println(System.getenv("MSBUILD_EXE_PATH")); RunResult runResult = this.csPlugin.runTests(path); assertEquals(RunResult.Status.PASSED, runResult.status); From 8450b325861d0c2173ddd3007711652ba9d81af3 Mon Sep 17 00:00:00 2001 From: PPeltola Date: Fri, 22 May 2020 14:36:56 +0300 Subject: [PATCH 37/61] more debug prints for tests --- .../java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java b/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java index d46e91955..f032995e2 100644 --- a/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java +++ b/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java @@ -10,6 +10,7 @@ import fi.helsinki.cs.tmc.langs.domain.TestResult; import fi.helsinki.cs.tmc.langs.io.StudentFilePolicy; import fi.helsinki.cs.tmc.langs.utils.TestUtils; +import java.io.File; import org.junit.Before; import org.junit.Test; @@ -49,7 +50,9 @@ public void testRunTestsPassing() { Path path = TestUtils.getPath(getClass(), "PassingProject"); System.out.println(path); System.out.println(System.getenv("TMC_CSHARP_BOOTSTRAP_PATH")); + System.out.println(new File(System.getenv("TMC_CSHARP_BOOTSTRAP_PATH")).exists()); System.out.println(System.getenv("MSBUILD_EXE_PATH")); + System.out.println(new File(System.getenv("MSBUILD_EXE_PATH")).exists()); RunResult runResult = this.csPlugin.runTests(path); assertEquals(RunResult.Status.PASSED, runResult.status); From e4fb27794456ac301fdb33d9779f2a98815d1a51 Mon Sep 17 00:00:00 2001 From: PPeltola Date: Fri, 22 May 2020 14:50:05 +0300 Subject: [PATCH 38/61] fixed msbuild path version --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index a30858c89..fcc3cc4d1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -34,7 +34,7 @@ before_install: - sudo apt-get install apt-transport-https -y -qq - wget https://github.com/TMC-C/tmc-csharp-runner/releases/download/v1.0.1/tmc-csharp-runner.tar.gz -O /tmp/tmc-csharp-runner.tar.gz - tar -xf /tmp/tmc-csharp-runner.tar.gz -C /tmp - - export MSBUILD_EXE_PATH="/usr/share/dotnet/sdk/3.1.202/MSBuild.dll" + - export MSBUILD_EXE_PATH="/usr/share/dotnet/sdk/3.1.300/MSBuild.dll" - export TMC_CSHARP_BOOTSTRAP_PATH="/tmp/publish/Bootstrap.dll" - export PATH=$PATH:$PWD/bin - source /opt/qt59/bin/qt59-env.sh From 7df84dd59c67da2a4c167a70d448df974a55e9cb Mon Sep 17 00:00:00 2001 From: isokissa3 Date: Mon, 25 May 2020 13:53:19 +0300 Subject: [PATCH 39/61] Print run results on failure --- .../fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java b/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java index f032995e2..ba6d57dc6 100644 --- a/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java +++ b/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java @@ -54,7 +54,7 @@ public void testRunTestsPassing() { System.out.println(System.getenv("MSBUILD_EXE_PATH")); System.out.println(new File(System.getenv("MSBUILD_EXE_PATH")).exists()); RunResult runResult = this.csPlugin.runTests(path); - assertEquals(RunResult.Status.PASSED, runResult.status); + assertEquals(runResult.toString(), RunResult.Status.PASSED, runResult.status); TestResult testResult = runResult.testResults.get(0); assertTrue(testResult.isSuccessful()); @@ -71,7 +71,7 @@ public void testRunTestsFailing() { Path path = TestUtils.getPath(getClass(), "FailingProject"); System.out.println(path); RunResult runResult = this.csPlugin.runTests(path); - assertEquals(RunResult.Status.TESTS_FAILED, runResult.status); + assertEquals(runResult.toString(), RunResult.Status.TESTS_FAILED, runResult.status); TestResult testResult = runResult.testResults.get(0); assertTrue(!testResult.isSuccessful()); From e0dee7d3c8ba99a5d2fc0d5c00d20a9cf915b98c Mon Sep 17 00:00:00 2001 From: isokissa3 Date: Mon, 25 May 2020 14:09:48 +0300 Subject: [PATCH 40/61] Print something actually useaful from the RunResult --- .../java/fi/helsinki/cs/tmc/langs/domain/RunResult.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tmc-langs-framework/src/main/java/fi/helsinki/cs/tmc/langs/domain/RunResult.java b/tmc-langs-framework/src/main/java/fi/helsinki/cs/tmc/langs/domain/RunResult.java index 92731b8e8..02a7a500b 100644 --- a/tmc-langs-framework/src/main/java/fi/helsinki/cs/tmc/langs/domain/RunResult.java +++ b/tmc-langs-framework/src/main/java/fi/helsinki/cs/tmc/langs/domain/RunResult.java @@ -4,6 +4,8 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; +import java.util.stream.Collectors; + /** * The result of running an exercise's test suite against a submission. */ @@ -81,7 +83,10 @@ public String toString() { return "RunResult{" + "status=" + status + ", testResults=" + testResults - + ", logKeys=" + logs.keySet() + + ", logKeys=" + logs.entrySet().stream().collect(Collectors.toMap( + e -> e.getKey(), + e -> new String(e.getValue()) + )) + + '}'; } } From 80ed1daf87d7d7b4c96422386fadacfc8f2ca874 Mon Sep 17 00:00:00 2001 From: isokissa3 Date: Tue, 26 May 2020 13:40:19 +0300 Subject: [PATCH 41/61] Try fixing Travis --- .travis.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index fcc3cc4d1..c96bbe467 100644 --- a/.travis.yml +++ b/.travis.yml @@ -32,9 +32,8 @@ before_install: - Rscript -e 'install.packages(c("devtools","testthat"),repos="http://cran.us.r-project.org")' - Rscript -e 'devtools::install_github("RTMC/tmc-r-tester/tmcRtestrunner")' - sudo apt-get install apt-transport-https -y -qq - - wget https://github.com/TMC-C/tmc-csharp-runner/releases/download/v1.0.1/tmc-csharp-runner.tar.gz -O /tmp/tmc-csharp-runner.tar.gz + - wget https://github.com/TMC-C/tmc-csharp-runner/releases/download/1.0.3/tmc-csharp-runner.tar.gz -O /tmp/tmc-csharp-runner.tar.gz - tar -xf /tmp/tmc-csharp-runner.tar.gz -C /tmp - - export MSBUILD_EXE_PATH="/usr/share/dotnet/sdk/3.1.300/MSBuild.dll" - export TMC_CSHARP_BOOTSTRAP_PATH="/tmp/publish/Bootstrap.dll" - export PATH=$PATH:$PWD/bin - source /opt/qt59/bin/qt59-env.sh From f908ee36241dc66e4d724b058735b7a7f08ccf21 Mon Sep 17 00:00:00 2001 From: isokissa3 Date: Tue, 26 May 2020 14:12:30 +0300 Subject: [PATCH 42/61] Travis debugging --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index c96bbe467..c60ffe73c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -32,7 +32,7 @@ before_install: - Rscript -e 'install.packages(c("devtools","testthat"),repos="http://cran.us.r-project.org")' - Rscript -e 'devtools::install_github("RTMC/tmc-r-tester/tmcRtestrunner")' - sudo apt-get install apt-transport-https -y -qq - - wget https://github.com/TMC-C/tmc-csharp-runner/releases/download/1.0.3/tmc-csharp-runner.tar.gz -O /tmp/tmc-csharp-runner.tar.gz + - wget https://github.com/TMC-C/tmc-csharp-runner/releases/download/1.0.3.1/tmc-csharp-runner.tar.gz -O /tmp/tmc-csharp-runner.tar.gz - tar -xf /tmp/tmc-csharp-runner.tar.gz -C /tmp - export TMC_CSHARP_BOOTSTRAP_PATH="/tmp/publish/Bootstrap.dll" - export PATH=$PATH:$PWD/bin From 86b4dedd6b8e62e5dfa212c68b73bc01ca0b978a Mon Sep 17 00:00:00 2001 From: isokissa3 Date: Tue, 26 May 2020 16:46:56 +0300 Subject: [PATCH 43/61] Try to fix Travis part 333 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index c60ffe73c..5a8f2bad8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -32,7 +32,7 @@ before_install: - Rscript -e 'install.packages(c("devtools","testthat"),repos="http://cran.us.r-project.org")' - Rscript -e 'devtools::install_github("RTMC/tmc-r-tester/tmcRtestrunner")' - sudo apt-get install apt-transport-https -y -qq - - wget https://github.com/TMC-C/tmc-csharp-runner/releases/download/1.0.3.1/tmc-csharp-runner.tar.gz -O /tmp/tmc-csharp-runner.tar.gz + - wget https://github.com/TMC-C/tmc-csharp-runner/releases/download/1.0.4/tmc-csharp-runner.tar.gz -O /tmp/tmc-csharp-runner.tar.gz - tar -xf /tmp/tmc-csharp-runner.tar.gz -C /tmp - export TMC_CSHARP_BOOTSTRAP_PATH="/tmp/publish/Bootstrap.dll" - export PATH=$PATH:$PWD/bin From ba7a80f0d7e57573952f46a0685a029d28934a9d Mon Sep 17 00:00:00 2001 From: PPeltola Date: Wed, 27 May 2020 12:24:12 +0300 Subject: [PATCH 44/61] lets try explicitly defining the msbuild path to be sure --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 5a8f2bad8..b49d42fd0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -35,6 +35,7 @@ before_install: - wget https://github.com/TMC-C/tmc-csharp-runner/releases/download/1.0.4/tmc-csharp-runner.tar.gz -O /tmp/tmc-csharp-runner.tar.gz - tar -xf /tmp/tmc-csharp-runner.tar.gz -C /tmp - export TMC_CSHARP_BOOTSTRAP_PATH="/tmp/publish/Bootstrap.dll" + - export MSBUILD_EXE_PATH="/usr/share/dotnet/sdk/3.1.300/MSBuild.dll" - export PATH=$PATH:$PWD/bin - source /opt/qt59/bin/qt59-env.sh - export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$PWD/lib From 02b098b76e75a686749034e6404af792a28f50b6 Mon Sep 17 00:00:00 2001 From: PPeltola Date: Wed, 27 May 2020 12:40:36 +0300 Subject: [PATCH 45/61] make travis use the automatic runner downloading --- .travis.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index b49d42fd0..164eae823 100644 --- a/.travis.yml +++ b/.travis.yml @@ -32,10 +32,6 @@ before_install: - Rscript -e 'install.packages(c("devtools","testthat"),repos="http://cran.us.r-project.org")' - Rscript -e 'devtools::install_github("RTMC/tmc-r-tester/tmcRtestrunner")' - sudo apt-get install apt-transport-https -y -qq - - wget https://github.com/TMC-C/tmc-csharp-runner/releases/download/1.0.4/tmc-csharp-runner.tar.gz -O /tmp/tmc-csharp-runner.tar.gz - - tar -xf /tmp/tmc-csharp-runner.tar.gz -C /tmp - - export TMC_CSHARP_BOOTSTRAP_PATH="/tmp/publish/Bootstrap.dll" - - export MSBUILD_EXE_PATH="/usr/share/dotnet/sdk/3.1.300/MSBuild.dll" - export PATH=$PATH:$PWD/bin - source /opt/qt59/bin/qt59-env.sh - export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$PWD/lib From 352a97bd42bf7f00fd3b7ee815d6f5c0c6afafb5 Mon Sep 17 00:00:00 2001 From: PPeltola Date: Wed, 27 May 2020 12:51:07 +0300 Subject: [PATCH 46/61] fix and update the runner version download --- .../java/fi/helsinki/cs/tmc/langs/csharp/CSharpPlugin.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tmc-langs-csharp/src/main/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPlugin.java b/tmc-langs-csharp/src/main/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPlugin.java index 742510667..9992570e9 100644 --- a/tmc-langs-csharp/src/main/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPlugin.java +++ b/tmc-langs-csharp/src/main/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPlugin.java @@ -55,6 +55,8 @@ public class CSharpPlugin extends AbstractLanguagePlugin { private static final Path SRC_PATH = Paths.get("src"); + private static final String RUNNER_ZIP_DOWNLOAD_URL = + "https://github.com/TMC-C/tmc-csharp-runner/releases/download/1.0.4/tmc-csharp-runner.zip"; private static final String CANNOT_RUN_TESTS_MESSAGE = "Failed to run tests."; private static final String CANNOT_PARSE_TEST_RESULTS_MESSAGE = "Failed to read test results."; @@ -265,7 +267,7 @@ private void ensureRunnerAvailability() { try { if (!Files.exists(jarPath.resolve(Paths.get("tmc-csharp-runner", "Bootstrap.dll")))) { File runnerZip = File.createTempFile("tmc-csharp-runner", null); - FileUtils.copyURLToFile(new URL("https://github.com/TMC-C/tmc-csharp-runner/releases/download/v1.0.2/tmc-csharp-runner.zip"), runnerZip); + FileUtils.copyURLToFile(new URL(RUNNER_ZIP_DOWNLOAD_URL), runnerZip); File runnerDir = jarPath.resolve("tmc-csharp-runner").toFile(); runnerDir.mkdir(); From fb8880016496dce067159ab95b5cae03bd3df9ea Mon Sep 17 00:00:00 2001 From: PPeltola Date: Wed, 27 May 2020 14:32:27 +0300 Subject: [PATCH 47/61] added debug prints for travis debugging --- .../cs/tmc/langs/csharp/CSharpPlugin.java | 45 +++++++++++-------- .../cs/tmc/langs/csharp/CSharpPluginTest.java | 11 +++-- 2 files changed, 31 insertions(+), 25 deletions(-) diff --git a/tmc-langs-csharp/src/main/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPlugin.java b/tmc-langs-csharp/src/main/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPlugin.java index 9992570e9..43309b1c9 100644 --- a/tmc-langs-csharp/src/main/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPlugin.java +++ b/tmc-langs-csharp/src/main/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPlugin.java @@ -55,8 +55,8 @@ public class CSharpPlugin extends AbstractLanguagePlugin { private static final Path SRC_PATH = Paths.get("src"); - private static final String RUNNER_ZIP_DOWNLOAD_URL = - "https://github.com/TMC-C/tmc-csharp-runner/releases/download/1.0.4/tmc-csharp-runner.zip"; + private static final String RUNNER_ZIP_DOWNLOAD_URL + = "https://github.com/TMC-C/tmc-csharp-runner/releases/download/1.0.4/tmc-csharp-runner.zip"; private static final String CANNOT_RUN_TESTS_MESSAGE = "Failed to run tests."; private static final String CANNOT_PARSE_TEST_RESULTS_MESSAGE = "Failed to read test results."; @@ -73,9 +73,9 @@ public class CSharpPlugin extends AbstractLanguagePlugin { private static final String CANNOT_CLEANUP_DIR = "Failed to run cleanup task on a directory."; private static final String RUNNER_DL_FAILED_MESSAGE = "Failed to download the CSharp Runner."; private static final String UNZIP_FAILED_MESSAGE = "Failed to unzip the CSharp Runner."; - private static final String JARPATH_DECODE_FAILED_MESSAGE + private static final String JARPATH_DECODE_FAILED_MESSAGE = "Failed to decode the langs jar file path"; - private static final String JARPATH_PARSE_FAILED_MESSAGE + private static final String JARPATH_PARSE_FAILED_MESSAGE = "Failed to parse the langs jar file path"; private static Logger log = LoggerFactory.getLogger(CSharpPlugin.class); @@ -138,7 +138,13 @@ public RunResult runTests(Path path) { try { ProcessResult result = runner.call(); - + + // Begin debug snippet + System.out.println("ProcessResult status code: " + result.statusCode); + System.out.println("ProcessResult output: " + result.output); + System.out.println("ProcessResult error output: " + result.errorOutput); + //End debug snippet + if (result.statusCode != 0) { log.error(COMPILATION_FAILED_MESSAGE); return runResultFromFailedCompilation(result); @@ -212,18 +218,18 @@ private String[] getTestCommand() { private String getBootstrapPath() { ensureRunnerAvailability(); - + Path jarPath = getJarPath(); - - if (jarPath != null - && Files.exists(jarPath.resolve(Paths.get("tmc-csharp-runner", "Bootstrap.dll")))) { + + if (jarPath != null + && Files.exists(jarPath.resolve(Paths.get("tmc-csharp-runner", "Bootstrap.dll")))) { return jarPath.resolve(Paths.get("tmc-csharp-runner", "Bootstrap.dll")).toString(); } else { System.out.println("Runner downloading failed, defaulting to environment variable"); } - + String envVarPath = System.getenv("TMC_CSHARP_BOOTSTRAP_PATH"); - + if (envVarPath != null) { return envVarPath; } @@ -261,14 +267,15 @@ private RunResult runResultFromFailedCompilation(ProcessResult result) { private void ensureRunnerAvailability() { Path jarPath = getJarPath(); - - if (jarPath == null) { return; } - + + if (jarPath == null) { + return; + } + try { if (!Files.exists(jarPath.resolve(Paths.get("tmc-csharp-runner", "Bootstrap.dll")))) { File runnerZip = File.createTempFile("tmc-csharp-runner", null); FileUtils.copyURLToFile(new URL(RUNNER_ZIP_DOWNLOAD_URL), runnerZip); - File runnerDir = jarPath.resolve("tmc-csharp-runner").toFile(); runnerDir.mkdir(); unzip(runnerZip, runnerDir); @@ -278,11 +285,11 @@ private void ensureRunnerAvailability() { log.error(RUNNER_DL_FAILED_MESSAGE, e); } } - + private Path getJarPath() { - String jarPathString - = CSharpPlugin.class.getProtectionDomain().getCodeSource().getLocation().getPath(); - + String jarPathString + = CSharpPlugin.class.getProtectionDomain().getCodeSource().getLocation().getPath(); + try { String decodedPath = URLDecoder.decode(jarPathString, "UTF-8"); diff --git a/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java b/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java index ba6d57dc6..1ae4ba285 100644 --- a/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java +++ b/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java @@ -10,7 +10,6 @@ import fi.helsinki.cs.tmc.langs.domain.TestResult; import fi.helsinki.cs.tmc.langs.io.StudentFilePolicy; import fi.helsinki.cs.tmc.langs.utils.TestUtils; -import java.io.File; import org.junit.Before; import org.junit.Test; @@ -48,11 +47,11 @@ public void getStudentFilePolicyReturnsCSharpStudentFilePolicy() { @Test public void testRunTestsPassing() { Path path = TestUtils.getPath(getClass(), "PassingProject"); - System.out.println(path); - System.out.println(System.getenv("TMC_CSHARP_BOOTSTRAP_PATH")); - System.out.println(new File(System.getenv("TMC_CSHARP_BOOTSTRAP_PATH")).exists()); - System.out.println(System.getenv("MSBUILD_EXE_PATH")); - System.out.println(new File(System.getenv("MSBUILD_EXE_PATH")).exists()); +// System.out.println(path); +// System.out.println(System.getenv("TMC_CSHARP_BOOTSTRAP_PATH")); +// System.out.println(new File(System.getenv("TMC_CSHARP_BOOTSTRAP_PATH")).exists()); +// System.out.println(System.getenv("MSBUILD_EXE_PATH")); +// System.out.println(new File(System.getenv("MSBUILD_EXE_PATH")).exists()); RunResult runResult = this.csPlugin.runTests(path); assertEquals(runResult.toString(), RunResult.Status.PASSED, runResult.status); From 8ee01ef6ce4f5eeef02a90d6b432cc388aef7429 Mon Sep 17 00:00:00 2001 From: isokissa3 Date: Wed, 27 May 2020 17:11:38 +0300 Subject: [PATCH 48/61] Update runner version --- .../main/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPlugin.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tmc-langs-csharp/src/main/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPlugin.java b/tmc-langs-csharp/src/main/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPlugin.java index 43309b1c9..c4f1e8a99 100644 --- a/tmc-langs-csharp/src/main/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPlugin.java +++ b/tmc-langs-csharp/src/main/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPlugin.java @@ -56,7 +56,7 @@ public class CSharpPlugin extends AbstractLanguagePlugin { private static final Path SRC_PATH = Paths.get("src"); private static final String RUNNER_ZIP_DOWNLOAD_URL - = "https://github.com/TMC-C/tmc-csharp-runner/releases/download/1.0.4/tmc-csharp-runner.zip"; + = "https://github.com/TMC-C/tmc-csharp-runner/releases/download/1.0.5/tmc-csharp-runner.zip"; private static final String CANNOT_RUN_TESTS_MESSAGE = "Failed to run tests."; private static final String CANNOT_PARSE_TEST_RESULTS_MESSAGE = "Failed to read test results."; From cc407afae918fa87fd590bafee33ab4b64e7589c Mon Sep 17 00:00:00 2001 From: Tubaias Date: Wed, 27 May 2020 17:37:50 +0300 Subject: [PATCH 49/61] more plugin tests --- .../cs/tmc/langs/csharp/CSharpPlugin.java | 14 ++-- .../cs/tmc/langs/csharp/CSharpPluginTest.java | 74 ++++++++++++++++--- .../NonCompilingSample.csproj | 8 ++ .../src/NonCompilingSample/Program.cs | 17 +++++ .../NonCompilingSampleTests.csproj | 21 ++++++ .../NonCompilingSampleTests/ProgramTest.cs | 25 +++++++ .../PythonProject/src/newpythonproject.py | 6 ++ .../resources/PythonProject/test/__init__.py | 0 .../resources/PythonProject/test/test_new.py | 14 ++++ .../resources/PythonProject/test/test_two.py | 17 +++++ .../PythonProject/test/tmc_test_results.json | 1 + .../resources/PythonProject/tmc/__init__.py | 2 + .../resources/PythonProject/tmc/__main__.py | 11 +++ .../resources/PythonProject/tmc/points.py | 50 +++++++++++++ .../resources/PythonProject/tmc/result.py | 52 +++++++++++++ .../resources/PythonProject/tmc/runner.py | 32 ++++++++ 16 files changed, 329 insertions(+), 15 deletions(-) create mode 100644 tmc-langs-csharp/src/test/resources/NonCompilingProject/src/NonCompilingSample/NonCompilingSample.csproj create mode 100644 tmc-langs-csharp/src/test/resources/NonCompilingProject/src/NonCompilingSample/Program.cs create mode 100644 tmc-langs-csharp/src/test/resources/NonCompilingProject/test/NonCompilingSampleTests/NonCompilingSampleTests.csproj create mode 100644 tmc-langs-csharp/src/test/resources/NonCompilingProject/test/NonCompilingSampleTests/ProgramTest.cs create mode 100644 tmc-langs-csharp/src/test/resources/PythonProject/src/newpythonproject.py create mode 100644 tmc-langs-csharp/src/test/resources/PythonProject/test/__init__.py create mode 100644 tmc-langs-csharp/src/test/resources/PythonProject/test/test_new.py create mode 100644 tmc-langs-csharp/src/test/resources/PythonProject/test/test_two.py create mode 100644 tmc-langs-csharp/src/test/resources/PythonProject/test/tmc_test_results.json create mode 100644 tmc-langs-csharp/src/test/resources/PythonProject/tmc/__init__.py create mode 100644 tmc-langs-csharp/src/test/resources/PythonProject/tmc/__main__.py create mode 100644 tmc-langs-csharp/src/test/resources/PythonProject/tmc/points.py create mode 100644 tmc-langs-csharp/src/test/resources/PythonProject/tmc/result.py create mode 100644 tmc-langs-csharp/src/test/resources/PythonProject/tmc/runner.py diff --git a/tmc-langs-csharp/src/main/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPlugin.java b/tmc-langs-csharp/src/main/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPlugin.java index 742510667..51b9acd4b 100644 --- a/tmc-langs-csharp/src/main/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPlugin.java +++ b/tmc-langs-csharp/src/main/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPlugin.java @@ -214,7 +214,7 @@ private String getBootstrapPath() { Path jarPath = getJarPath(); if (jarPath != null - && Files.exists(jarPath.resolve(Paths.get("tmc-csharp-runner", "Bootstrap.dll")))) { + && Files.exists(jarPath.resolve(Paths.get("tmc-csharp-runner", "Bootstrap.dll")))) { return jarPath.resolve(Paths.get("tmc-csharp-runner", "Bootstrap.dll")).toString(); } else { System.out.println("Runner downloading failed, defaulting to environment variable"); @@ -260,7 +260,9 @@ private RunResult runResultFromFailedCompilation(ProcessResult result) { private void ensureRunnerAvailability() { Path jarPath = getJarPath(); - if (jarPath == null) { return; } + if (jarPath == null) { + return; + } try { if (!Files.exists(jarPath.resolve(Paths.get("tmc-csharp-runner", "Bootstrap.dll")))) { @@ -277,10 +279,10 @@ private void ensureRunnerAvailability() { } } - private Path getJarPath() { - String jarPathString - = CSharpPlugin.class.getProtectionDomain().getCodeSource().getLocation().getPath(); - + public Path getJarPath() { + String jarPathString + = CSharpPlugin.class.getProtectionDomain().getCodeSource().getLocation().getPath(); + try { String decodedPath = URLDecoder.decode(jarPathString, "UTF-8"); diff --git a/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java b/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java index ba6d57dc6..1125bb236 100644 --- a/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java +++ b/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java @@ -1,6 +1,8 @@ package fi.helsinki.cs.tmc.langs.csharp; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import fi.helsinki.cs.tmc.langs.abstraction.Strategy; @@ -10,11 +12,14 @@ import fi.helsinki.cs.tmc.langs.domain.TestResult; import fi.helsinki.cs.tmc.langs.io.StudentFilePolicy; import fi.helsinki.cs.tmc.langs.utils.TestUtils; -import java.io.File; +import java.io.IOException; +import java.nio.file.Files; import org.junit.Before; import org.junit.Test; +import org.apache.commons.io.FileUtils; + import java.nio.file.Path; import java.nio.file.Paths; import java.util.Locale; @@ -38,21 +43,50 @@ public void testGetLanguageName() { assertEquals("csharp", this.csPlugin.getPluginName()); } + @Test + public void testCSharpIsRecognizedAsCSharp() { + Path csharpProjectPath = TestUtils.getPath(getClass(), "PassingProject"); + assertTrue(csPlugin.isExerciseTypeCorrect(csharpProjectPath)); + } + + @Test + public void testPythonIsNotRecognizedAsCSharp() { + Path pythonProjectPath = TestUtils.getPath(getClass(), "PythonProject"); + assertFalse(csPlugin.isExerciseTypeCorrect(pythonProjectPath)); + } + @Test public void getStudentFilePolicyReturnsCSharpStudentFilePolicy() { StudentFilePolicy policy = this.csPlugin.getStudentFilePolicy(Paths.get("")); - assertTrue(policy instanceof CSharpStudentFilePolicy); } + @Test + public void testJarPathExists() { + Path jarPath = csPlugin.getJarPath(); + assertNotNull(jarPath); + } + + @Test + public void testDownloadingRunner() throws IOException { + Path jarPath = csPlugin.getJarPath(); + Path dirPath = jarPath.resolve(Paths.get("tmc-csharp-runner")); + + if (Files.exists(dirPath)) { + FileUtils.deleteDirectory(dirPath.toFile()); + } + + Path projectPath = TestUtils.getPath(getClass(), "PassingProject"); + RunResult runResult = this.csPlugin.runTests(projectPath); + assertEquals(runResult.toString(), RunResult.Status.PASSED, runResult.status); + + assertTrue(Files.exists(dirPath)); + assertTrue(Files.exists(jarPath.resolve(Paths.get("tmc-csharp-runner", "Bootstrap.dll")))); + } + @Test public void testRunTestsPassing() { Path path = TestUtils.getPath(getClass(), "PassingProject"); - System.out.println(path); - System.out.println(System.getenv("TMC_CSHARP_BOOTSTRAP_PATH")); - System.out.println(new File(System.getenv("TMC_CSHARP_BOOTSTRAP_PATH")).exists()); - System.out.println(System.getenv("MSBUILD_EXE_PATH")); - System.out.println(new File(System.getenv("MSBUILD_EXE_PATH")).exists()); RunResult runResult = this.csPlugin.runTests(path); assertEquals(runResult.toString(), RunResult.Status.PASSED, runResult.status); @@ -69,7 +103,6 @@ public void testRunTestsPassing() { @Test public void testRunTestsFailing() { Path path = TestUtils.getPath(getClass(), "FailingProject"); - System.out.println(path); RunResult runResult = this.csPlugin.runTests(path); assertEquals(runResult.toString(), RunResult.Status.TESTS_FAILED, runResult.status); @@ -77,7 +110,13 @@ public void testRunTestsFailing() { assertTrue(!testResult.isSuccessful()); assertTrue(!testResult.getMessage().isEmpty()); assertEquals(0, testResult.points.size()); - assertEquals(3, testResult.getException().size()); + } + + @Test + public void testRunTestsNonCompiling() { + Path path = TestUtils.getPath(getClass(), "NonCompilingProject"); + RunResult runResult = this.csPlugin.runTests(path); + assertEquals(runResult.toString(), RunResult.Status.COMPILE_FAILED, runResult.status); } @Test @@ -96,4 +135,21 @@ public void testCheckCodeStyleStratery() { assertTrue(result.getStrategy() == Strategy.DISABLED); } + @Test + public void testCleanRemovesBinAndObj() throws IOException { + Path projectPath = TestUtils.getPath(getClass(), "PassingProject"); + this.csPlugin.runTests(projectPath); + + assertTrue(Files.exists(projectPath.resolve(Paths.get("src", "PassingSample", "bin")))); + assertTrue(Files.exists(projectPath.resolve(Paths.get("src", "PassingSample", "obj")))); + assertTrue(Files.exists(projectPath.resolve(Paths.get("test", "PassingSampleTests", "bin")))); + assertTrue(Files.exists(projectPath.resolve(Paths.get("test", "PassingSampleTests", "obj")))); + + csPlugin.clean(projectPath); + + assertFalse(Files.exists(projectPath.resolve(Paths.get("src", "PassingSample", "bin")))); + assertFalse(Files.exists(projectPath.resolve(Paths.get("src", "PassingSample", "obj")))); + assertFalse(Files.exists(projectPath.resolve(Paths.get("test", "PassingSampleTests", "bin")))); + assertFalse(Files.exists(projectPath.resolve(Paths.get("test", "PassingSampleTests", "obj")))); + } } diff --git a/tmc-langs-csharp/src/test/resources/NonCompilingProject/src/NonCompilingSample/NonCompilingSample.csproj b/tmc-langs-csharp/src/test/resources/NonCompilingProject/src/NonCompilingSample/NonCompilingSample.csproj new file mode 100644 index 000000000..c73e0d169 --- /dev/null +++ b/tmc-langs-csharp/src/test/resources/NonCompilingProject/src/NonCompilingSample/NonCompilingSample.csproj @@ -0,0 +1,8 @@ + + + + Exe + netcoreapp3.1 + + + diff --git a/tmc-langs-csharp/src/test/resources/NonCompilingProject/src/NonCompilingSample/Program.cs b/tmc-langs-csharp/src/test/resources/NonCompilingProject/src/NonCompilingSample/Program.cs new file mode 100644 index 000000000..f4d788856 --- /dev/null +++ b/tmc-langs-csharp/src/test/resources/NonCompilingProject/src/NonCompilingSample/Program.cs @@ -0,0 +1,17 @@ +using System; + +namespace NonCompilingSample +{ + public class Program + { + public static string GetName(string name) => name; + + public static int GetYear(int year) => year; + + public static void Main(string[] args) + { + Console.WriteLine("This is a passing test."); + ( + } + } +} diff --git a/tmc-langs-csharp/src/test/resources/NonCompilingProject/test/NonCompilingSampleTests/NonCompilingSampleTests.csproj b/tmc-langs-csharp/src/test/resources/NonCompilingProject/test/NonCompilingSampleTests/NonCompilingSampleTests.csproj new file mode 100644 index 000000000..79bba1623 --- /dev/null +++ b/tmc-langs-csharp/src/test/resources/NonCompilingProject/test/NonCompilingSampleTests/NonCompilingSampleTests.csproj @@ -0,0 +1,21 @@ + + + + netcoreapp3.1 + + false + + + + + + + + + + + + + + + diff --git a/tmc-langs-csharp/src/test/resources/NonCompilingProject/test/NonCompilingSampleTests/ProgramTest.cs b/tmc-langs-csharp/src/test/resources/NonCompilingProject/test/NonCompilingSampleTests/ProgramTest.cs new file mode 100644 index 000000000..e330cc9c3 --- /dev/null +++ b/tmc-langs-csharp/src/test/resources/NonCompilingProject/test/NonCompilingSampleTests/ProgramTest.cs @@ -0,0 +1,25 @@ +using System; +using Xunit; +using NonCompilingSample; +using TestMyCode.CSharp.API.Attributes; + +namespace PassingSampleTests +{ + [Points("1")] + public class ProgramTest + { + [Fact] + [Points("1.1")] + public void TestGetName() + { + Assert.Equal("Clare", Program.GetName("Clare")); + } + + [Fact] + [Points("1.2")] + public void TestGetYear() + { + Assert.Equal(1900, Program.GetYear(1900)); + } + } +} diff --git a/tmc-langs-csharp/src/test/resources/PythonProject/src/newpythonproject.py b/tmc-langs-csharp/src/test/resources/PythonProject/src/newpythonproject.py new file mode 100644 index 000000000..9f8b2e7a5 --- /dev/null +++ b/tmc-langs-csharp/src/test/resources/PythonProject/src/newpythonproject.py @@ -0,0 +1,6 @@ + +__author__ = "henrik" +__date__ = "$08-Jul-2015 15:08:13$" + +if __name__ == "__main__": + print("Hello World!") diff --git a/tmc-langs-csharp/src/test/resources/PythonProject/test/__init__.py b/tmc-langs-csharp/src/test/resources/PythonProject/test/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tmc-langs-csharp/src/test/resources/PythonProject/test/test_new.py b/tmc-langs-csharp/src/test/resources/PythonProject/test/test_new.py new file mode 100644 index 000000000..faa0401ff --- /dev/null +++ b/tmc-langs-csharp/src/test/resources/PythonProject/test/test_new.py @@ -0,0 +1,14 @@ +import unittest +import tmc +from tmc import points + + +@points('1.1') +class TestCase(unittest.TestCase): + + @points('1.2') + def test_new(self): + self.assertEqual("a", "a"); + +if __name__ == '__main__': + unittest.main() diff --git a/tmc-langs-csharp/src/test/resources/PythonProject/test/test_two.py b/tmc-langs-csharp/src/test/resources/PythonProject/test/test_two.py new file mode 100644 index 000000000..1e44e7d66 --- /dev/null +++ b/tmc-langs-csharp/src/test/resources/PythonProject/test/test_two.py @@ -0,0 +1,17 @@ +import unittest +from tmc import points + + +@points('1.1') +class SecondTest(unittest.TestCase): + + @points('1.2') + def test_a_is_a(self): + self.assertEqual('a', 'a') + + @points('1.2') + def test_b_is_b(self): + self.assertEqual('b', 'b') + +if __name__ == '__main__': + unittest.main() diff --git a/tmc-langs-csharp/src/test/resources/PythonProject/test/tmc_test_results.json b/tmc-langs-csharp/src/test/resources/PythonProject/test/tmc_test_results.json new file mode 100644 index 000000000..0637a088a --- /dev/null +++ b/tmc-langs-csharp/src/test/resources/PythonProject/test/tmc_test_results.json @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/tmc-langs-csharp/src/test/resources/PythonProject/tmc/__init__.py b/tmc-langs-csharp/src/test/resources/PythonProject/tmc/__init__.py new file mode 100644 index 000000000..de896fa10 --- /dev/null +++ b/tmc-langs-csharp/src/test/resources/PythonProject/tmc/__init__.py @@ -0,0 +1,2 @@ +from .points import points +from .runner import TMCTestRunner diff --git a/tmc-langs-csharp/src/test/resources/PythonProject/tmc/__main__.py b/tmc-langs-csharp/src/test/resources/PythonProject/tmc/__main__.py new file mode 100644 index 000000000..e9843e320 --- /dev/null +++ b/tmc-langs-csharp/src/test/resources/PythonProject/tmc/__main__.py @@ -0,0 +1,11 @@ +from unittest import TestProgram +from .runner import TMCTestRunner +import sys + + +if sys.argv.__len__() > 1 and sys.argv[1] == 'available_points': + TMCTestRunner().available_points() + sys.exit() + +main = TestProgram +main(testRunner=TMCTestRunner, module=None, failfast=False) diff --git a/tmc-langs-csharp/src/test/resources/PythonProject/tmc/points.py b/tmc-langs-csharp/src/test/resources/PythonProject/tmc/points.py new file mode 100644 index 000000000..e56e6cef1 --- /dev/null +++ b/tmc-langs-csharp/src/test/resources/PythonProject/tmc/points.py @@ -0,0 +1,50 @@ +from inspect import isclass, isfunction +from collections import defaultdict + +point_register = {'suite': defaultdict(list), 'test': defaultdict(list)} + + +def qualifier(test): + return "%s.%s" % (test.__module__, test.__qualname__) + + +def save_points(o, points, dst): + q = qualifier(o) + dst[q] += filter(lambda point: point not in dst[q], points) + + +def points(*points): + + def points_wrapper(o): + if isclass(o): + save_points(o, points, point_register['suite']) + elif isfunction(o): + save_points(o, points, point_register['test']) + else: + raise Exception("Expected decorator object '%s' type to be Class or Function but was %s." % (o, type(o))) + return o + + if not points: + raise Exception("You need to define at least one point in the points decorator declaration") + for point in points: + if type(point) is not str: + msg = "Points decorator argument '%s' needs to be a string, but was %s." % (point, type(point).__name__) + raise Exception(msg) + return points_wrapper + + +def _parse_points(test): + name = _name_test(test) + testPoints = point_register['test'] + points = testPoints[name] + key = name[:name.rfind('.')] + suitePoints = point_register['suite'][key] + points += suitePoints + return points + + +def _name_test(test): + module = test.__module__ + classname = test.__class__.__name__ + testName = test._testMethodName + return module + '.' + classname + '.' + testName diff --git a/tmc-langs-csharp/src/test/resources/PythonProject/tmc/result.py b/tmc-langs-csharp/src/test/resources/PythonProject/tmc/result.py new file mode 100644 index 000000000..0613235f1 --- /dev/null +++ b/tmc-langs-csharp/src/test/resources/PythonProject/tmc/result.py @@ -0,0 +1,52 @@ +from unittest.runner import TextTestResult +from .points import _parse_points, _name_test +import atexit +import json +import traceback + +results = [] + + +class TMCResult(TextTestResult): + + def __init__(self, stream, descriptions, verbosity): + super(TMCResult, self).__init__(stream, descriptions, verbosity) + + def startTest(self, test): + super(TMCResult, self).startTest(test) + + def addSuccess(self, test): + super(TMCResult, self).addSuccess(test) + self.addResult(test, 'passed') + + def addFailure(self, test, err): + super(TMCResult, self).addFailure(test, err) + self.addResult(test, 'failed', err) + + def addError(self, test, err): + super(TMCResult, self).addError(test, err) + self.addResult(test, 'errored', err) + + def addResult(self, test, status, err=None): + points = _parse_points(test) + message = "" + backtrace = [] + if err is not None: + message = str(err[1]) + backtrace = traceback.format_tb(err[2]) + + details = { + 'name': _name_test(test), + 'status': status, + 'message': message, + 'passed': status == 'passed', + 'points': points, + 'backtrace': backtrace + } + results.append(details) + + # TODO: Do not do this if not using TMCTestRunner + @atexit.register + def write_output(): + with open('.tmc_test_results.json', 'w') as f: + json.dump(results, f, ensure_ascii=False) diff --git a/tmc-langs-csharp/src/test/resources/PythonProject/tmc/runner.py b/tmc-langs-csharp/src/test/resources/PythonProject/tmc/runner.py new file mode 100644 index 000000000..9ec23e533 --- /dev/null +++ b/tmc-langs-csharp/src/test/resources/PythonProject/tmc/runner.py @@ -0,0 +1,32 @@ +from unittest import TextTestRunner, TestLoader +from .result import TMCResult +from .points import _parse_points, _name_test +from itertools import chain +import json + + +class TMCTestRunner(TextTestRunner): + """A test runner for TMC exercises. + """ + + resultclass = TMCResult + + def __init__(self, *args, **kwargs): + super(TMCTestRunner, self).__init__(*args, **kwargs) + + def run(self, test): + print('Running tests with some TMC magic...') + return super(TMCTestRunner, self).run(test) + + def available_points(self): + testLoader = TestLoader() + tests = testLoader.discover('.', 'test*.py', None) + tests = list(chain(*chain(*tests._tests))) + + points = map(_parse_points, tests) + names = map(_name_test, tests) + + result = dict(zip(names, points)) + + with open('.available_points.json', 'w') as f: + json.dump(result, f, ensure_ascii=False) From 1531e93ebbea7defebcd4d2bcbddf084f1b4a147 Mon Sep 17 00:00:00 2001 From: Tubaias Date: Wed, 27 May 2020 18:18:57 +0300 Subject: [PATCH 50/61] tests that worked until the merge --- .../fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java b/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java index 40618360b..20fa739ee 100644 --- a/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java +++ b/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java @@ -79,6 +79,7 @@ public void testDownloadingRunner() throws IOException { Path projectPath = TestUtils.getPath(getClass(), "PassingProject"); RunResult runResult = this.csPlugin.runTests(projectPath); + assertNotNull(runResult); assertEquals(runResult.toString(), RunResult.Status.PASSED, runResult.status); assertTrue(Files.exists(dirPath)); @@ -90,6 +91,7 @@ public void testRunTestsPassing() { Path path = TestUtils.getPath(getClass(), "PassingProject"); RunResult runResult = this.csPlugin.runTests(path); + assertNotNull(runResult); assertEquals(runResult.toString(), RunResult.Status.PASSED, runResult.status); TestResult testResult = runResult.testResults.get(0); @@ -106,6 +108,7 @@ public void testRunTestsPassing() { public void testRunTestsFailing() { Path path = TestUtils.getPath(getClass(), "FailingProject"); RunResult runResult = this.csPlugin.runTests(path); + assertNotNull(runResult); assertEquals(runResult.toString(), RunResult.Status.TESTS_FAILED, runResult.status); TestResult testResult = runResult.testResults.get(0); @@ -118,6 +121,7 @@ public void testRunTestsFailing() { public void testRunTestsNonCompiling() { Path path = TestUtils.getPath(getClass(), "NonCompilingProject"); RunResult runResult = this.csPlugin.runTests(path); + assertNotNull(runResult); assertEquals(runResult.toString(), RunResult.Status.COMPILE_FAILED, runResult.status); } From f86c5dd3212b9e7f51158927290eee9974637417 Mon Sep 17 00:00:00 2001 From: isokissa3 Date: Thu, 28 May 2020 12:17:09 +0300 Subject: [PATCH 51/61] =?UTF-8?q?Part=20=F0=9F=98=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPlugin.java | 2 +- .../java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/tmc-langs-csharp/src/main/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPlugin.java b/tmc-langs-csharp/src/main/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPlugin.java index 31edc9688..92c8ce6c2 100644 --- a/tmc-langs-csharp/src/main/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPlugin.java +++ b/tmc-langs-csharp/src/main/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPlugin.java @@ -56,7 +56,7 @@ public class CSharpPlugin extends AbstractLanguagePlugin { private static final Path SRC_PATH = Paths.get("src"); private static final String RUNNER_ZIP_DOWNLOAD_URL - = "https://github.com/TMC-C/tmc-csharp-runner/releases/download/1.0.5/tmc-csharp-runner.zip"; + = "https://github.com/TMC-C/tmc-csharp-runner/releases/download/1.0.5.1/tmc-csharp-runner.zip"; private static final String CANNOT_RUN_TESTS_MESSAGE = "Failed to run tests."; private static final String CANNOT_PARSE_TEST_RESULTS_MESSAGE = "Failed to read test results."; diff --git a/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java b/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java index 20fa739ee..612051694 100644 --- a/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java +++ b/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java @@ -92,6 +92,7 @@ public void testRunTestsPassing() { RunResult runResult = this.csPlugin.runTests(path); assertNotNull(runResult); + System.out.println(runResult); assertEquals(runResult.toString(), RunResult.Status.PASSED, runResult.status); TestResult testResult = runResult.testResults.get(0); From 8fc1986bf398313b41fd2eb08e2c3d26c199e027 Mon Sep 17 00:00:00 2001 From: isokissa3 Date: Thu, 28 May 2020 13:10:47 +0300 Subject: [PATCH 52/61] =?UTF-8?q?=F0=9F=A4=A8=F0=9F=A4=A8=F0=9F=A4=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../helsinki/cs/tmc/langs/csharp/CSharpPlugin.java | 13 +++++++------ .../cs/tmc/langs/csharp/CSharpPluginTest.java | 14 ++++++++++++++ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/tmc-langs-csharp/src/main/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPlugin.java b/tmc-langs-csharp/src/main/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPlugin.java index 92c8ce6c2..b0ec0573f 100644 --- a/tmc-langs-csharp/src/main/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPlugin.java +++ b/tmc-langs-csharp/src/main/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPlugin.java @@ -217,6 +217,13 @@ private String[] getTestCommand() { } private String getBootstrapPath() { + + String envVarPath = System.getenv("TMC_CSHARP_BOOTSTRAP_PATH"); + + if (envVarPath != null) { + return envVarPath; + } + ensureRunnerAvailability(); Path jarPath = getJarPath(); @@ -228,12 +235,6 @@ private String getBootstrapPath() { System.out.println("Runner downloading failed, defaulting to environment variable"); } - String envVarPath = System.getenv("TMC_CSHARP_BOOTSTRAP_PATH"); - - if (envVarPath != null) { - return envVarPath; - } - log.error(CANNOT_LOCATE_RUNNER_MESSAGE); return null; diff --git a/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java b/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java index 612051694..979c42a81 100644 --- a/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java +++ b/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java @@ -70,6 +70,7 @@ public void testJarPathExists() { @Test public void testDownloadingRunner() throws IOException { + System.out.println("TEST #1 START"); Path jarPath = csPlugin.getJarPath(); Path dirPath = jarPath.resolve(Paths.get("tmc-csharp-runner")); @@ -84,10 +85,12 @@ public void testDownloadingRunner() throws IOException { assertTrue(Files.exists(dirPath)); assertTrue(Files.exists(jarPath.resolve(Paths.get("tmc-csharp-runner", "Bootstrap.dll")))); + System.out.println("TEST #1 END"); } @Test public void testRunTestsPassing() { + System.out.println("TEST #2 START"); Path path = TestUtils.getPath(getClass(), "PassingProject"); RunResult runResult = this.csPlugin.runTests(path); @@ -103,10 +106,12 @@ public void testRunTestsPassing() { assertTrue(testResult.points.contains("1.2")); assertEquals("", testResult.getMessage()); assertEquals(0, testResult.getException().size()); + System.out.println("TEST #2 END"); } @Test public void testRunTestsFailing() { + System.out.println("TEST #3 START"); Path path = TestUtils.getPath(getClass(), "FailingProject"); RunResult runResult = this.csPlugin.runTests(path); assertNotNull(runResult); @@ -116,34 +121,42 @@ public void testRunTestsFailing() { assertTrue(!testResult.isSuccessful()); assertTrue(!testResult.getMessage().isEmpty()); assertEquals(0, testResult.points.size()); + System.out.println("TEST #3 END"); } @Test public void testRunTestsNonCompiling() { + System.out.println("TEST #4 START"); Path path = TestUtils.getPath(getClass(), "NonCompilingProject"); RunResult runResult = this.csPlugin.runTests(path); assertNotNull(runResult); assertEquals(runResult.toString(), RunResult.Status.COMPILE_FAILED, runResult.status); + System.out.println("TEST #4 END"); } @Test public void testScanExercise() { + System.out.println("TEST #5 START"); Path path = TestUtils.getPath(getClass(), "PassingProject"); ExerciseDesc testDesc = this.csPlugin.scanExercise(path, "cs-tests").get(); assertEquals("cs-tests", testDesc.name); assertEquals("PassingSampleTests.ProgramTest.TestGetName", testDesc.tests.get(0).name); assertEquals(2, testDesc.tests.get(0).points.size()); + System.out.println("TEST #5 END"); } @Test() public void testCheckCodeStyleStratery() { + System.out.println("TEST #6 START"); Path path = TestUtils.getPath(getClass(), "PassingProject"); ValidationResult result = this.csPlugin.checkCodeStyle(path, new Locale("en")); assertTrue(result.getStrategy() == Strategy.DISABLED); + System.out.println("TEST #6 END"); } @Test public void testCleanRemovesBinAndObj() throws IOException { + System.out.println("TEST #7 START"); Path projectPath = TestUtils.getPath(getClass(), "PassingProject"); this.csPlugin.runTests(projectPath); @@ -158,5 +171,6 @@ public void testCleanRemovesBinAndObj() throws IOException { assertFalse(Files.exists(projectPath.resolve(Paths.get("src", "PassingSample", "obj")))); assertFalse(Files.exists(projectPath.resolve(Paths.get("test", "PassingSampleTests", "bin")))); assertFalse(Files.exists(projectPath.resolve(Paths.get("test", "PassingSampleTests", "obj")))); + System.out.println("TEST #7 END"); } } From 17e6085189d6cc97cd9b8f03a020308023b6252a Mon Sep 17 00:00:00 2001 From: isokissa3 Date: Thu, 28 May 2020 13:35:37 +0300 Subject: [PATCH 53/61] =?UTF-8?q?=F0=9F=A4=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPlugin.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tmc-langs-csharp/src/main/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPlugin.java b/tmc-langs-csharp/src/main/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPlugin.java index b0ec0573f..47b7b9af4 100644 --- a/tmc-langs-csharp/src/main/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPlugin.java +++ b/tmc-langs-csharp/src/main/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPlugin.java @@ -56,7 +56,7 @@ public class CSharpPlugin extends AbstractLanguagePlugin { private static final Path SRC_PATH = Paths.get("src"); private static final String RUNNER_ZIP_DOWNLOAD_URL - = "https://github.com/TMC-C/tmc-csharp-runner/releases/download/1.0.5.1/tmc-csharp-runner.zip"; + = "https://github.com/TMC-C/tmc-csharp-runner/releases/download/1.5.0.2/tmc-csharp-runner.zip"; private static final String CANNOT_RUN_TESTS_MESSAGE = "Failed to run tests."; private static final String CANNOT_PARSE_TEST_RESULTS_MESSAGE = "Failed to read test results."; From 95f0f7289540d65673a543b8303ec386351cf870 Mon Sep 17 00:00:00 2001 From: isokissa3 Date: Thu, 28 May 2020 13:56:20 +0300 Subject: [PATCH 54/61] =?UTF-8?q?=F0=9F=98=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPlugin.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tmc-langs-csharp/src/main/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPlugin.java b/tmc-langs-csharp/src/main/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPlugin.java index 47b7b9af4..b866d385f 100644 --- a/tmc-langs-csharp/src/main/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPlugin.java +++ b/tmc-langs-csharp/src/main/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPlugin.java @@ -56,7 +56,7 @@ public class CSharpPlugin extends AbstractLanguagePlugin { private static final Path SRC_PATH = Paths.get("src"); private static final String RUNNER_ZIP_DOWNLOAD_URL - = "https://github.com/TMC-C/tmc-csharp-runner/releases/download/1.5.0.2/tmc-csharp-runner.zip"; + = "https://github.com/TMC-C/tmc-csharp-runner/releases/download/1.0.5.2/tmc-csharp-runner.zip"; private static final String CANNOT_RUN_TESTS_MESSAGE = "Failed to run tests."; private static final String CANNOT_PARSE_TEST_RESULTS_MESSAGE = "Failed to read test results."; From a4bf82f47ba4d779cecc8017a0336b01a5bdb521 Mon Sep 17 00:00:00 2001 From: Tubaias Date: Thu, 28 May 2020 14:51:42 +0300 Subject: [PATCH 55/61] fixed tests --- .../cs/tmc/langs/csharp/CSharpPluginTest.java | 23 +++++++++-------- .../src/PassingSample/PassingSample.csproj | 8 ++++++ .../src/PassingSample/Program.cs | 17 +++++++++++++ .../PassingSampleTests.csproj | 21 ++++++++++++++++ .../test/PassingSampleTests/ProgramTest.cs | 25 +++++++++++++++++++ 5 files changed, 84 insertions(+), 10 deletions(-) create mode 100644 tmc-langs-csharp/src/test/resources/CleanUpProject/src/PassingSample/PassingSample.csproj create mode 100644 tmc-langs-csharp/src/test/resources/CleanUpProject/src/PassingSample/Program.cs create mode 100644 tmc-langs-csharp/src/test/resources/CleanUpProject/test/PassingSampleTests/PassingSampleTests.csproj create mode 100644 tmc-langs-csharp/src/test/resources/CleanUpProject/test/PassingSampleTests/ProgramTest.cs diff --git a/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java b/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java index 20fa739ee..bf6915acd 100644 --- a/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java +++ b/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java @@ -13,14 +13,12 @@ import fi.helsinki.cs.tmc.langs.io.StudentFilePolicy; import fi.helsinki.cs.tmc.langs.utils.TestUtils; -import java.io.IOException; -import java.nio.file.Files; - +import org.apache.commons.io.FileUtils; import org.junit.Before; import org.junit.Test; -import org.apache.commons.io.FileUtils; - +import java.io.IOException; +import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.Locale; @@ -79,6 +77,7 @@ public void testDownloadingRunner() throws IOException { Path projectPath = TestUtils.getPath(getClass(), "PassingProject"); RunResult runResult = this.csPlugin.runTests(projectPath); + assertNotNull(runResult); assertEquals(runResult.toString(), RunResult.Status.PASSED, runResult.status); @@ -143,19 +142,23 @@ public void testCheckCodeStyleStratery() { @Test public void testCleanRemovesBinAndObj() throws IOException { - Path projectPath = TestUtils.getPath(getClass(), "PassingProject"); + Path projectPath = TestUtils.getPath(getClass(), "CleanUpProject"); this.csPlugin.runTests(projectPath); assertTrue(Files.exists(projectPath.resolve(Paths.get("src", "PassingSample", "bin")))); assertTrue(Files.exists(projectPath.resolve(Paths.get("src", "PassingSample", "obj")))); - assertTrue(Files.exists(projectPath.resolve(Paths.get("test", "PassingSampleTests", "bin")))); - assertTrue(Files.exists(projectPath.resolve(Paths.get("test", "PassingSampleTests", "obj")))); + assertTrue(Files.exists( + projectPath.resolve(Paths.get("test", "PassingSampleTests", "bin")))); + assertTrue(Files.exists( + projectPath.resolve(Paths.get("test", "PassingSampleTests", "obj")))); csPlugin.clean(projectPath); assertFalse(Files.exists(projectPath.resolve(Paths.get("src", "PassingSample", "bin")))); assertFalse(Files.exists(projectPath.resolve(Paths.get("src", "PassingSample", "obj")))); - assertFalse(Files.exists(projectPath.resolve(Paths.get("test", "PassingSampleTests", "bin")))); - assertFalse(Files.exists(projectPath.resolve(Paths.get("test", "PassingSampleTests", "obj")))); + assertFalse(Files.exists( + projectPath.resolve(Paths.get("test", "PassingSampleTests", "bin")))); + assertFalse(Files.exists( + projectPath.resolve(Paths.get("test", "PassingSampleTests", "obj")))); } } diff --git a/tmc-langs-csharp/src/test/resources/CleanUpProject/src/PassingSample/PassingSample.csproj b/tmc-langs-csharp/src/test/resources/CleanUpProject/src/PassingSample/PassingSample.csproj new file mode 100644 index 000000000..c73e0d169 --- /dev/null +++ b/tmc-langs-csharp/src/test/resources/CleanUpProject/src/PassingSample/PassingSample.csproj @@ -0,0 +1,8 @@ + + + + Exe + netcoreapp3.1 + + + diff --git a/tmc-langs-csharp/src/test/resources/CleanUpProject/src/PassingSample/Program.cs b/tmc-langs-csharp/src/test/resources/CleanUpProject/src/PassingSample/Program.cs new file mode 100644 index 000000000..03b30c1fd --- /dev/null +++ b/tmc-langs-csharp/src/test/resources/CleanUpProject/src/PassingSample/Program.cs @@ -0,0 +1,17 @@ +using System; + +namespace PassingSample +{ + public class Program + { + + public static string GetName(string name) => name; + + public static int GetYear(int year) => year; + + public static void Main(string[] args) + { + Console.WriteLine("This is a passing test."); + } + } +} diff --git a/tmc-langs-csharp/src/test/resources/CleanUpProject/test/PassingSampleTests/PassingSampleTests.csproj b/tmc-langs-csharp/src/test/resources/CleanUpProject/test/PassingSampleTests/PassingSampleTests.csproj new file mode 100644 index 000000000..e6f6f119e --- /dev/null +++ b/tmc-langs-csharp/src/test/resources/CleanUpProject/test/PassingSampleTests/PassingSampleTests.csproj @@ -0,0 +1,21 @@ + + + + netcoreapp3.1 + + false + + + + + + + + + + + + + + + diff --git a/tmc-langs-csharp/src/test/resources/CleanUpProject/test/PassingSampleTests/ProgramTest.cs b/tmc-langs-csharp/src/test/resources/CleanUpProject/test/PassingSampleTests/ProgramTest.cs new file mode 100644 index 000000000..d890c0abb --- /dev/null +++ b/tmc-langs-csharp/src/test/resources/CleanUpProject/test/PassingSampleTests/ProgramTest.cs @@ -0,0 +1,25 @@ +using System; +using Xunit; +using PassingSample; +using TestMyCode.CSharp.API.Attributes; + +namespace PassingSampleTests +{ + [Points("1")] + public class ProgramTest + { + [Fact] + [Points("1.1")] + public void TestGetName() + { + Assert.Equal("Clare", Program.GetName("Clare")); + } + + [Fact] + [Points("1.2")] + public void TestGetYear() + { + Assert.Equal(1900, Program.GetYear(1900)); + } + } +} From 3960a7cbf90e047834a0c46f5bbbd0aa940e05fd Mon Sep 17 00:00:00 2001 From: isokissa3 Date: Thu, 28 May 2020 15:15:46 +0300 Subject: [PATCH 56/61] =?UTF-8?q?=F0=9F=A5=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPlugin.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tmc-langs-csharp/src/main/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPlugin.java b/tmc-langs-csharp/src/main/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPlugin.java index b866d385f..73caeb392 100644 --- a/tmc-langs-csharp/src/main/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPlugin.java +++ b/tmc-langs-csharp/src/main/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPlugin.java @@ -56,7 +56,7 @@ public class CSharpPlugin extends AbstractLanguagePlugin { private static final Path SRC_PATH = Paths.get("src"); private static final String RUNNER_ZIP_DOWNLOAD_URL - = "https://github.com/TMC-C/tmc-csharp-runner/releases/download/1.0.5.2/tmc-csharp-runner.zip"; + = "https://github.com/TMC-C/tmc-csharp-runner/releases/download/1.0.6/tmc-csharp-runner.zip"; private static final String CANNOT_RUN_TESTS_MESSAGE = "Failed to run tests."; private static final String CANNOT_PARSE_TEST_RESULTS_MESSAGE = "Failed to read test results."; From d2d8825408b956debb587073d5452ec20f8c3e5e Mon Sep 17 00:00:00 2001 From: PPeltola Date: Thu, 28 May 2020 15:41:07 +0300 Subject: [PATCH 57/61] fixed checkstyle & made coveralls read jacoco --- .travis.yml | 2 +- .../cs/tmc/langs/domain/RunResult.java | 19 +++++++++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index 164eae823..2a726a148 100644 --- a/.travis.yml +++ b/.travis.yml @@ -43,7 +43,7 @@ script: - mvn checkstyle:check -q - . ./clitest.sh after_success: - - mvn clean cobertura:cobertura org.eluder.coveralls:coveralls-maven-plugin:report -q + - mvn clean jacoco:report coveralls:report -q - ./deploy.sh os: - linux diff --git a/tmc-langs-framework/src/main/java/fi/helsinki/cs/tmc/langs/domain/RunResult.java b/tmc-langs-framework/src/main/java/fi/helsinki/cs/tmc/langs/domain/RunResult.java index 02a7a500b..1ea363897 100644 --- a/tmc-langs-framework/src/main/java/fi/helsinki/cs/tmc/langs/domain/RunResult.java +++ b/tmc-langs-framework/src/main/java/fi/helsinki/cs/tmc/langs/domain/RunResult.java @@ -24,7 +24,9 @@ public enum Status { /** * The submission or tests did not compile. * - *

The compiler error should be given in {@code logs[SpecialLogs.COMPILER_OUTPUT]}. + *

+ * The compiler error should be given in + * {@code logs[SpecialLogs.COMPILER_OUTPUT]}. */ COMPILE_FAILED, /** @@ -35,7 +37,9 @@ public enum Status { * For when no other status seems suitable, or the language plugin has * suffered an internal error. * - *

Details should be given in {@code logs[SpecialLogs.GENERIC_ERROR_MESSAGE]}. + *

+ * Details should be given in + * {@code logs[SpecialLogs.GENERIC_ERROR_MESSAGE]}. */ GENERIC_ERROR, } @@ -48,7 +52,8 @@ public enum Status { /** * Whether each test passed and which points were awarded. * - *

If the tests could not be run (e.g. due to compilation failure) then this + *

+ * If the tests could not be run (e.g. due to compilation failure) then this * may be empty (but not null). */ public final ImmutableList testResults; @@ -56,9 +61,11 @@ public enum Status { /** * Logs from the test run. * - *

The key may be an arbitrary string identifying the type of log. + *

+ * The key may be an arbitrary string identifying the type of log. * - *

See the SpecialLogs class for names of logs that TMC understands. The + *

+ * See the SpecialLogs class for names of logs that TMC understands. The * result may also contain other custom log types. */ public final ImmutableMap logs; @@ -86,7 +93,7 @@ public String toString() { + ", logKeys=" + logs.entrySet().stream().collect(Collectors.toMap( e -> e.getKey(), e -> new String(e.getValue()) - )) + + )) + '}'; } } From b859576b6fb30d924f675749c22e8b10c3eb0be1 Mon Sep 17 00:00:00 2001 From: PPeltola Date: Thu, 28 May 2020 15:57:11 +0300 Subject: [PATCH 58/61] check fixstyle --- .../helsinki/cs/tmc/langs/domain/RunResult.java | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/tmc-langs-framework/src/main/java/fi/helsinki/cs/tmc/langs/domain/RunResult.java b/tmc-langs-framework/src/main/java/fi/helsinki/cs/tmc/langs/domain/RunResult.java index 1ea363897..320815ab9 100644 --- a/tmc-langs-framework/src/main/java/fi/helsinki/cs/tmc/langs/domain/RunResult.java +++ b/tmc-langs-framework/src/main/java/fi/helsinki/cs/tmc/langs/domain/RunResult.java @@ -24,9 +24,7 @@ public enum Status { /** * The submission or tests did not compile. * - *

- * The compiler error should be given in - * {@code logs[SpecialLogs.COMPILER_OUTPUT]}. + *

The compiler error should be given in {@code logs[SpecialLogs.COMPILER_OUTPUT]}. */ COMPILE_FAILED, /** @@ -37,9 +35,7 @@ public enum Status { * For when no other status seems suitable, or the language plugin has * suffered an internal error. * - *

- * Details should be given in - * {@code logs[SpecialLogs.GENERIC_ERROR_MESSAGE]}. + *

Details should be given in {@code logs[SpecialLogs.GENERIC_ERROR_MESSAGE]}. */ GENERIC_ERROR, } @@ -52,8 +48,7 @@ public enum Status { /** * Whether each test passed and which points were awarded. * - *

- * If the tests could not be run (e.g. due to compilation failure) then this + *

If the tests could not be run (e.g. due to compilation failure) then this * may be empty (but not null). */ public final ImmutableList testResults; @@ -61,11 +56,9 @@ public enum Status { /** * Logs from the test run. * - *

- * The key may be an arbitrary string identifying the type of log. + *

The key may be an arbitrary string identifying the type of log. * - *

- * See the SpecialLogs class for names of logs that TMC understands. The + *

See the SpecialLogs class for names of logs that TMC understands. The * result may also contain other custom log types. */ public final ImmutableMap logs; From 47ccc47e3ba35f97d2099c10a2a10a755120ee95 Mon Sep 17 00:00:00 2001 From: isokissa3 Date: Thu, 28 May 2020 16:31:11 +0300 Subject: [PATCH 59/61] Remove debug pritns from tests --- .../cs/tmc/langs/csharp/CSharpPluginTest.java | 60 ++++++++++--------- 1 file changed, 33 insertions(+), 27 deletions(-) diff --git a/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java b/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java index 31070ffbf..78872deaa 100644 --- a/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java +++ b/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java @@ -34,6 +34,7 @@ public CSharpPluginTest() { @Before public void setUp() { this.csPlugin = new CSharpPlugin(); + System.setProperty("TEST_ENV", "TEST"); } @@ -45,30 +46,33 @@ public void testGetLanguageName() { @Test public void testCSharpIsRecognizedAsCSharp() { Path csharpProjectPath = TestUtils.getPath(getClass(), "PassingProject"); + assertTrue(csPlugin.isExerciseTypeCorrect(csharpProjectPath)); } @Test public void testPythonIsNotRecognizedAsCSharp() { Path pythonProjectPath = TestUtils.getPath(getClass(), "PythonProject"); + assertFalse(csPlugin.isExerciseTypeCorrect(pythonProjectPath)); } @Test public void getStudentFilePolicyReturnsCSharpStudentFilePolicy() { StudentFilePolicy policy = this.csPlugin.getStudentFilePolicy(Paths.get("")); + assertTrue(policy instanceof CSharpStudentFilePolicy); } @Test public void testJarPathExists() { Path jarPath = csPlugin.getJarPath(); + assertNotNull(jarPath); } @Test public void testDownloadingRunner() throws IOException { - System.out.println("TEST #1 START"); Path jarPath = csPlugin.getJarPath(); Path dirPath = jarPath.resolve(Paths.get("tmc-csharp-runner")); @@ -84,94 +88,96 @@ public void testDownloadingRunner() throws IOException { assertTrue(Files.exists(dirPath)); assertTrue(Files.exists(jarPath.resolve(Paths.get("tmc-csharp-runner", "Bootstrap.dll")))); - System.out.println("TEST #1 END"); } @Test public void testRunTestsPassing() { - System.out.println("TEST #2 START"); Path path = TestUtils.getPath(getClass(), "PassingProject"); RunResult runResult = this.csPlugin.runTests(path); + assertNotNull(runResult); - System.out.println(runResult); assertEquals(runResult.toString(), RunResult.Status.PASSED, runResult.status); TestResult testResult = runResult.testResults.get(0); assertTrue(testResult.isSuccessful()); + assertEquals("PassingSampleTests.ProgramTest.TestGetYear", testResult.getName()); assertEquals(2, testResult.points.size()); + assertTrue(testResult.points.contains("1")); assertTrue(testResult.points.contains("1.2")); + assertEquals("", testResult.getMessage()); assertEquals(0, testResult.getException().size()); - System.out.println("TEST #2 END"); } @Test public void testRunTestsFailing() { - System.out.println("TEST #3 START"); Path path = TestUtils.getPath(getClass(), "FailingProject"); + RunResult runResult = this.csPlugin.runTests(path); + assertNotNull(runResult); assertEquals(runResult.toString(), RunResult.Status.TESTS_FAILED, runResult.status); TestResult testResult = runResult.testResults.get(0); - assertTrue(!testResult.isSuccessful()); - assertTrue(!testResult.getMessage().isEmpty()); + + assertFalse(testResult.isSuccessful()); + assertFalse(testResult.getMessage().isEmpty()); + assertEquals(0, testResult.points.size()); - System.out.println("TEST #3 END"); } @Test public void testRunTestsNonCompiling() { - System.out.println("TEST #4 START"); Path path = TestUtils.getPath(getClass(), "NonCompilingProject"); + RunResult runResult = this.csPlugin.runTests(path); + assertNotNull(runResult); + assertEquals(runResult.toString(), RunResult.Status.COMPILE_FAILED, runResult.status); - System.out.println("TEST #4 END"); } @Test public void testScanExercise() { - System.out.println("TEST #5 START"); Path path = TestUtils.getPath(getClass(), "PassingProject"); - ExerciseDesc testDesc = this.csPlugin.scanExercise(path, "cs-tests").get(); + + ExerciseDesc testDesc = this.csPlugin.scanExercise(path, "cs-tests").orNull(); + + assertNotNull(testDesc); + assertEquals("cs-tests", testDesc.name); assertEquals("PassingSampleTests.ProgramTest.TestGetName", testDesc.tests.get(0).name); assertEquals(2, testDesc.tests.get(0).points.size()); - System.out.println("TEST #5 END"); } - @Test() - public void testCheckCodeStyleStratery() { - System.out.println("TEST #6 START"); + @Test + public void testCheckCodeStyleStrategy() { Path path = TestUtils.getPath(getClass(), "PassingProject"); + ValidationResult result = this.csPlugin.checkCodeStyle(path, new Locale("en")); - assertTrue(result.getStrategy() == Strategy.DISABLED); - System.out.println("TEST #6 END"); + + assertEquals(Strategy.DISABLED, result.getStrategy()); } @Test public void testCleanRemovesBinAndObj() throws IOException { Path projectPath = TestUtils.getPath(getClass(), "PassingProject"); + this.csPlugin.runTests(projectPath); assertTrue(Files.exists(projectPath.resolve(Paths.get("src", "PassingSample", "bin")))); assertTrue(Files.exists(projectPath.resolve(Paths.get("src", "PassingSample", "obj")))); - assertTrue(Files.exists( - projectPath.resolve(Paths.get("test", "PassingSampleTests", "bin")))); - assertTrue(Files.exists( - projectPath.resolve(Paths.get("test", "PassingSampleTests", "obj")))); + assertTrue(Files.exists(projectPath.resolve(Paths.get("test", "PassingSampleTests", "bin")))); + assertTrue(Files.exists(projectPath.resolve(Paths.get("test", "PassingSampleTests", "obj")))); csPlugin.clean(projectPath); assertFalse(Files.exists(projectPath.resolve(Paths.get("src", "PassingSample", "bin")))); assertFalse(Files.exists(projectPath.resolve(Paths.get("src", "PassingSample", "obj")))); - assertFalse(Files.exists( - projectPath.resolve(Paths.get("test", "PassingSampleTests", "bin")))); - assertFalse(Files.exists( - projectPath.resolve(Paths.get("test", "PassingSampleTests", "obj")))); + assertFalse(Files.exists(projectPath.resolve(Paths.get("test", "PassingSampleTests", "bin")))); + assertFalse(Files.exists(projectPath.resolve(Paths.get("test", "PassingSampleTests", "obj")))); } } From a5b8cdcad03ef68a68e7e0cc770f4b9a0d99a188 Mon Sep 17 00:00:00 2001 From: chenhuiz Date: Fri, 29 May 2020 12:21:39 +0300 Subject: [PATCH 60/61] fixed checkstyle --- .../cs/tmc/langs/csharp/CSharpPluginTest.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java b/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java index 78872deaa..73b6f3c6a 100644 --- a/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java +++ b/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java @@ -170,14 +170,18 @@ public void testCleanRemovesBinAndObj() throws IOException { assertTrue(Files.exists(projectPath.resolve(Paths.get("src", "PassingSample", "bin")))); assertTrue(Files.exists(projectPath.resolve(Paths.get("src", "PassingSample", "obj")))); - assertTrue(Files.exists(projectPath.resolve(Paths.get("test", "PassingSampleTests", "bin")))); - assertTrue(Files.exists(projectPath.resolve(Paths.get("test", "PassingSampleTests", "obj")))); + assertTrue(Files.exists(projectPath.resolve( + Paths.get("test", "PassingSampleTests", "bin")))); + assertTrue(Files.exists(projectPath.resolve( + Paths.get("test", "PassingSampleTests", "obj")))); csPlugin.clean(projectPath); assertFalse(Files.exists(projectPath.resolve(Paths.get("src", "PassingSample", "bin")))); assertFalse(Files.exists(projectPath.resolve(Paths.get("src", "PassingSample", "obj")))); - assertFalse(Files.exists(projectPath.resolve(Paths.get("test", "PassingSampleTests", "bin")))); - assertFalse(Files.exists(projectPath.resolve(Paths.get("test", "PassingSampleTests", "obj")))); + assertFalse(Files.exists(projectPath.resolve( + Paths.get("test", "PassingSampleTests", "bin")))); + assertFalse(Files.exists(projectPath.resolve( + Paths.get("test", "PassingSampleTests", "obj")))); } } From f34effdb45abcd5365886b58831a42a43608a80e Mon Sep 17 00:00:00 2001 From: chenhuiz Date: Fri, 29 May 2020 12:47:55 +0300 Subject: [PATCH 61/61] removed unused config --- .../java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java b/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java index 73b6f3c6a..c98ad9601 100644 --- a/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java +++ b/tmc-langs-csharp/src/test/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPluginTest.java @@ -34,8 +34,6 @@ public CSharpPluginTest() { @Before public void setUp() { this.csPlugin = new CSharpPlugin(); - - System.setProperty("TEST_ENV", "TEST"); } @Test