Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 91 additions & 5 deletions .github/workflows/pr-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,99 @@ jobs:

- name: Copy test files
run: |
echo "Copying test data"
mkdir -p src/test/resources
echo "Copying hidden tests"
mkdir -p src/test/java src/test/resources
cp -R hidden-tests/src/test/java/. src/test/java/
cp -R hidden-tests/src/test/resources/. src/test/resources/
echo ""
echo "Скопированы файлы:"
find src/test/resources -type f | sort | while read f; do echo " $f"; done
find src/test/java src/test/resources -type f | sort | while read f; do echo " $f"; done
rm -rf hidden-tests


- name: Select test pattern from commit message
id: select_tests
uses: actions/github-script@v7
with:
script: |
const pr = context.payload.pull_request;
if (!pr) {
core.setOutput('pattern', '');
return;
}
const repo = { owner: context.repo.owner, repo: context.repo.repo };
const { data: commit } = await github.rest.repos.getCommit({
...repo,
ref: pr.head.sha
});
const msg = (commit.commit.message || '').toLowerCase();

const patterns = [];
const add = (p) => { if (!patterns.includes(p)) patterns.push(p); };

if (msg.startsWith('atm:')) add('**/atm/*Test');
if (msg.startsWith('html:')) add('**/html/*Test');
if (msg.startsWith('randomset:')) add('**/randomSet/*Test');
if (msg.startsWith('cube:')) add('**/CubeSimpleTest');

core.setOutput('pattern', patterns.length ? patterns.join(',') : '');

- name: Run honors no-collections test
id: honors_test
continue-on-error: true
if: steps.select_tests.outputs.pattern == '**/randomSet/*Test'
run: mvn -B -Dtest=hse.java.lectures.lecture3.practice.randomSet.RandomSetBytecodeTest test

- name: Comment on PR for honors solution
if: steps.honors_test.outcome == 'success'
uses: actions/github-script@v7
with:
script: |
const pr = context.payload.pull_request;
if (!pr) {
core.info('No PR context, skipping comment.');
return;
}
const body = [
'Поздравляем! 🎉',
'',
'Вы решили сложную версию: решение прошло проверку «без коллекций».'
].join('\n');
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr.number,
body
});

- name: Run tests
run: mvn -B test
run: |
if [ -n "${{ steps.select_tests.outputs.pattern }}" ]; then
echo "Running selected tests: ${{ steps.select_tests.outputs.pattern }}"
mvn -B -Dtest='${{ steps.select_tests.outputs.pattern }},!**/RandomSetBytecodeTest' test
else
echo "No task prefix found. Failing."
exit 1
fi

- name: Comment on PR when no task prefix
if: steps.select_tests.outputs.pattern == ''
uses: actions/github-script@v7
with:
script: |
const pr = context.payload.pull_request;
if (!pr) {
core.info('No PR context, skipping comment.');
return;
}
const body = [
'Тесты не запускались.',
'',
'Укажите задачу в начале сообщения коммита:',
'atm: ..., html: ..., randomset: ...'
].join('\n');
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr.number,
body
});
20 changes: 20 additions & 0 deletions README-commit-format.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Формат коммитов для запуска тестов

## Зачем это нужно
CI запускает тесты выборочно. Чтобы он знал, какие тесты запускать, сообщение коммита должно начинаться с названия задачи.

## Формат
Используйте префикс в начале сообщения коммита:

- `atm: ...`
- `html: ...`
- `randomset: ...`

Тег задачи указывается в описании каждой задачи

Пример:
```
randomset: implement getRandom and contains
```

Если префикс не указан, CI **не запускает тесты** и оставляет комментарий в PR.
9 changes: 0 additions & 9 deletions commander/commander.iml

This file was deleted.

9 changes: 8 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<!-- ASM для анализа байткода в тестах -->
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<version>9.8</version>
<scope>test</scope>
</dependency>
<!-- Jackson для чтения JSON в тестах -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
Expand Down Expand Up @@ -65,4 +72,4 @@
</plugins>
</build>

</project>
</project>
14 changes: 14 additions & 0 deletions src/main/java/hse/java/lectures/lecture3/examples/Box.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package hse.java.lectures.lecture3.examples;

public class Box<T> {

private T item;

public void put(T item) {
this.item = item;
}

public T get() {
return item;
}
}
43 changes: 43 additions & 0 deletions src/main/java/hse/java/lectures/lecture3/examples/Generics.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package hse.java.lectures.lecture3.examples;

import java.util.ArrayList;
import java.util.List;

public class Generics {



public <T> T getType(T type) {
System.out.println(type.getClass());
return type;
}

public static <T extends Number> void write(List<T> list, T value) {
list.add(value);
}

public static <T extends Number & Comparable<T>> T get(T value) {
return value;
}

public static void testGenerics() {
// get(1.).compareTo()
write(List.of(1), 1);
write(List.of(), 1.2);
List<Integer> ints = new ArrayList<>();
ints.add(1);
ints.add(2);
// PECS
List<? extends Number> nums = ints;
List<? super Integer> si = ints;
si.add(1);
si.get(1);
}

public static void main(String[] args) {
List<Integer> il = new ArrayList<>();
write(il, 5);
System.out.println(il);
}

}
19 changes: 19 additions & 0 deletions src/main/java/hse/java/lectures/lecture3/examples/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package hse.java.lectures.lecture3.examples;

import java.util.ArrayList;
import java.util.concurrent.Callable;

public class Main {
public static void main(String[] args) {
Box<Integer> box = new Box<>();
Box<Double> dBox = new Box<>();
Callable<Integer> callable;

int x = new Integer(3);
Integer y = 5;

Box<? extends Number> nBox = box;
new Methods().get(new ArrayList<Integer>()).add(1);

}
}
10 changes: 10 additions & 0 deletions src/main/java/hse/java/lectures/lecture3/examples/Methods.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package hse.java.lectures.lecture3.examples;

public class Methods {


public <T> T get(T type) {
return type;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package hse.java.lectures.lecture3.examples;

import java.io.*;

public class TryCatchThrows {

public void testRuntime() throws RuntimeException {
throw new RuntimeException("Test runtime");
}

public void testException() throws Exception {
throw new Exception("test exception");
}

public void testError() throws Error {
throw new Error("test error");
}

public void testTryRuntime() {
try {
testRuntime();
} catch (RuntimeException e) {
System.out.println("Catch " + e.getMessage());
} finally {
System.out.println("finally");
}
}

public void testTryException() {
try {
testException();
} catch (Exception e) {
System.out.println("Catch " + e.getMessage());
} finally {
System.out.println("finally");
}
}

public void testTryError() {
// testError();
try {
testError();
} catch (Error e) {
System.out.println("Catch " + e.getMessage());
} finally {
System.out.println("finally");
}
}

public static void foo() {
throw new RuntimeException("My runtime");
}

public static void bar() throws Exception {
throw new Exception("My exception");
}

public static void main(String[] args) {
// foo();
// try {
// bar();
// } catch (Exception e) {
// System.err.println("Hello exception");
// } finally {
//
// }

// try (BufferedReader br = new BufferedReader(new FileReader(""))) {
//
// } catch (IOException e) {
// throw new RuntimeException(e);
// }

// int x = 1/ 0;
int[] a = new int[1];
System.out.println(a[2]);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package hse.java.lectures.lecture3.practice.randomSet;

public class EmptySetException extends RuntimeException {
public EmptySetException(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package hse.java.lectures.lecture3.practice.randomSet;

public class RandomSet<T> {

public boolean insert(T value) {
throw new UnsupportedOperationException("Not implemented");
}

public boolean remove(T value) {
throw new UnsupportedOperationException("Not implemented");
}

public boolean contains(T value) {
throw new UnsupportedOperationException("Not implemented");
}

public T getRandom() {
throw new UnsupportedOperationException("Not implemented");
}

}
Loading